diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/camera/CameraStop.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/camera/CameraStop.kt index 060c50f14..57aea256a 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/components/camera/CameraStop.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/camera/CameraStop.kt @@ -30,6 +30,9 @@ class CameraStop { private var mMode = CameraMode.EASE private var mDuration = 2000 private var mCallback: Animator.AnimatorListener? = null + + var ts: Int? = null + fun setBearing(bearing: Double) { mBearing = bearing } @@ -153,6 +156,10 @@ class CameraStop { ): CameraStop { val stop = CameraStop() + if (readableMap.hasKey("__updateTS")) { + stop.ts = readableMap.getInt("__updateTS") + } + if (readableMap.hasKey("pitch")) { stop.setTilt(readableMap.getDouble("pitch")) } diff --git a/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCamera.kt b/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCamera.kt index cfc0c830c..dbd6d0b54 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCamera.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCamera.kt @@ -72,6 +72,9 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame private var mMaxBounds: LatLngBounds? = null + var ts: Int? = null; + + private val mCameraCallback: Animator.AnimatorListener = object : Animator.AnimatorListener { override fun onAnimationStart(animator: Animator) {} override fun onAnimationEnd(animator: Animator) { @@ -110,10 +113,12 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame } } fun setStop(stop: CameraStop) { - mCameraStop = stop - stop.setCallback(mCameraCallback) - if (mMapView != null) { - stop.let { updateCamera(it) } + if (stop.ts != mCameraStop?.ts) { + mCameraStop = stop + stop.setCallback(mCameraCallback) + if (mMapView != null) { + stop.let { updateCamera(it) } + } } } diff --git a/ios/RNMBX/RNMBXCameraComponentView.mm b/ios/RNMBX/RNMBXCameraComponentView.mm index 60a1d6931..7677a0185 100644 --- a/ios/RNMBX/RNMBXCameraComponentView.mm +++ b/ios/RNMBX/RNMBXCameraComponentView.mm @@ -69,58 +69,62 @@ + (ComponentDescriptorProvider)componentDescriptorProvider - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps { - const auto &newProps = static_cast(*props); - id maxBounds = RNMBXConvertFollyDynamicToId(newProps.maxBounds); + const auto &oldViewProps = static_cast(*oldProps); + const auto &newViewProps = static_cast(*props); + id maxBounds = RNMBXConvertFollyDynamicToId(newViewProps.maxBounds); if (maxBounds != nil) { _view.maxBounds = maxBounds; } - id animationDuration = RNMBXConvertFollyDynamicToId(newProps.animationDuration); + id animationDuration = RNMBXConvertFollyDynamicToId(newViewProps.animationDuration); if (animationDuration != nil) { _view.animationDuration = animationDuration; } - id animationMode = RNMBXConvertFollyDynamicToId(newProps.animationMode); + id animationMode = RNMBXConvertFollyDynamicToId(newViewProps.animationMode); if (animationMode != nil) { _view.animationMode = animationMode; } - id defaultStop = RNMBXConvertFollyDynamicToId(newProps.defaultStop); + id defaultStop = RNMBXConvertFollyDynamicToId(newViewProps.defaultStop); if (defaultStop != nil) { _view.defaultStop = defaultStop; } - id followUserLocation = RNMBXConvertFollyDynamicToId(newProps.followUserLocation); + id followUserLocation = RNMBXConvertFollyDynamicToId(newViewProps.followUserLocation); if (followUserLocation != nil) { _view.followUserLocation = followUserLocation; } - id followUserMode = RNMBXConvertFollyDynamicToId(newProps.followUserMode); + id followUserMode = RNMBXConvertFollyDynamicToId(newViewProps.followUserMode); if (followUserMode != nil) { _view.followUserMode = followUserMode; } - id followZoomLevel = RNMBXConvertFollyDynamicToId(newProps.followZoomLevel); + id followZoomLevel = RNMBXConvertFollyDynamicToId(newViewProps.followZoomLevel); if (followZoomLevel != nil) { _view.followZoomLevel = followZoomLevel; } - id followPitch = RNMBXConvertFollyDynamicToId(newProps.followPitch); + id followPitch = RNMBXConvertFollyDynamicToId(newViewProps.followPitch); if (followPitch != nil) { _view.followPitch = followPitch; } - id followHeading = RNMBXConvertFollyDynamicToId(newProps.followHeading); + id followHeading = RNMBXConvertFollyDynamicToId(newViewProps.followHeading); if (followHeading != nil) { _view.followHeading = followHeading; } - id followPadding = RNMBXConvertFollyDynamicToId(newProps.followPadding); + id followPadding = RNMBXConvertFollyDynamicToId(newViewProps.followPadding); if (followPadding != nil) { _view.followPadding = followPadding; } - id maxZoomLevel = RNMBXConvertFollyDynamicToId(newProps.maxZoomLevel); + id maxZoomLevel = RNMBXConvertFollyDynamicToId(newViewProps.maxZoomLevel); if (maxZoomLevel != nil) { _view.maxZoomLevel = maxZoomLevel; } - id minZoomLevel = RNMBXConvertFollyDynamicToId(newProps.minZoomLevel); + id minZoomLevel = RNMBXConvertFollyDynamicToId(newViewProps.minZoomLevel); if (minZoomLevel != nil) { _view.minZoomLevel = minZoomLevel; } - id stop = RNMBXConvertFollyDynamicToId(newProps.stop); - if (stop != nil) { + + if (!oldProps || oldViewProps.stop != newViewProps.stop) { + id stop = RNMBXConvertFollyDynamicToId(newViewProps.stop); + if (stop != nil) { _view.stop = stop; + } } [super updateProps:props oldProps:oldProps]; } diff --git a/src/components/Camera.tsx b/src/components/Camera.tsx index 0d3aa2594..b09ce24a1 100644 --- a/src/components/Camera.tsx +++ b/src/components/Camera.tsx @@ -380,6 +380,8 @@ export const Camera = memo( return; } + lastTS += 1; + if (!config.type) // @ts-expect-error The compiler doesn't understand that the `config` union type is guaranteed // to be an object type. @@ -398,13 +400,15 @@ export const Camera = memo( _nativeStops = [..._nativeStops, _nativeStop]; } nativeCamera.current?.setNativeProps({ - stop: { stops: _nativeStops }, + stop: { stops: _nativeStops, __updateTS: lastTS }, }); } } else if (config.type === 'CameraStop') { const _nativeStop = buildNativeStop(config); if (_nativeStop) { - nativeCamera.current?.setNativeProps({ stop: _nativeStop }); + nativeCamera.current?.setNativeProps({ + stop: { __updateTS: lastTS, ..._nativeStop }, + }); } } }; @@ -590,6 +594,8 @@ export const Camera = memo( ), ); +let lastTS = 0; + const RNMBXCamera = NativeCameraView; export type Camera = CameraRef;