From 03a8f2e00e04fb6e0e9a55e37e5ca94a83c55617 Mon Sep 17 00:00:00 2001 From: Dave Pereira-Gurnell Date: Thu, 14 Dec 2023 10:16:01 +0000 Subject: [PATCH] Fix crash setting zoomEnabled on MapView creation (#3269) --- ios/RNMBX/RNMBXMapView.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ios/RNMBX/RNMBXMapView.swift b/ios/RNMBX/RNMBXMapView.swift index df67bc74c..215024f94 100644 --- a/ios/RNMBX/RNMBXMapView.swift +++ b/ios/RNMBX/RNMBXMapView.swift @@ -273,6 +273,7 @@ open class RNMBXMapView: UIView { case scaleBar case onLongPress case onPress + case zoomEnabled case scrollEnabled case rotateEnabled case pitchEnabled @@ -298,6 +299,8 @@ open class RNMBXMapView: UIView { map.applyOnLongPress() case .onPress: map.applyOnPress() + case .zoomEnabled: + map.applyZoomEnabled() case .scrollEnabled: map.applyScrollEnabled() case .rotateEnabled: @@ -661,10 +664,18 @@ open class RNMBXMapView: UIView { changes.apply(self) } + var zoomEnabled: Bool? = nil @objc public func setReactZoomEnabled(_ value: Bool) { - self.mapView.gestures.options.quickZoomEnabled = value - self.mapView.gestures.options.doubleTapToZoomInEnabled = value - self.mapView.gestures.options.pinchZoomEnabled = value + self.zoomEnabled = value + changed(.zoomEnabled) + } + + func applyZoomEnabled() { + if let value = zoomEnabled { + self.mapView.gestures.options.quickZoomEnabled = value + self.mapView.gestures.options.doubleTapToZoomInEnabled = value + self.mapView.gestures.options.pinchZoomEnabled = value + } } var scrollEnabled: Bool? = nil