Skip to content

Commit 32ee76b

Browse files
authored
fix: issue with maxPitch MapView config setting not propagating to native components (#4191)
* - fix: preserve maxPitch when updating camera bounds for Android - fix: maxPitch prop in iOS Fabric component view not getting propagated from javascript * - add min/max pitch settings when camera bounds are updated
1 parent 4a2be2f commit 32ee76b

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCamera.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,13 @@ class RNMBXCamera(private val mContext: Context, private val mManager: RNMBXCame
182182

183183
private fun updateMaxBounds(mapView: RNMBXMapView) {
184184
val map = mapView.getMapboxMap()
185+
val currentBounds = map.getBounds()
185186
val builder = CameraBoundsOptions.Builder()
186187
builder.bounds(mMaxBounds?.toBounds())
187188
builder.minZoom(mMinZoomLevel ?: 0.0) // Passing null does not reset this value.
188189
builder.maxZoom(mMaxZoomLevel ?: 25.0) // Passing null does not reset this value.
190+
builder.minPitch(currentBounds.minPitch)
191+
builder.maxPitch(currentBounds.maxPitch)
189192
map.setBounds(builder.build())
190193
mCameraStop?.let { updateCamera(it, mapView) }
191194
}

ios/RNMBX/RNMBXCamera.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,9 @@ open class RNMBXCamera : RNMBXMapAndMapViewComponentBase {
331331

332332
func _updateMaxBounds() {
333333
withMapView { map in
334+
let current = map.mapboxMap.cameraBounds
334335
var options = CameraBoundsOptions()
335-
336+
336337
if let maxBounds = self.maxBoundsFeature {
337338
logged("RNMBXCamera._updateMaxBounds._toCoordinateBounds") {
338339
options.bounds = try self._toCoordinateBounds(maxBounds)
@@ -342,7 +343,9 @@ open class RNMBXCamera : RNMBXMapAndMapViewComponentBase {
342343
}
343344
options.minZoom = self.minZoomLevel?.CGFloat
344345
options.maxZoom = self.maxZoomLevel?.CGFloat
345-
346+
options.minPitch = current.minPitch
347+
options.maxPitch = current.maxPitch
348+
346349
logged("RNMBXCamera._updateMaxBounds") {
347350
try map.mapboxMap.setCameraBounds(with: options)
348351
}

ios/RNMBX/RNMBXMapViewComponentView.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
192192
RNMBX_REMAP_OPTIONAL_PROP_BOOL(rotateEnabled, reactRotateEnabled)
193193

194194
RNMBX_REMAP_OPTIONAL_PROP_BOOL(pitchEnabled, reactPitchEnabled)
195+
196+
id maxPitch = RNMBXConvertFollyDynamicToId(newViewProps.maxPitch);
197+
if (maxPitch != nil) {
198+
_view.reactMaxPitch = maxPitch;
199+
}
195200

196201
RNMBX_REMAP_OPTIONAL_PROP_NSDictionary(gestureSettings, reactGestureSettings)
197202

0 commit comments

Comments
 (0)