Skip to content

Commit d061296

Browse files
authored
Remove MapboxV10 constant and dead code (#4166)
* 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. * 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.
1 parent 5bf5512 commit d061296

File tree

9 files changed

+79
-156
lines changed

9 files changed

+79
-156
lines changed

android/src/main/java/com/rnmapbox/rnmbx/modules/RNMBXModule.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class RNMBXModule(private val mReactContext: ReactApplicationContext) : ReactCon
114114
val locationModuleCallbackNames: MutableMap<String, String> = HashMap()
115115
locationModuleCallbackNames["Update"] = RNMBXLocationModule.LOCATION_UPDATE
116116
return MapBuilder.builder<String, Any>()
117+
// Deprecated: means v10 or later, always true. Will be removed in next major version.
117118
.put("MapboxV10", true)
118119
.put("StyleURL", styleURLS)
119120
.put("EventTypes", eventTypes)

docs/MapView.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ boolean
253253
```
254254
[Android only] Enable/Disable use of GLSurfaceView instead of TextureView.
255255
256-
_defaults to:_ `RNMBXModule.MapboxV10 ? true : false`
256+
_defaults to:_ `true`
257257
258258
259259
### requestDisallowInterceptTouchEvent

docs/MarkerView.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ the view, and (1, 1) is the bottom-right corner. Defaults to the center at (0.5,
5252
```tsx
5353
boolean
5454
```
55-
@v10
56-
5755
Whether or not nearby markers on the map should all be displayed. If false, adjacent
5856
markers will 'collapse' and only one will be shown. Defaults to false.
5957

docs/docs.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5320,7 +5320,7 @@
53205320
"name": "surfaceView",
53215321
"required": false,
53225322
"type": "boolean",
5323-
"default": "RNMBXModule.MapboxV10 ? true : false",
5323+
"default": "true",
53245324
"description": "[Android only] Enable/Disable use of GLSurfaceView instead of TextureView."
53255325
},
53265326
{
@@ -5697,7 +5697,7 @@
56975697
"required": false,
56985698
"type": "boolean",
56995699
"default": "false",
5700-
"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."
5700+
"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."
57015701
},
57025702
{
57035703
"name": "allowOverlapWithPuck",

ios/RNMBX/RNMBXModule.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class RNMBXModule : NSObject {
2323
@objc
2424
func constantsToExport() -> [AnyHashable: Any]! {
2525
return [
26+
// Deprecated: means v10 or later, always true. Will be removed in next major version.
2627
"MapboxV10":true,
2728
"StyleURL":
2829
[

setup-jest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ NativeModules.RNMBXModule = {
9999
setTelemetryEnabled: jest.fn(),
100100
setConnected: jest.fn(),
101101
clearData: jest.fn(),
102-
102+
// Deprecated: means v10 or later, always true. Will be removed in next major version.
103103
MapboxV10: true,
104104
};
105105

src/components/MapView.tsx

Lines changed: 70 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ if (RNMBXModule == null) {
3737
'Native part of Mapbox React Native libraries were not registered properly, double check our native installation guides.',
3838
);
3939
}
40-
if (!RNMBXModule.MapboxV10) {
41-
console.warn(
42-
'@rnmapbox/maps: Non v10 implementations are deprecated and will be removed in next version - see https://github.com/rnmapbox/maps/wiki/Deprecated-RNMapboxImpl-Maplibre',
43-
);
44-
}
4540

4641
const styles = StyleSheet.create({
4742
matchParent: { flex: 1 },
@@ -494,7 +489,7 @@ class MapView extends NativeBridgeComponent(
494489
compassFadeWhenNorth: false,
495490
logoEnabled: true,
496491
scaleBarEnabled: true,
497-
surfaceView: RNMBXModule.MapboxV10 ? true : false,
492+
surfaceView: true,
498493
requestDisallowInterceptTouchEvent: false,
499494
regionWillChangeDebounceTime: 10,
500495
regionDidChangeDebounceTime: 500,
@@ -591,83 +586,81 @@ class MapView extends NativeBridgeComponent(
591586
}
592587

593588
_setHandledMapChangedEvents(props: Props) {
594-
if (isAndroid() || RNMBXModule.MapboxV10) {
595-
const events: string[] = [];
596-
597-
function addIfHasHandler(name: CallbablePropKeysWithoutOn) {
598-
if (props[`on${name}`] != null) {
599-
if (EventTypes[name] == null) {
600-
if (name === 'DidFailLoadingMap') {
601-
console.warn(
602-
`rnmapbox maps: on${name} is deprecated, please use onMapLoadingError`,
603-
);
604-
} else {
605-
console.warn(`rnmapbox maps: ${name} is not supported`);
606-
}
589+
const events: string[] = [];
590+
591+
function addIfHasHandler(name: CallbablePropKeysWithoutOn) {
592+
if (props[`on${name}`] != null) {
593+
if (EventTypes[name] == null) {
594+
if (name === 'DidFailLoadingMap') {
595+
console.warn(
596+
`rnmapbox maps: on${name} is deprecated, please use onMapLoadingError`,
597+
);
607598
} else {
608-
events.push(EventTypes[name]);
609-
return true;
599+
console.warn(`rnmapbox maps: ${name} is not supported`);
610600
}
601+
} else {
602+
events.push(EventTypes[name]);
603+
return true;
611604
}
612-
return false;
613605
}
606+
return false;
607+
}
614608

615-
addIfHasHandler('RegionWillChange');
616-
addIfHasHandler('RegionIsChanging');
617-
addIfHasHandler('RegionDidChange');
618-
addIfHasHandler('UserLocationUpdate');
619-
addIfHasHandler('WillStartLoadingMap');
620-
addIfHasHandler('DidFinishLoadingMap');
621-
addIfHasHandler('MapLoadingError');
622-
addIfHasHandler('DidFailLoadingMap');
623-
addIfHasHandler('WillStartRenderingFrame');
624-
addIfHasHandler('DidFinishRenderingFrame');
625-
addIfHasHandler('DidFinishRenderingFrameFully');
626-
addIfHasHandler('WillStartRenderingMap');
627-
addIfHasHandler('DidFinishRenderingMap');
628-
addIfHasHandler('DidFinishRenderingMapFully');
629-
addIfHasHandler('DidFinishLoadingStyle');
630-
631-
addIfHasHandler('CameraChanged');
632-
addIfHasHandler('MapIdle');
633-
634-
if (addIfHasHandler('RegionDidChange')) {
635-
if (!this.deprecationLogged.regionDidChange) {
636-
console.warn(
637-
'onRegionDidChange is deprecated and will be removed in next release - please use onMapIdle. https://github.com/rnmapbox/maps/wiki/Deprecated-RegionIsDidChange',
638-
);
639-
this.deprecationLogged.regionDidChange = true;
640-
}
641-
if (props.onMapIdle) {
642-
console.warn(
643-
'rnmapbox/maps: only one of MapView.onRegionDidChange or onMapIdle is supported',
644-
);
645-
}
609+
addIfHasHandler('RegionWillChange');
610+
addIfHasHandler('RegionIsChanging');
611+
addIfHasHandler('RegionDidChange');
612+
addIfHasHandler('UserLocationUpdate');
613+
addIfHasHandler('WillStartLoadingMap');
614+
addIfHasHandler('DidFinishLoadingMap');
615+
addIfHasHandler('MapLoadingError');
616+
addIfHasHandler('DidFailLoadingMap');
617+
addIfHasHandler('WillStartRenderingFrame');
618+
addIfHasHandler('DidFinishRenderingFrame');
619+
addIfHasHandler('DidFinishRenderingFrameFully');
620+
addIfHasHandler('WillStartRenderingMap');
621+
addIfHasHandler('DidFinishRenderingMap');
622+
addIfHasHandler('DidFinishRenderingMapFully');
623+
addIfHasHandler('DidFinishLoadingStyle');
624+
625+
addIfHasHandler('CameraChanged');
626+
addIfHasHandler('MapIdle');
627+
628+
if (addIfHasHandler('RegionDidChange')) {
629+
if (!this.deprecationLogged.regionDidChange) {
630+
console.warn(
631+
'onRegionDidChange is deprecated and will be removed in next release - please use onMapIdle. https://github.com/rnmapbox/maps/wiki/Deprecated-RegionIsDidChange',
632+
);
633+
this.deprecationLogged.regionDidChange = true;
646634
}
647-
if (addIfHasHandler('RegionIsChanging')) {
648-
if (!this.deprecationLogged.regionIsChanging) {
649-
console.warn(
650-
'onRegionIsChanging is deprecated and will be removed in next release - please use onCameraChanged. https://github.com/rnmapbox/maps/wiki/Deprecated-RegionIsDidChange',
651-
);
652-
this.deprecationLogged.regionIsChanging = true;
653-
}
654-
if (props.onCameraChanged) {
655-
console.warn(
656-
'rnmapbox/maps: only one of MapView.onRegionIsChanging or onCameraChanged is supported',
657-
);
658-
}
635+
if (props.onMapIdle) {
636+
console.warn(
637+
'rnmapbox/maps: only one of MapView.onRegionDidChange or onMapIdle is supported',
638+
);
659639
}
660-
661-
if (props.onRegionWillChange) {
640+
}
641+
if (addIfHasHandler('RegionIsChanging')) {
642+
if (!this.deprecationLogged.regionIsChanging) {
643+
console.warn(
644+
'onRegionIsChanging is deprecated and will be removed in next release - please use onCameraChanged. https://github.com/rnmapbox/maps/wiki/Deprecated-RegionIsDidChange',
645+
);
646+
this.deprecationLogged.regionIsChanging = true;
647+
}
648+
if (props.onCameraChanged) {
662649
console.warn(
663-
'onRegionWillChange is deprecated and will be removed in v10 - please use onRegionIsChanging',
650+
'rnmapbox/maps: only one of MapView.onRegionIsChanging or onCameraChanged is supported',
664651
);
665652
}
653+
}
666654

667-
this._runNativeMethod('setHandledMapChangedEvents', this._nativeRef, [
668-
events,
669-
]);
655+
if (props.onRegionWillChange) {
656+
console.warn(
657+
'onRegionWillChange is deprecated and will be removed in v10 - please use onRegionIsChanging',
658+
);
670659
}
660+
661+
this._runNativeMethod('setHandledMapChangedEvents', this._nativeRef, [
662+
events,
663+
]);
671664
}
672665

673666
/**
@@ -770,10 +763,7 @@ class MapView extends NativeBridgeComponent(
770763
filter: FilterExpression | [] = [],
771764
layerIDs: string[] | null = null,
772765
): Promise<GeoJSON.FeatureCollection | undefined> {
773-
if (
774-
bbox != null &&
775-
(bbox.length === 4 || (RNMBXModule.MapboxV10 && bbox.length === 0))
776-
) {
766+
if (bbox != null && (bbox.length === 4 || bbox.length === 0)) {
777767
const res = await this._runNative<{ data: GeoJSON.FeatureCollection }>(
778768
'queryRenderedFeaturesInRect',
779769
[bbox, getFilter(filter), layerIDs],
@@ -891,12 +881,6 @@ class MapView extends NativeBridgeComponent(
891881
* v10 only
892882
*/
893883
async clearData(): Promise<void> {
894-
if (!RNMBXModule.MapboxV10) {
895-
console.warn(
896-
'RNMapbox: clearData is only implemented in v10 implementation or later',
897-
);
898-
return;
899-
}
900884
await this._runNative<void>('clearData');
901885
}
902886

@@ -956,13 +940,6 @@ class MapView extends NativeBridgeComponent(
956940
sourceId: string,
957941
sourceLayerId: string | null = null,
958942
): Promise<void> {
959-
if (!RNMBXModule.MapboxV10) {
960-
console.warn(
961-
'RNMapbox: setFeatureState is only implemented in v10 implementation or later',
962-
);
963-
return;
964-
}
965-
966943
await this._runNative<void>('setFeatureState', [
967944
featureId,
968945
state,
@@ -983,13 +960,6 @@ class MapView extends NativeBridgeComponent(
983960
sourceId: string,
984961
sourceLayerId: string | null = null,
985962
): Promise<Readonly<Record<string, unknown>>> {
986-
if (!RNMBXModule.MapboxV10) {
987-
console.warn(
988-
'RNMapbox: setFeatureState is only implemented in v10 implementation or later',
989-
);
990-
return {};
991-
}
992-
993963
const res = await this._runNative<{
994964
featureState: Readonly<Record<string, unknown>>;
995965
}>('getFeatureState', [featureId, sourceId, sourceLayerId]);
@@ -1013,13 +983,6 @@ class MapView extends NativeBridgeComponent(
1013983
sourceId: string,
1014984
sourceLayerId: string | null = null,
1015985
): Promise<void> {
1016-
if (!RNMBXModule.MapboxV10) {
1017-
console.warn(
1018-
'RNMapbox: removeFeatureState is only implemented in v10 implementation or later',
1019-
);
1020-
return;
1021-
}
1022-
1023986
await this._runNative<void>('removeFeatureState', [
1024987
featureId,
1025988
stateKey,
@@ -1187,13 +1150,11 @@ class MapView extends NativeBridgeComponent(
11871150
return;
11881151
}
11891152

1190-
if (RNMBXModule.MapboxV10) {
1191-
if (!this.deprecationLogged.contentInset) {
1192-
console.warn(
1193-
'@rnmapbox/maps: contentInset is deprecated, use Camera padding instead.',
1194-
);
1195-
this.deprecationLogged.contentInset = true;
1196-
}
1153+
if (!this.deprecationLogged.contentInset) {
1154+
console.warn(
1155+
'@rnmapbox/maps: contentInset is deprecated, use Camera padding instead.',
1156+
);
1157+
this.deprecationLogged.contentInset = true;
11971158
}
11981159

11991160
if (!Array.isArray(this.props.contentInset)) {
@@ -1235,9 +1196,6 @@ class MapView extends NativeBridgeComponent(
12351196
}
12361197

12371198
_setLocalizeLabels(props: Props) {
1238-
if (!RNMBXModule.MapboxV10) {
1239-
return;
1240-
}
12411199
if (typeof props.localizeLabels === 'boolean') {
12421200
props.localizeLabels = {
12431201
locale: 'current',

src/components/MarkerView.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import React from 'react';
2-
import { NativeModules, Platform, type ViewProps } from 'react-native';
2+
import { type ViewProps } from 'react-native';
33

44
import RNMBXMakerViewContentComponent from '../specs/RNMBXMarkerViewContentNativeComponent';
55
import NativeMarkerViewComponent from '../specs/RNMBXMarkerViewNativeComponent';
66
import { type Position } from '../types/Position';
77
import { toJSONString } from '../utils';
88
import { makePoint } from '../utils/geoUtils';
99

10-
import PointAnnotation from './PointAnnotation';
11-
12-
const Mapbox = NativeModules.RNMBXModule;
13-
1410
type Props = ViewProps & {
1511
/**
1612
* The center point (specified as a map coordinate) of the marker.
@@ -27,8 +23,6 @@ type Props = ViewProps & {
2723
};
2824

2925
/**
30-
* @v10
31-
*
3226
* Whether or not nearby markers on the map should all be displayed. If false, adjacent
3327
* markers will 'collapse' and only one will be shown. Defaults to false.
3428
*/
@@ -69,17 +63,6 @@ class MarkerView extends React.PureComponent<Props> {
6963
isSelected: false,
7064
};
7165

72-
static lastId = 0;
73-
__idForPointAnnotation?: string;
74-
75-
_idForPointAnnotation(): string {
76-
if (this.__idForPointAnnotation === undefined) {
77-
MarkerView.lastId = MarkerView.lastId + 1;
78-
this.__idForPointAnnotation = `MV-${MarkerView.lastId}`;
79-
}
80-
return this.__idForPointAnnotation;
81-
}
82-
8366
_getCoordinate(coordinate: Position): string | undefined {
8467
if (!coordinate) {
8568
return undefined;
@@ -99,12 +82,6 @@ class MarkerView extends React.PureComponent<Props> {
9982
);
10083
}
10184

102-
if (Platform.OS === 'ios' && !Mapbox.MapboxV10) {
103-
return (
104-
<PointAnnotation id={this._idForPointAnnotation()} {...this.props} />
105-
);
106-
}
107-
10885
const { anchor = { x: 0.5, y: 0.5 } } = this.props;
10986

11087
return (

0 commit comments

Comments
 (0)