From f7f770218defc962e50da6f23fb5b9f1c848bf2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Sun, 1 Mar 2026 15:53:50 +0100 Subject: [PATCH 1/2] fix: remove MapboxV10 constant and dead code branches MapboxV10 was always hardcoded to true on both platforms. Remove the constant and all conditional branches that checked it, simplifying the codebase. Closes #4131. --- .../com/rnmapbox/rnmbx/modules/RNMBXModule.kt | 1 - docs/MapView.md | 2 +- docs/MarkerView.md | 2 - docs/docs.json | 4 +- ios/RNMBX/RNMBXModule.swift | 1 - setup-jest.js | 2 - src/components/MapView.tsx | 182 +++++++----------- src/components/MarkerView.tsx | 25 +-- src/modules/offline/offlineManager.ts | 16 +- 9 files changed, 76 insertions(+), 159 deletions(-) diff --git a/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt b/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt index 1f2d594ab3..d0c1115595 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt @@ -114,7 +114,6 @@ class RNMBXModule(private val mReactContext: ReactApplicationContext) : ReactCon val locationModuleCallbackNames: MutableMap = HashMap() locationModuleCallbackNames["Update"] = RNMBXLocationModule.LOCATION_UPDATE return MapBuilder.builder() - .put("MapboxV10", true) .put("StyleURL", styleURLS) .put("EventTypes", eventTypes) .put("StyleSource", styleSourceConsts) diff --git a/docs/MapView.md b/docs/MapView.md index d2ad2d0c82..af36a33c33 100644 --- a/docs/MapView.md +++ b/docs/MapView.md @@ -253,7 +253,7 @@ boolean ``` [Android only] Enable/Disable use of GLSurfaceView instead of TextureView. - _defaults to:_ `RNMBXModule.MapboxV10 ? true : false` + _defaults to:_ `true` ### requestDisallowInterceptTouchEvent diff --git a/docs/MarkerView.md b/docs/MarkerView.md index acb7626afc..c81967d7ec 100644 --- a/docs/MarkerView.md +++ b/docs/MarkerView.md @@ -52,8 +52,6 @@ the view, and (1, 1) is the bottom-right corner. Defaults to the center at (0.5, ```tsx boolean ``` -@v10 - Whether or not nearby markers on the map should all be displayed. If false, adjacent markers will 'collapse' and only one will be shown. Defaults to false. diff --git a/docs/docs.json b/docs/docs.json index 7f9b2bd2d3..6767add686 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -5320,7 +5320,7 @@ "name": "surfaceView", "required": false, "type": "boolean", - "default": "RNMBXModule.MapboxV10 ? true : false", + "default": "true", "description": "[Android only] Enable/Disable use of GLSurfaceView instead of TextureView." }, { @@ -5697,7 +5697,7 @@ "required": false, "type": "boolean", "default": "false", - "description": "@v10\n\nWhether or not nearby markers on the map should all be displayed. If false, adjacent\nmarkers will 'collapse' and only one will be shown. Defaults to false." + "description": "Whether or not nearby markers on the map should all be displayed. If false, adjacent\nmarkers will 'collapse' and only one will be shown. Defaults to false." }, { "name": "allowOverlapWithPuck", diff --git a/ios/RNMBX/RNMBXModule.swift b/ios/RNMBX/RNMBXModule.swift index 7d37b4ea92..033b9eccef 100644 --- a/ios/RNMBX/RNMBXModule.swift +++ b/ios/RNMBX/RNMBXModule.swift @@ -23,7 +23,6 @@ class RNMBXModule : NSObject { @objc func constantsToExport() -> [AnyHashable: Any]! { return [ - "MapboxV10":true, "StyleURL": [ "Street": StyleURI.streets.rawValue, diff --git a/setup-jest.js b/setup-jest.js index 5a046367e6..90dd35f26a 100644 --- a/setup-jest.js +++ b/setup-jest.js @@ -99,8 +99,6 @@ NativeModules.RNMBXModule = { setTelemetryEnabled: jest.fn(), setConnected: jest.fn(), clearData: jest.fn(), - - MapboxV10: true, }; NativeModules.RNMBXOfflineModule = nativeModule({ diff --git a/src/components/MapView.tsx b/src/components/MapView.tsx index b458c85176..fb9754157a 100644 --- a/src/components/MapView.tsx +++ b/src/components/MapView.tsx @@ -37,11 +37,6 @@ if (RNMBXModule == null) { 'Native part of Mapbox React Native libraries were not registered properly, double check our native installation guides.', ); } -if (!RNMBXModule.MapboxV10) { - console.warn( - '@rnmapbox/maps: Non v10 implementations are deprecated and will be removed in next version - see https://github.com/rnmapbox/maps/wiki/Deprecated-RNMapboxImpl-Maplibre', - ); -} const styles = StyleSheet.create({ matchParent: { flex: 1 }, @@ -494,7 +489,7 @@ class MapView extends NativeBridgeComponent( compassFadeWhenNorth: false, logoEnabled: true, scaleBarEnabled: true, - surfaceView: RNMBXModule.MapboxV10 ? true : false, + surfaceView: true, requestDisallowInterceptTouchEvent: false, regionWillChangeDebounceTime: 10, regionDidChangeDebounceTime: 500, @@ -591,83 +586,81 @@ class MapView extends NativeBridgeComponent( } _setHandledMapChangedEvents(props: Props) { - if (isAndroid() || RNMBXModule.MapboxV10) { - const events: string[] = []; - - function addIfHasHandler(name: CallbablePropKeysWithoutOn) { - if (props[`on${name}`] != null) { - if (EventTypes[name] == null) { - if (name === 'DidFailLoadingMap') { - console.warn( - `rnmapbox maps: on${name} is deprecated, please use onMapLoadingError`, - ); - } else { - console.warn(`rnmapbox maps: ${name} is not supported`); - } + const events: string[] = []; + + function addIfHasHandler(name: CallbablePropKeysWithoutOn) { + if (props[`on${name}`] != null) { + if (EventTypes[name] == null) { + if (name === 'DidFailLoadingMap') { + console.warn( + `rnmapbox maps: on${name} is deprecated, please use onMapLoadingError`, + ); } else { - events.push(EventTypes[name]); - return true; + console.warn(`rnmapbox maps: ${name} is not supported`); } + } else { + events.push(EventTypes[name]); + return true; } - return false; } + return false; + } - addIfHasHandler('RegionWillChange'); - addIfHasHandler('RegionIsChanging'); - addIfHasHandler('RegionDidChange'); - addIfHasHandler('UserLocationUpdate'); - addIfHasHandler('WillStartLoadingMap'); - addIfHasHandler('DidFinishLoadingMap'); - addIfHasHandler('MapLoadingError'); - addIfHasHandler('DidFailLoadingMap'); - addIfHasHandler('WillStartRenderingFrame'); - addIfHasHandler('DidFinishRenderingFrame'); - addIfHasHandler('DidFinishRenderingFrameFully'); - addIfHasHandler('WillStartRenderingMap'); - addIfHasHandler('DidFinishRenderingMap'); - addIfHasHandler('DidFinishRenderingMapFully'); - addIfHasHandler('DidFinishLoadingStyle'); - - addIfHasHandler('CameraChanged'); - addIfHasHandler('MapIdle'); - - if (addIfHasHandler('RegionDidChange')) { - if (!this.deprecationLogged.regionDidChange) { - console.warn( - 'onRegionDidChange is deprecated and will be removed in next release - please use onMapIdle. https://github.com/rnmapbox/maps/wiki/Deprecated-RegionIsDidChange', - ); - this.deprecationLogged.regionDidChange = true; - } - if (props.onMapIdle) { - console.warn( - 'rnmapbox/maps: only one of MapView.onRegionDidChange or onMapIdle is supported', - ); - } + addIfHasHandler('RegionWillChange'); + addIfHasHandler('RegionIsChanging'); + addIfHasHandler('RegionDidChange'); + addIfHasHandler('UserLocationUpdate'); + addIfHasHandler('WillStartLoadingMap'); + addIfHasHandler('DidFinishLoadingMap'); + addIfHasHandler('MapLoadingError'); + addIfHasHandler('DidFailLoadingMap'); + addIfHasHandler('WillStartRenderingFrame'); + addIfHasHandler('DidFinishRenderingFrame'); + addIfHasHandler('DidFinishRenderingFrameFully'); + addIfHasHandler('WillStartRenderingMap'); + addIfHasHandler('DidFinishRenderingMap'); + addIfHasHandler('DidFinishRenderingMapFully'); + addIfHasHandler('DidFinishLoadingStyle'); + + addIfHasHandler('CameraChanged'); + addIfHasHandler('MapIdle'); + + if (addIfHasHandler('RegionDidChange')) { + if (!this.deprecationLogged.regionDidChange) { + console.warn( + 'onRegionDidChange is deprecated and will be removed in next release - please use onMapIdle. https://github.com/rnmapbox/maps/wiki/Deprecated-RegionIsDidChange', + ); + this.deprecationLogged.regionDidChange = true; } - if (addIfHasHandler('RegionIsChanging')) { - if (!this.deprecationLogged.regionIsChanging) { - console.warn( - 'onRegionIsChanging is deprecated and will be removed in next release - please use onCameraChanged. https://github.com/rnmapbox/maps/wiki/Deprecated-RegionIsDidChange', - ); - this.deprecationLogged.regionIsChanging = true; - } - if (props.onCameraChanged) { - console.warn( - 'rnmapbox/maps: only one of MapView.onRegionIsChanging or onCameraChanged is supported', - ); - } + if (props.onMapIdle) { + console.warn( + 'rnmapbox/maps: only one of MapView.onRegionDidChange or onMapIdle is supported', + ); } - - if (props.onRegionWillChange) { + } + if (addIfHasHandler('RegionIsChanging')) { + if (!this.deprecationLogged.regionIsChanging) { + console.warn( + 'onRegionIsChanging is deprecated and will be removed in next release - please use onCameraChanged. https://github.com/rnmapbox/maps/wiki/Deprecated-RegionIsDidChange', + ); + this.deprecationLogged.regionIsChanging = true; + } + if (props.onCameraChanged) { console.warn( - 'onRegionWillChange is deprecated and will be removed in v10 - please use onRegionIsChanging', + 'rnmapbox/maps: only one of MapView.onRegionIsChanging or onCameraChanged is supported', ); } + } - this._runNativeMethod('setHandledMapChangedEvents', this._nativeRef, [ - events, - ]); + if (props.onRegionWillChange) { + console.warn( + 'onRegionWillChange is deprecated and will be removed in v10 - please use onRegionIsChanging', + ); } + + this._runNativeMethod('setHandledMapChangedEvents', this._nativeRef, [ + events, + ]); } /** @@ -770,10 +763,7 @@ class MapView extends NativeBridgeComponent( filter: FilterExpression | [] = [], layerIDs: string[] | null = null, ): Promise { - if ( - bbox != null && - (bbox.length === 4 || (RNMBXModule.MapboxV10 && bbox.length === 0)) - ) { + if (bbox != null && (bbox.length === 4 || bbox.length === 0)) { const res = await this._runNative<{ data: GeoJSON.FeatureCollection }>( 'queryRenderedFeaturesInRect', [bbox, getFilter(filter), layerIDs], @@ -891,12 +881,6 @@ class MapView extends NativeBridgeComponent( * v10 only */ async clearData(): Promise { - if (!RNMBXModule.MapboxV10) { - console.warn( - 'RNMapbox: clearData is only implemented in v10 implementation or later', - ); - return; - } await this._runNative('clearData'); } @@ -956,13 +940,6 @@ class MapView extends NativeBridgeComponent( sourceId: string, sourceLayerId: string | null = null, ): Promise { - if (!RNMBXModule.MapboxV10) { - console.warn( - 'RNMapbox: setFeatureState is only implemented in v10 implementation or later', - ); - return; - } - await this._runNative('setFeatureState', [ featureId, state, @@ -983,13 +960,6 @@ class MapView extends NativeBridgeComponent( sourceId: string, sourceLayerId: string | null = null, ): Promise>> { - if (!RNMBXModule.MapboxV10) { - console.warn( - 'RNMapbox: setFeatureState is only implemented in v10 implementation or later', - ); - return {}; - } - const res = await this._runNative<{ featureState: Readonly>; }>('getFeatureState', [featureId, sourceId, sourceLayerId]); @@ -1013,13 +983,6 @@ class MapView extends NativeBridgeComponent( sourceId: string, sourceLayerId: string | null = null, ): Promise { - if (!RNMBXModule.MapboxV10) { - console.warn( - 'RNMapbox: removeFeatureState is only implemented in v10 implementation or later', - ); - return; - } - await this._runNative('removeFeatureState', [ featureId, stateKey, @@ -1187,13 +1150,11 @@ class MapView extends NativeBridgeComponent( return; } - if (RNMBXModule.MapboxV10) { - if (!this.deprecationLogged.contentInset) { - console.warn( - '@rnmapbox/maps: contentInset is deprecated, use Camera padding instead.', - ); - this.deprecationLogged.contentInset = true; - } + if (!this.deprecationLogged.contentInset) { + console.warn( + '@rnmapbox/maps: contentInset is deprecated, use Camera padding instead.', + ); + this.deprecationLogged.contentInset = true; } if (!Array.isArray(this.props.contentInset)) { @@ -1235,9 +1196,6 @@ class MapView extends NativeBridgeComponent( } _setLocalizeLabels(props: Props) { - if (!RNMBXModule.MapboxV10) { - return; - } if (typeof props.localizeLabels === 'boolean') { props.localizeLabels = { locale: 'current', diff --git a/src/components/MarkerView.tsx b/src/components/MarkerView.tsx index 4489ee5990..d0df829e62 100644 --- a/src/components/MarkerView.tsx +++ b/src/components/MarkerView.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { NativeModules, Platform, type ViewProps } from 'react-native'; +import { type ViewProps } from 'react-native'; import RNMBXMakerViewContentComponent from '../specs/RNMBXMarkerViewContentNativeComponent'; import NativeMarkerViewComponent from '../specs/RNMBXMarkerViewNativeComponent'; @@ -7,10 +7,6 @@ import { type Position } from '../types/Position'; import { toJSONString } from '../utils'; import { makePoint } from '../utils/geoUtils'; -import PointAnnotation from './PointAnnotation'; - -const Mapbox = NativeModules.RNMBXModule; - type Props = ViewProps & { /** * The center point (specified as a map coordinate) of the marker. @@ -27,8 +23,6 @@ type Props = ViewProps & { }; /** - * @v10 - * * Whether or not nearby markers on the map should all be displayed. If false, adjacent * markers will 'collapse' and only one will be shown. Defaults to false. */ @@ -69,17 +63,6 @@ class MarkerView extends React.PureComponent { isSelected: false, }; - static lastId = 0; - __idForPointAnnotation?: string; - - _idForPointAnnotation(): string { - if (this.__idForPointAnnotation === undefined) { - MarkerView.lastId = MarkerView.lastId + 1; - this.__idForPointAnnotation = `MV-${MarkerView.lastId}`; - } - return this.__idForPointAnnotation; - } - _getCoordinate(coordinate: Position): string | undefined { if (!coordinate) { return undefined; @@ -99,12 +82,6 @@ class MarkerView extends React.PureComponent { ); } - if (Platform.OS === 'ios' && !Mapbox.MapboxV10) { - return ( - - ); - } - const { anchor = { x: 0.5, y: 0.5 } } = this.props; return ( diff --git a/src/modules/offline/offlineManager.ts b/src/modules/offline/offlineManager.ts index 5d25c1d6f3..e6a9f680a9 100644 --- a/src/modules/offline/offlineManager.ts +++ b/src/modules/offline/offlineManager.ts @@ -182,14 +182,7 @@ class OfflineManager { * @return {void} */ async invalidateAmbientCache(): Promise { - if (RNMBXModule.MapboxV10) { - console.warn( - 'RNMapbox: invalidateAmbientCache is not implemented on v10', - ); - return; - } - await this._initialize(); - await MapboxOfflineManager.invalidateAmbientCache(); + console.warn('RNMapbox: invalidateAmbientCache is not implemented on v10'); } /** @@ -204,12 +197,7 @@ class OfflineManager { * @return {void} */ async clearAmbientCache(): Promise { - if (RNMBXModule.MapboxV10) { - console.warn('RNMapbox: clearAmbientCache is not implemented on v10'); - return; - } - await this._initialize(); - await MapboxOfflineManager.clearAmbientCache(); + console.warn('RNMapbox: clearAmbientCache is not implemented on v10'); } /** From fb923fdaceb826a84528c30e165670fce4c46c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Sun, 1 Mar 2026 16:01:07 +0100 Subject: [PATCH 2/2] keep MapboxV10 constant as deprecated The constant actually means "v10 or later" and is always true. Keep it for backwards compatibility but mark as deprecated. --- android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt | 2 ++ ios/RNMBX/RNMBXModule.swift | 2 ++ setup-jest.js | 2 ++ 3 files changed, 6 insertions(+) diff --git a/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt b/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt index d0c1115595..b236fdf60d 100644 --- a/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt +++ b/android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt @@ -114,6 +114,8 @@ class RNMBXModule(private val mReactContext: ReactApplicationContext) : ReactCon val locationModuleCallbackNames: MutableMap = HashMap() locationModuleCallbackNames["Update"] = RNMBXLocationModule.LOCATION_UPDATE return MapBuilder.builder() + // Deprecated: means v10 or later, always true. Will be removed in next major version. + .put("MapboxV10", true) .put("StyleURL", styleURLS) .put("EventTypes", eventTypes) .put("StyleSource", styleSourceConsts) diff --git a/ios/RNMBX/RNMBXModule.swift b/ios/RNMBX/RNMBXModule.swift index 033b9eccef..6d6b1695ed 100644 --- a/ios/RNMBX/RNMBXModule.swift +++ b/ios/RNMBX/RNMBXModule.swift @@ -23,6 +23,8 @@ class RNMBXModule : NSObject { @objc func constantsToExport() -> [AnyHashable: Any]! { return [ + // Deprecated: means v10 or later, always true. Will be removed in next major version. + "MapboxV10":true, "StyleURL": [ "Street": StyleURI.streets.rawValue, diff --git a/setup-jest.js b/setup-jest.js index 90dd35f26a..79bd9b4bbc 100644 --- a/setup-jest.js +++ b/setup-jest.js @@ -99,6 +99,8 @@ NativeModules.RNMBXModule = { setTelemetryEnabled: jest.fn(), setConnected: jest.fn(), clearData: jest.fn(), + // Deprecated: means v10 or later, always true. Will be removed in next major version. + MapboxV10: true, }; NativeModules.RNMBXOfflineModule = nativeModule({