@maplibre/maplibre-react-native 10.0.0-alpha.6 → 10.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +3 -1
- package/.yarn/sdks/eslint/bin/eslint.js +8 -1
- package/.yarn/sdks/eslint/lib/api.js +8 -1
- package/.yarn/sdks/eslint/lib/unsupported-api.js +8 -1
- package/.yarn/sdks/prettier/bin/prettier.cjs +8 -1
- package/.yarn/sdks/prettier/index.cjs +8 -1
- package/.yarn/sdks/typescript/bin/tsc +8 -1
- package/.yarn/sdks/typescript/bin/tsserver +8 -1
- package/.yarn/sdks/typescript/lib/tsc.js +8 -1
- package/.yarn/sdks/typescript/lib/tsserver.js +20 -6
- package/.yarn/sdks/typescript/lib/tsserverlibrary.js +20 -6
- package/.yarn/sdks/typescript/lib/typescript.js +8 -1
- package/CHANGELOG.md +4 -0
- package/CONTRIBUTING.md +10 -9
- package/docs/Camera.md +3 -3
- package/docs/MapView.md +9 -33
- package/docs/UserLocation.md +10 -2
- package/docs/docs.json +16 -31
- package/javascript/Maplibre.ts +5 -1
- package/javascript/components/BackgroundLayer.tsx +27 -20
- package/javascript/components/Callout.tsx +40 -40
- package/javascript/components/Camera.tsx +421 -478
- package/javascript/components/CircleLayer.tsx +29 -22
- package/javascript/components/FillExtrusionLayer.tsx +23 -23
- package/javascript/components/FillLayer.tsx +22 -19
- package/javascript/components/HeatmapLayer.tsx +21 -19
- package/javascript/components/ImageSource.tsx +25 -32
- package/javascript/components/Images.tsx +36 -35
- package/javascript/components/Light.tsx +20 -47
- package/javascript/components/LineLayer.tsx +23 -20
- package/javascript/components/MapView.tsx +604 -554
- package/javascript/components/MarkerView.tsx +23 -38
- package/javascript/components/NativeUserLocation.tsx +3 -5
- package/javascript/components/PointAnnotation.tsx +111 -87
- package/javascript/components/RasterLayer.tsx +21 -18
- package/javascript/components/RasterSource.tsx +39 -42
- package/javascript/components/ShapeSource.tsx +287 -239
- package/javascript/components/Style.tsx +1 -1
- package/javascript/components/SymbolLayer.tsx +34 -28
- package/javascript/components/UserLocation.tsx +164 -151
- package/javascript/components/VectorSource.tsx +128 -117
- package/javascript/components/annotations/Annotation.tsx +105 -79
- package/javascript/{components/AbstractLayer.tsx → hooks/useAbstractLayer.ts} +54 -37
- package/javascript/hooks/useAbstractSource.ts +34 -0
- package/javascript/hooks/useNativeBridge.ts +125 -0
- package/javascript/hooks/useNativeRef.ts +13 -0
- package/javascript/hooks/useOnce.ts +12 -0
- package/javascript/utils/Logger.ts +3 -3
- package/package.json +2 -1
- package/javascript/components/AbstractSource.tsx +0 -27
- package/javascript/components/NativeBridgeComponent.tsx +0 -117
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import {runNativeCommand, isAndroid, NativeArg} from '../utils';
|
|
2
|
-
|
|
3
|
-
import {Component, SyntheticEvent} from 'react';
|
|
4
|
-
|
|
5
|
-
export type RNMLEvent<PayloadType = {[key: string]: string}> = {
|
|
6
|
-
payload: PayloadType;
|
|
7
|
-
type: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
let callbackIncrement = 0;
|
|
11
|
-
|
|
12
|
-
const NativeBridgeComponent = <
|
|
13
|
-
Props extends object,
|
|
14
|
-
BaseComponent extends new (...args: any[]) => Component<Props>,
|
|
15
|
-
>(
|
|
16
|
-
B: BaseComponent,
|
|
17
|
-
nativeModuleName: string,
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type,@typescript-eslint/explicit-module-boundary-types
|
|
19
|
-
) => {
|
|
20
|
-
const NativeBridge = class extends B {
|
|
21
|
-
_nativeModuleName: string;
|
|
22
|
-
_onAndroidCallback: (e: any) => void;
|
|
23
|
-
_callbackMap: Map<string, any>;
|
|
24
|
-
_preRefMapMethodQueue: any[];
|
|
25
|
-
|
|
26
|
-
constructor(...args: any[]) {
|
|
27
|
-
super(...args);
|
|
28
|
-
|
|
29
|
-
this._nativeModuleName = nativeModuleName;
|
|
30
|
-
this._onAndroidCallback = this._onAndroidCallback0.bind(this);
|
|
31
|
-
this._callbackMap = new Map();
|
|
32
|
-
this._preRefMapMethodQueue = [];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
_addAddAndroidCallback<ReturnType>(
|
|
36
|
-
id: string,
|
|
37
|
-
resolve: (value: ReturnType) => void,
|
|
38
|
-
reject: (error: Error) => void,
|
|
39
|
-
): void {
|
|
40
|
-
this._callbackMap.set(id, {resolve, reject});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
_removeAndroidCallback(id: string): void {
|
|
44
|
-
this._callbackMap.delete(id);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
_onAndroidCallback0(e: SyntheticEvent<Element, RNMLEvent>): void {
|
|
48
|
-
const callbackID = e.nativeEvent.type;
|
|
49
|
-
const callback = this._callbackMap.get(callbackID);
|
|
50
|
-
|
|
51
|
-
if (!callback) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
this._callbackMap.delete(callbackID);
|
|
56
|
-
const {payload} = e.nativeEvent;
|
|
57
|
-
if (payload.error) {
|
|
58
|
-
callback.reject.call(null, new Error(payload.error));
|
|
59
|
-
} else {
|
|
60
|
-
callback.resolve.call(null, payload);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async _runPendingNativeCommands<RefType extends Component>(
|
|
65
|
-
nativeRef: RefType | null | undefined,
|
|
66
|
-
): Promise<void> {
|
|
67
|
-
if (nativeRef) {
|
|
68
|
-
while (this._preRefMapMethodQueue.length > 0) {
|
|
69
|
-
const item = this._preRefMapMethodQueue.pop();
|
|
70
|
-
|
|
71
|
-
if (item && item.method && item.resolver) {
|
|
72
|
-
const res = await this._runNativeCommand(
|
|
73
|
-
item.method.name,
|
|
74
|
-
nativeRef,
|
|
75
|
-
item.method.args,
|
|
76
|
-
);
|
|
77
|
-
item.resolver(res);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
_runNativeCommand<RefType extends Component, ReturnType = NativeArg>(
|
|
84
|
-
methodName: string,
|
|
85
|
-
nativeRef: RefType | undefined | null,
|
|
86
|
-
args: NativeArg[] = [],
|
|
87
|
-
): Promise<ReturnType> {
|
|
88
|
-
if (!nativeRef) {
|
|
89
|
-
return new Promise(resolve => {
|
|
90
|
-
this._preRefMapMethodQueue.push({
|
|
91
|
-
method: {name: methodName, args},
|
|
92
|
-
resolver: resolve,
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (isAndroid()) {
|
|
98
|
-
return new Promise((resolve, reject) => {
|
|
99
|
-
callbackIncrement += 1;
|
|
100
|
-
const callbackID = `${methodName}_${callbackIncrement}`;
|
|
101
|
-
this._addAddAndroidCallback(callbackID, resolve, reject);
|
|
102
|
-
args.unshift(callbackID);
|
|
103
|
-
runNativeCommand(this._nativeModuleName, methodName, nativeRef, args);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return runNativeCommand(
|
|
107
|
-
this._nativeModuleName,
|
|
108
|
-
methodName,
|
|
109
|
-
nativeRef,
|
|
110
|
-
args,
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
return NativeBridge;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export default NativeBridgeComponent;
|