@rnmapbox/maps 10.1.12 → 10.1.13
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/android/src/main/java/com/rnmapbox/rnmbx/RNMBXPackage.kt +13 -2
- package/android/src/main/java/com/rnmapbox/rnmbx/components/camera/CameraStop.kt +0 -6
- package/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCamera.kt +11 -6
- package/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCameraManager.kt +2 -1
- package/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCameraModule.kt +51 -0
- package/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXVIewportManager.kt +2 -1
- package/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXCameraModuleSpec.java +41 -0
- package/ios/RNMBX/RNMBXCamera.swift +49 -54
- package/ios/RNMBX/RNMBXCameraModule.h +18 -0
- package/ios/RNMBX/RNMBXCameraModule.mm +67 -0
- package/lib/commonjs/components/Camera.js +14 -15
- package/lib/commonjs/components/Camera.js.map +1 -1
- package/lib/commonjs/components/Viewport.js +2 -43
- package/lib/commonjs/components/Viewport.js.map +1 -1
- package/lib/commonjs/specs/NativeRNMBXCameraModule.js +10 -0
- package/lib/commonjs/specs/NativeRNMBXCameraModule.js.map +1 -0
- package/lib/commonjs/utils/NativeCommands.js +50 -0
- package/lib/commonjs/utils/NativeCommands.js.map +1 -0
- package/lib/module/components/Camera.js +15 -16
- package/lib/module/components/Camera.js.map +1 -1
- package/lib/module/components/Viewport.js +1 -42
- package/lib/module/components/Viewport.js.map +1 -1
- package/lib/module/specs/NativeRNMBXCameraModule.js +6 -0
- package/lib/module/specs/NativeRNMBXCameraModule.js.map +1 -0
- package/lib/module/utils/NativeCommands.js +43 -0
- package/lib/module/utils/NativeCommands.js.map +1 -0
- package/lib/typescript/src/components/Camera.d.ts.map +1 -1
- package/lib/typescript/src/components/Viewport.d.ts +0 -3
- package/lib/typescript/src/components/Viewport.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeRNMBXCameraModule.d.ts +27 -0
- package/lib/typescript/src/specs/NativeRNMBXCameraModule.d.ts.map +1 -0
- package/lib/typescript/src/utils/NativeCommands.d.ts +25 -0
- package/lib/typescript/src/utils/NativeCommands.d.ts.map +1 -0
- package/package.json +1 -1
- package/setup-jest.js +4 -0
- package/src/components/Camera.tsx +22 -10
- package/src/components/Viewport.tsx +2 -94
- package/src/specs/NativeRNMBXCameraModule.ts +36 -0
- package/src/utils/NativeCommands.ts +89 -0
|
@@ -2,6 +2,7 @@ import React, {
|
|
|
2
2
|
forwardRef,
|
|
3
3
|
memo,
|
|
4
4
|
useCallback,
|
|
5
|
+
useEffect,
|
|
5
6
|
useImperativeHandle,
|
|
6
7
|
useMemo,
|
|
7
8
|
useRef,
|
|
@@ -13,6 +14,8 @@ import { type Position } from '../types/Position';
|
|
|
13
14
|
import { makeLatLngBounds, makePoint } from '../utils/geoUtils';
|
|
14
15
|
import { type NativeRefType } from '../utils/nativeRef';
|
|
15
16
|
import NativeCameraView from '../specs/RNMBXCameraNativeComponent';
|
|
17
|
+
import RNMBXCameraModule from '../specs/NativeRNMBXCameraModule';
|
|
18
|
+
import { NativeCommands, type NativeArg } from '../utils/NativeCommands';
|
|
16
19
|
|
|
17
20
|
const NativeModule = NativeModules.RNMBXModule;
|
|
18
21
|
|
|
@@ -250,6 +253,15 @@ export const Camera = memo(
|
|
|
250
253
|
null,
|
|
251
254
|
) as NativeRefType<NativeCameraProps>;
|
|
252
255
|
|
|
256
|
+
const commands = useMemo(() => new NativeCommands(RNMBXCameraModule), []);
|
|
257
|
+
|
|
258
|
+
useEffect(() => {
|
|
259
|
+
if (nativeCamera.current) {
|
|
260
|
+
commands.setNativeRef(nativeCamera.current);
|
|
261
|
+
}
|
|
262
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
263
|
+
}, [commands, nativeCamera.current]);
|
|
264
|
+
|
|
253
265
|
const buildNativeStop = useCallback(
|
|
254
266
|
(
|
|
255
267
|
stop: CameraStop,
|
|
@@ -380,8 +392,6 @@ export const Camera = memo(
|
|
|
380
392
|
return;
|
|
381
393
|
}
|
|
382
394
|
|
|
383
|
-
lastTS += 1;
|
|
384
|
-
|
|
385
395
|
if (!config.type)
|
|
386
396
|
// @ts-expect-error The compiler doesn't understand that the `config` union type is guaranteed
|
|
387
397
|
// to be an object type.
|
|
@@ -399,22 +409,26 @@ export const Camera = memo(
|
|
|
399
409
|
if (_nativeStop) {
|
|
400
410
|
_nativeStops = [..._nativeStops, _nativeStop];
|
|
401
411
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
412
|
+
|
|
413
|
+
commands.call<void>('updateCameraStop', [
|
|
414
|
+
{
|
|
415
|
+
stops: _nativeStops,
|
|
416
|
+
} as unknown as NativeArg[],
|
|
417
|
+
]);
|
|
405
418
|
}
|
|
406
419
|
} else if (config.type === 'CameraStop') {
|
|
407
420
|
const _nativeStop = buildNativeStop(config);
|
|
408
421
|
if (_nativeStop) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
422
|
+
commands.call<void>('updateCameraStop', [
|
|
423
|
+
_nativeStop as unknown as NativeArg,
|
|
424
|
+
]);
|
|
412
425
|
}
|
|
413
426
|
}
|
|
414
427
|
};
|
|
415
428
|
const setCamera = useCallback(_setCamera, [
|
|
416
429
|
allowUpdates,
|
|
417
430
|
buildNativeStop,
|
|
431
|
+
commands,
|
|
418
432
|
]);
|
|
419
433
|
|
|
420
434
|
const _fitBounds: CameraRef['fitBounds'] = (
|
|
@@ -594,8 +608,6 @@ export const Camera = memo(
|
|
|
594
608
|
),
|
|
595
609
|
);
|
|
596
610
|
|
|
597
|
-
let lastTS = 0;
|
|
598
|
-
|
|
599
611
|
const RNMBXCamera = NativeCameraView;
|
|
600
612
|
|
|
601
613
|
export type Camera = CameraRef;
|
|
@@ -7,18 +7,14 @@ import React, {
|
|
|
7
7
|
useMemo,
|
|
8
8
|
useRef,
|
|
9
9
|
} from 'react';
|
|
10
|
-
import {
|
|
11
|
-
NodeHandle,
|
|
12
|
-
findNodeHandle,
|
|
13
|
-
type NativeMethods,
|
|
14
|
-
type NativeSyntheticEvent,
|
|
15
|
-
} from 'react-native';
|
|
10
|
+
import { type NativeMethods, type NativeSyntheticEvent } from 'react-native';
|
|
16
11
|
|
|
17
12
|
import NativeViewport, {
|
|
18
13
|
type NativeViewportReal,
|
|
19
14
|
type OnStatusChangedEventTypeReal,
|
|
20
15
|
} from '../specs/RNMBXViewportNativeComponent';
|
|
21
16
|
import RNMBXViewportModule from '../specs/NativeRNMBXViewportModule';
|
|
17
|
+
import { NativeCommands } from '../utils/NativeCommands';
|
|
22
18
|
|
|
23
19
|
type FollowPuckOptions = {
|
|
24
20
|
/**
|
|
@@ -240,91 +236,3 @@ type NativeProps = Omit<Props, 'onStatusChanged'> & {
|
|
|
240
236
|
type RNMBXViewportRefType = Component<NativeProps> & Readonly<NativeMethods>;
|
|
241
237
|
|
|
242
238
|
const RNMBXViewport = NativeViewport as NativeViewportReal;
|
|
243
|
-
|
|
244
|
-
export type NativeArg =
|
|
245
|
-
| string
|
|
246
|
-
| number
|
|
247
|
-
| boolean
|
|
248
|
-
| null
|
|
249
|
-
| { [k: string]: NativeArg }
|
|
250
|
-
| NativeArg[]
|
|
251
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
252
|
-
| Function
|
|
253
|
-
| GeoJSON.Geometry
|
|
254
|
-
| undefined;
|
|
255
|
-
|
|
256
|
-
type FunctionKeys<T> = keyof {
|
|
257
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
258
|
-
[K in keyof T as T[K] extends Function ? K : never]: T[K];
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
type RefType = React.Component;
|
|
262
|
-
|
|
263
|
-
class NativeCommands<Spec extends object> {
|
|
264
|
-
module: Spec;
|
|
265
|
-
|
|
266
|
-
preRefMethodQueue: Array<{
|
|
267
|
-
method: { name: FunctionKeys<Spec>; args: NativeArg[] };
|
|
268
|
-
resolver: (value: unknown) => void;
|
|
269
|
-
}>;
|
|
270
|
-
|
|
271
|
-
nativeRef: RefType | undefined;
|
|
272
|
-
|
|
273
|
-
constructor(module: Spec) {
|
|
274
|
-
this.module = module;
|
|
275
|
-
this.preRefMethodQueue = [];
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
async setNativeRef(nativeRef: RefType) {
|
|
279
|
-
if (nativeRef) {
|
|
280
|
-
this.nativeRef = nativeRef;
|
|
281
|
-
while (this.preRefMethodQueue.length > 0) {
|
|
282
|
-
const item = this.preRefMethodQueue.pop();
|
|
283
|
-
|
|
284
|
-
if (item && item.method && item.resolver) {
|
|
285
|
-
const res = await this._call(
|
|
286
|
-
item.method.name,
|
|
287
|
-
nativeRef,
|
|
288
|
-
item.method.args,
|
|
289
|
-
);
|
|
290
|
-
item.resolver(res);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
call<T>(name: FunctionKeys<Spec>, args: NativeArg[]): Promise<T> {
|
|
297
|
-
if (this.nativeRef) {
|
|
298
|
-
return this._call(name, this.nativeRef, args);
|
|
299
|
-
} else {
|
|
300
|
-
return new Promise((resolve) => {
|
|
301
|
-
this.preRefMethodQueue.push({
|
|
302
|
-
method: { name, args },
|
|
303
|
-
resolver: resolve as (args: unknown) => void,
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
_call<T>(
|
|
310
|
-
name: FunctionKeys<Spec>,
|
|
311
|
-
nativeRef: RefType,
|
|
312
|
-
args: NativeArg[],
|
|
313
|
-
): Promise<T> {
|
|
314
|
-
const handle = findNodeHandle(nativeRef);
|
|
315
|
-
if (handle) {
|
|
316
|
-
return (
|
|
317
|
-
this.module[name] as (
|
|
318
|
-
arg0: NodeHandle,
|
|
319
|
-
...args: NativeArg[]
|
|
320
|
-
) => Promise<T>
|
|
321
|
-
)(handle, ...args);
|
|
322
|
-
} else {
|
|
323
|
-
throw new Error(
|
|
324
|
-
`Could not find handle for native ref ${module} when trying to invoke ${String(
|
|
325
|
-
name,
|
|
326
|
-
)}`,
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
|
|
2
|
+
import { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
4
|
+
|
|
5
|
+
type ViewRef = Int32 | null;
|
|
6
|
+
|
|
7
|
+
interface NativeCameraStop {
|
|
8
|
+
centerCoordinate?: string;
|
|
9
|
+
bounds?: string;
|
|
10
|
+
heading?: number;
|
|
11
|
+
pitch?: number;
|
|
12
|
+
zoom?: number;
|
|
13
|
+
paddingLeft?: number;
|
|
14
|
+
paddingRight?: number;
|
|
15
|
+
paddingTop?: number;
|
|
16
|
+
paddingBottom?: number;
|
|
17
|
+
duration?: number;
|
|
18
|
+
mode?: NativeAnimationMode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type Stop =
|
|
22
|
+
| {
|
|
23
|
+
stops: NativeCameraStop[];
|
|
24
|
+
}
|
|
25
|
+
| NativeCameraStop;
|
|
26
|
+
|
|
27
|
+
type NativeAnimationMode = 'flight' | 'ease' | 'linear' | 'none' | 'move';
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-unused-vars
|
|
30
|
+
type ObjectOr<T> = Object;
|
|
31
|
+
|
|
32
|
+
export interface Spec extends TurboModule {
|
|
33
|
+
updateCameraStop(viewRef: ViewRef, stops: ObjectOr<Stop>): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('RNMBXCameraModule');
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { NodeHandle, findNodeHandle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export type NativeArg =
|
|
4
|
+
| string
|
|
5
|
+
| number
|
|
6
|
+
| boolean
|
|
7
|
+
| null
|
|
8
|
+
| { [k: string]: NativeArg }
|
|
9
|
+
| NativeArg[]
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
11
|
+
| Function
|
|
12
|
+
| GeoJSON.Geometry
|
|
13
|
+
| undefined;
|
|
14
|
+
|
|
15
|
+
type FunctionKeys<T> = keyof {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
17
|
+
[K in keyof T as T[K] extends Function ? K : never]: T[K];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type RefType = React.Component;
|
|
21
|
+
|
|
22
|
+
export class NativeCommands<Spec extends object> {
|
|
23
|
+
module: Spec;
|
|
24
|
+
|
|
25
|
+
preRefMethodQueue: Array<{
|
|
26
|
+
method: { name: FunctionKeys<Spec>; args: NativeArg[] };
|
|
27
|
+
resolver: (value: unknown) => void;
|
|
28
|
+
}>;
|
|
29
|
+
|
|
30
|
+
nativeRef: RefType | undefined;
|
|
31
|
+
|
|
32
|
+
constructor(module: Spec) {
|
|
33
|
+
this.module = module;
|
|
34
|
+
this.preRefMethodQueue = [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async setNativeRef(nativeRef: RefType) {
|
|
38
|
+
if (nativeRef) {
|
|
39
|
+
this.nativeRef = nativeRef;
|
|
40
|
+
while (this.preRefMethodQueue.length > 0) {
|
|
41
|
+
const item = this.preRefMethodQueue.pop();
|
|
42
|
+
|
|
43
|
+
if (item && item.method && item.resolver) {
|
|
44
|
+
const res = await this._call(
|
|
45
|
+
item.method.name,
|
|
46
|
+
nativeRef,
|
|
47
|
+
item.method.args,
|
|
48
|
+
);
|
|
49
|
+
item.resolver(res);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
call<T>(name: FunctionKeys<Spec>, args: NativeArg[]): Promise<T> {
|
|
56
|
+
if (this.nativeRef) {
|
|
57
|
+
return this._call(name, this.nativeRef, args);
|
|
58
|
+
} else {
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
this.preRefMethodQueue.push({
|
|
61
|
+
method: { name, args },
|
|
62
|
+
resolver: resolve as (args: unknown) => void,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
_call<T>(
|
|
69
|
+
name: FunctionKeys<Spec>,
|
|
70
|
+
nativeRef: RefType,
|
|
71
|
+
args: NativeArg[],
|
|
72
|
+
): Promise<T> {
|
|
73
|
+
const handle = findNodeHandle(nativeRef);
|
|
74
|
+
if (handle) {
|
|
75
|
+
return (
|
|
76
|
+
this.module[name] as (
|
|
77
|
+
arg0: NodeHandle,
|
|
78
|
+
...args: NativeArg[]
|
|
79
|
+
) => Promise<T>
|
|
80
|
+
)(handle, ...args);
|
|
81
|
+
} else {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`Could not find handle for native ref ${module} when trying to invoke ${String(
|
|
84
|
+
name,
|
|
85
|
+
)}`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|