Skip to content

Commit

Permalink
fix(android): error when clearing followUserLocation (#3308)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfazekas authored Jan 9, 2024
1 parent 2af89e2 commit 9383f85
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
private val mAnimated = false
private val mHeading = 0.0

private var mFollowUserLocation = false
private var mFollowUserLocation = defaultFollowUserLocation
private var mFollowUserMode: String? = null
private var mFollowZoomLevel : Double? = null
private var mFollowPitch : Double? = null
Expand Down Expand Up @@ -126,8 +126,8 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
_updateViewportState()
}

fun setFollowUserLocation(value: Boolean) {
mFollowUserLocation = value
fun setFollowUserLocation(value: Boolean?) {
mFollowUserLocation = value ?: defaultFollowUserLocation
_updateViewportState()
}

Expand Down Expand Up @@ -559,5 +559,7 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
const val minimumZoomLevelForUserTracking = 10.5
const val defaultZoomLevelForUserTracking = 14.0
const val LOG_TAG = "RNMBXCamera"

const val defaultFollowUserLocation = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.mapbox.geojson.FeatureCollection
import com.rnmapbox.rnmbx.components.AbstractEventEmitter
import com.rnmapbox.rnmbx.components.camera.CameraStop.Companion.fromReadableMap
import com.rnmapbox.rnmbx.utils.GeoJSONUtils.toLatLngBounds

import com.rnmapbox.rnmbx.utils.extensions.asBooleanOrNull

class RNMBXCameraManager(private val mContext: ReactApplicationContext) :
AbstractEventEmitter<RNMBXCamera?>(
Expand Down Expand Up @@ -66,7 +66,7 @@ class RNMBXCameraManager(private val mContext: ReactApplicationContext) :

@ReactProp(name = "followUserLocation")
override fun setFollowUserLocation(camera: RNMBXCamera, value: Dynamic) {
camera.setFollowUserLocation(value.asBoolean())
camera.setFollowUserLocation(value.asBooleanOrNull())
}

@ReactProp(name = "followUserMode")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ fun Dynamic.toValue(): Value {
ReadableType.Array -> asArray().toValue()
ReadableType.Map -> asMap().toValue()
}
}

fun Dynamic.asBooleanOrNull(): Boolean? {
return if (isNull) {
null
} else {
asBoolean()
}
}

0 comments on commit 9383f85

Please sign in to comment.