diff --git a/example/src/examples/Map/ShowMap.tsx b/example/src/examples/Map/ShowMap.tsx index 3e0cea198..7c8db840d 100755 --- a/example/src/examples/Map/ShowMap.tsx +++ b/example/src/examples/Map/ShowMap.tsx @@ -15,9 +15,11 @@ const ShowMap = () => { data: (Mapbox.StyleURL as any)[key], // bad any, because enums }; }) - .sort(onSortOptions); + .sort(onSortOptions) + .concat({ data: 'mount', label: '(un)mount' }); const [styleURL, setStyleURL] = useState({ styleURL: _mapOptions[0].data }); + const [isMounted, setIsMounted] = useState(true); useEffect(() => { Mapbox.locationManager.start(); @@ -42,17 +44,26 @@ const ShowMap = () => { selectedIndex={_mapOptions.findIndex( (i) => i.data === styleURL.styleURL, )} - onPress={(index) => onMapChange(index, _mapOptions[index].data)} + onPress={(index) => { + const { data } = _mapOptions[index]; + if (data === 'mount') { + setIsMounted((m) => !m); + return; + } + onMapChange(index, data); + }} /> - - + {isMounted ? ( + + - - + + + ) : null} ); }; diff --git a/ios/RNMBX/RNMBXMapView.swift b/ios/RNMBX/RNMBXMapView.swift index 34248c843..5aa9db7d4 100644 --- a/ios/RNMBX/RNMBXMapView.swift +++ b/ios/RNMBX/RNMBXMapView.swift @@ -154,7 +154,23 @@ class RNMBXCameraChanged : RNMBXEvent, RCTEvent { } @objc(RNMBXMapView) -open class RNMBXMapView: UIView { +open class RNMBXMapView: UIView, RCTInvalidating { + + public func invalidate() { + self.removeAllFeaturesFromMap(reason: .ViewRemoval) + +#if RNMBX_11 + cancelables.forEach { $0.cancel() } + cancelables.removeAll() +#endif + + _mapView.gestures.delegate = nil + _mapView.removeFromSuperview() + _mapView = nil + + self.removeFromSuperview() + } + var imageManager: ImageManager = ImageManager() var tapDelegate: IgnoreRNMBXMakerViewGestureDelegate? = nil