Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): error when clearing followUserLocation #3308

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}
Loading