@maplibre/maplibre-react-native 10.1.1 → 10.1.2

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.
Files changed (46) hide show
  1. package/lib/commonjs/components/ShapeSource.js +2 -1
  2. package/lib/commonjs/components/ShapeSource.js.map +1 -1
  3. package/lib/commonjs/utils/animated/AbstractAnimatedCoordinates.js +8 -7
  4. package/lib/commonjs/utils/animated/AbstractAnimatedCoordinates.js.map +1 -1
  5. package/lib/commonjs/utils/animated/AnimatedExtractCoordinateFromArray.js +1 -2
  6. package/lib/commonjs/utils/animated/AnimatedExtractCoordinateFromArray.js.map +1 -1
  7. package/lib/commonjs/utils/animated/AnimatedRouteCoordinatesArray.js +28 -38
  8. package/lib/commonjs/utils/animated/AnimatedRouteCoordinatesArray.js.map +1 -1
  9. package/lib/commonjs/utils/animated/AnimatedShape.js +11 -7
  10. package/lib/commonjs/utils/animated/AnimatedShape.js.map +1 -1
  11. package/lib/module/components/ShapeSource.js +2 -1
  12. package/lib/module/components/ShapeSource.js.map +1 -1
  13. package/lib/module/utils/animated/AbstractAnimatedCoordinates.js +8 -7
  14. package/lib/module/utils/animated/AbstractAnimatedCoordinates.js.map +1 -1
  15. package/lib/module/utils/animated/AnimatedExtractCoordinateFromArray.js +1 -3
  16. package/lib/module/utils/animated/AnimatedExtractCoordinateFromArray.js.map +1 -1
  17. package/lib/module/utils/animated/AnimatedRouteCoordinatesArray.js +29 -39
  18. package/lib/module/utils/animated/AnimatedRouteCoordinatesArray.js.map +1 -1
  19. package/lib/module/utils/animated/AnimatedShape.js +11 -7
  20. package/lib/module/utils/animated/AnimatedShape.js.map +1 -1
  21. package/lib/typescript/commonjs/src/components/ShapeSource.d.ts +1 -1
  22. package/lib/typescript/commonjs/src/components/ShapeSource.d.ts.map +1 -1
  23. package/lib/typescript/commonjs/src/utils/animated/AbstractAnimatedCoordinates.d.ts +12 -12
  24. package/lib/typescript/commonjs/src/utils/animated/AbstractAnimatedCoordinates.d.ts.map +1 -1
  25. package/lib/typescript/commonjs/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts +5 -3
  26. package/lib/typescript/commonjs/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts.map +1 -1
  27. package/lib/typescript/commonjs/src/utils/animated/AnimatedRouteCoordinatesArray.d.ts +33 -21
  28. package/lib/typescript/commonjs/src/utils/animated/AnimatedRouteCoordinatesArray.d.ts.map +1 -1
  29. package/lib/typescript/commonjs/src/utils/animated/AnimatedShape.d.ts +8 -4
  30. package/lib/typescript/commonjs/src/utils/animated/AnimatedShape.d.ts.map +1 -1
  31. package/lib/typescript/module/src/components/ShapeSource.d.ts +1 -1
  32. package/lib/typescript/module/src/components/ShapeSource.d.ts.map +1 -1
  33. package/lib/typescript/module/src/utils/animated/AbstractAnimatedCoordinates.d.ts +12 -12
  34. package/lib/typescript/module/src/utils/animated/AbstractAnimatedCoordinates.d.ts.map +1 -1
  35. package/lib/typescript/module/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts +5 -3
  36. package/lib/typescript/module/src/utils/animated/AnimatedExtractCoordinateFromArray.d.ts.map +1 -1
  37. package/lib/typescript/module/src/utils/animated/AnimatedRouteCoordinatesArray.d.ts +33 -21
  38. package/lib/typescript/module/src/utils/animated/AnimatedRouteCoordinatesArray.d.ts.map +1 -1
  39. package/lib/typescript/module/src/utils/animated/AnimatedShape.d.ts +8 -4
  40. package/lib/typescript/module/src/utils/animated/AnimatedShape.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/components/ShapeSource.tsx +58 -53
  43. package/src/utils/animated/AbstractAnimatedCoordinates.ts +26 -15
  44. package/src/utils/animated/AnimatedExtractCoordinateFromArray.ts +10 -6
  45. package/src/utils/animated/AnimatedRouteCoordinatesArray.ts +63 -51
  46. package/src/utils/animated/AnimatedShape.ts +22 -13
@@ -1,5 +1,21 @@
1
1
  import { type Coord, type Units } from "@turf/helpers";
2
2
  import { AbstractAnimatedCoordinates, type AnimatedCoordinates } from "./AbstractAnimatedCoordinates";
3
+ interface AnimatedRouteToValue {
4
+ end: {
5
+ point: Coord | AnimatedCoordinates;
6
+ }
7
+ /**
8
+ * Animate to this length of the coordinates array
9
+ */
10
+ | {
11
+ along: number;
12
+ units?: Units;
13
+ };
14
+ /**
15
+ * @deprecated Use `end.units` in conjunction with `end.along` instead
16
+ */
17
+ units?: Units;
18
+ }
3
19
  interface AnimatedRouteState {
4
20
  actRoute?: AnimatedCoordinates[];
5
21
  fullRoute: AnimatedCoordinates[];
@@ -7,47 +23,43 @@ interface AnimatedRouteState {
7
23
  from: number;
8
24
  current?: number;
9
25
  to: number;
10
- point?: Coord;
11
- along?: Coord;
12
- };
26
+ } & ({
27
+ point?: Coord | AnimatedCoordinates;
28
+ } | {
29
+ along?: number;
30
+ });
13
31
  }
14
- export declare class AnimatedRouteCoordinatesArray extends AbstractAnimatedCoordinates<AnimatedRouteState> {
32
+ export declare class AnimatedRouteCoordinatesArray extends AbstractAnimatedCoordinates<AnimatedRouteState, AnimatedRouteToValue> {
15
33
  /**
16
34
  * Calculate initial state
17
35
  *
18
- * @param {*} args - to value from animate
19
- * @returns {object} - the state object
36
+ * @param {AnimatedCoordinates[]} coordinatesArray
37
+ * @returns {AnimatedRouteState}
20
38
  */
21
39
  onInitialState(coordinatesArray: AnimatedCoordinates[]): AnimatedRouteState;
22
40
  /**
23
- * Calculate value from state.
41
+ * Calculate value from state
24
42
  *
25
- * @param {object} state - either state from initialState and/or from calculate
26
- * @returns {object}
43
+ * @param {AnimatedRouteState} state Previous state
44
+ * @returns {AnimatedCoordinates[]}
27
45
  */
28
- onGetValue(state: AnimatedRouteState): AnimatedRouteState | AnimatedCoordinates[];
46
+ onGetValue(state: AnimatedRouteState): AnimatedCoordinates[];
29
47
  /**
30
48
  * Calculates state based on startingState and progress, returns a new state
31
49
  *
32
- * @param {object} state - state object from initialState and/or from calculate
33
- * @param {number} progress - value between 0 and 1
34
- * @returns {object} next state
50
+ * @param {AnimatedRouteState} state Previous state
51
+ * @param {number} progress Value between 0 and 1
52
+ * @returns {AnimatedRouteState}
35
53
  */
36
54
  onCalculate(state: AnimatedRouteState, progress: number): AnimatedRouteState;
37
55
  /**
38
56
  * Subclasses can override to start a new animation
39
57
  *
58
+ * @param {AnimatedRouteState} state
40
59
  * @param {*} toValue - to value from animate
41
- * @param {*} actCoords - the current coordinates array to start from
42
60
  * @returns {object} The state
43
61
  */
44
- onStart(state: AnimatedRouteState, toValue: {
45
- end: {
46
- point?: Coord;
47
- along?: number;
48
- };
49
- units?: Units;
50
- }): AnimatedRouteState;
62
+ onStart(state: AnimatedRouteState, toValue: AnimatedRouteToValue): AnimatedRouteState;
51
63
  get originalRoute(): AnimatedCoordinates[];
52
64
  }
53
65
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"AnimatedRouteCoordinatesArray.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/animated/AnimatedRouteCoordinatesArray.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,KAAK,EACV,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AAIvB,OAAO,EACL,2BAA2B,EAC3B,KAAK,mBAAmB,EACzB,MAAM,+BAA+B,CAAC;AAEvC,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACjC,SAAS,EAAE,mBAAmB,EAAE,CAAC;IACjC,GAAG,EAAE;QACH,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,KAAK,CAAC,EAAE,KAAK,CAAC;KACf,CAAC;CACH;AAED,qBAAa,6BAA8B,SAAQ,2BAA2B,CAAC,kBAAkB,CAAC;IAChG;;;;;OAKG;IACH,cAAc,CAAC,gBAAgB,EAAE,mBAAmB,EAAE,GAAG,kBAAkB;IAS3E;;;;;OAKG;IACH,UAAU,CACR,KAAK,EAAE,kBAAkB,GACxB,kBAAkB,GAAG,mBAAmB,EAAE;IAI7C;;;;;;OAMG;IACH,WAAW,CAAC,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,GAAG,kBAAkB;IAgC5E;;;;;;OAMG;IACH,OAAO,CACL,KAAK,EAAE,kBAAkB,EACzB,OAAO,EAAE;QAAE,GAAG,EAAE;YAAE,KAAK,CAAC,EAAE,KAAK,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE,GACjE,kBAAkB;IA0CrB,IAAI,aAAa,IAAI,mBAAmB,EAAE,CAEzC;CACF"}
1
+ {"version":3,"file":"AnimatedRouteCoordinatesArray.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/animated/AnimatedRouteCoordinatesArray.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,KAAK,EAGV,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AAIvB,OAAO,EACL,2BAA2B,EAC3B,KAAK,mBAAmB,EACzB,MAAM,+BAA+B,CAAC;AAEvC,UAAU,oBAAoB;IAC5B,GAAG,EAGD;QAAE,KAAK,EAAE,KAAK,GAAG,mBAAmB,CAAA;KAAE;IACtC;;OAEG;OACD;QACE,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,KAAK,CAAC;KACf,CAAC;IAEN;;OAEG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,UAAU,kBAAkB;IAC1B,QAAQ,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACjC,SAAS,EAAE,mBAAmB,EAAE,CAAC;IACjC,GAAG,EAAE;QACH,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,EAAE,EAAE,MAAM,CAAC;KACZ,GAAG,CAAC;QAAE,KAAK,CAAC,EAAE,KAAK,GAAG,mBAAmB,CAAA;KAAE,GAAG;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpE;AAED,qBAAa,6BAA8B,SAAQ,2BAA2B,CAC5E,kBAAkB,EAClB,oBAAoB,CACrB;IACC;;;;;OAKG;IACH,cAAc,CAAC,gBAAgB,EAAE,mBAAmB,EAAE,GAAG,kBAAkB;IAS3E;;;;;OAKG;IACH,UAAU,CAAC,KAAK,EAAE,kBAAkB,GAAG,mBAAmB,EAAE;IAI5D;;;;;;OAMG;IACH,WAAW,CAAC,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,GAAG,kBAAkB;IAgC5E;;;;;;OAMG;IACH,OAAO,CACL,KAAK,EAAE,kBAAkB,EACzB,OAAO,EAAE,oBAAoB,GAC5B,kBAAkB;IAoCrB,IAAI,aAAa,IAAI,mBAAmB,EAAE,CAEzC;CACF"}
@@ -1,24 +1,28 @@
1
1
  import { Animated } from "react-native";
2
- import { AnimatedCoordinatesArray } from "./AnimatedCoordinatesArray";
2
+ import type { AnimatedCoordinatesArray } from "./AnimatedCoordinatesArray";
3
3
  import { AnimatedExtractCoordinateFromArray } from "./AnimatedExtractCoordinateFromArray";
4
4
  import { AnimatedRouteCoordinatesArray } from "./AnimatedRouteCoordinatesArray";
5
5
  declare const AnimatedWithChildren: any;
6
6
  type Shape = {
7
7
  type: "Point";
8
- coordinates: AnimatedExtractCoordinateFromArray | AnimatedRouteCoordinatesArray;
8
+ coordinates: AnimatedExtractCoordinateFromArray;
9
9
  } | {
10
10
  type: "LineString";
11
- coordinates: AnimatedCoordinatesArray;
11
+ coordinates: AnimatedCoordinatesArray | AnimatedRouteCoordinatesArray;
12
12
  };
13
13
  /**
14
14
  * AnimatedShape can be used to have animated properties inside the shape property
15
+ *
16
+ * Equivalent of AnimatedStyle for shapes
17
+ * https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Animated/nodes/AnimatedStyle.js
18
+ *
15
19
  * @example
16
20
  * <AnimatedShapeSource ... shape={new AnimatedShape({type:'LineString', coordinates: animatedCoords})} />
17
21
  */
18
22
  export declare class AnimatedShape extends AnimatedWithChildren {
19
23
  constructor(shape: Shape);
20
24
  _walkShapeAndGetValues(value: any): any;
21
- __getValue(): any;
25
+ __getValue(): GeoJSON.Point | GeoJSON.LineString;
22
26
  _walkAndProcess(value: any, cb: (value: Animated.Node) => void): void;
23
27
  __attach(): void;
24
28
  __detach(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"AnimatedShape.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/animated/AnimatedShape.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAIhF,QAAA,MAAM,oBAAoB,KAA0C,CAAC;AASrE,KAAK,KAAK,GACN;IACE,IAAI,EAAE,OAAO,CAAC;IACd,WAAW,EACP,kCAAkC,GAClC,6BAA6B,CAAC;CACnC,GACD;IACE,IAAI,EAAE,YAAY,CAAC;IACnB,WAAW,EAAE,wBAAwB,CAAC;CACvC,CAAC;AAEN;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,oBAAoB;gBAIzC,KAAK,EAAE,KAAK;IAKxB,sBAAsB,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG;IAkBvC,UAAU,IAAI,GAAG;IAMjB,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,KAAK,IAAI,GAAG,IAAI;IAarE,QAAQ,IAAI,IAAI;IAIhB,QAAQ,IAAI,IAAI;CAIjB"}
1
+ {"version":3,"file":"AnimatedShape.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/animated/AnimatedShape.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAAE,kCAAkC,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAGhF,QAAA,MAAM,oBAAoB,KAA0C,CAAC;AAUrE,KAAK,KAAK,GACN;IACE,IAAI,EAAE,OAAO,CAAC;IACd,WAAW,EAAE,kCAAkC,CAAC;CACjD,GACD;IACE,IAAI,EAAE,YAAY,CAAC;IACnB,WAAW,EAAE,wBAAwB,GAAG,6BAA6B,CAAC;CACvE,CAAC;AAEN;;;;;;;;GAQG;AACH,qBAAa,aAAc,SAAQ,oBAAoB;gBACzC,KAAK,EAAE,KAAK;IAKxB,sBAAsB,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG;IAuBvC,UAAU,IAAI,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,UAAU;IAWhD,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,KAAK,IAAI,GAAG,IAAI;IAarE,QAAQ,IAAI,IAAI;IAIhB,QAAQ,IAAI,IAAI;CAIjB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@maplibre/maplibre-react-native",
3
3
  "description": "React Native library for creating maps with MapLibre Native for Android & iOS",
4
- "version": "10.1.1",
4
+ "version": "10.1.2",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": true
@@ -32,7 +32,7 @@ const MLRNModule = NativeModules.MLRNModule;
32
32
  export const NATIVE_MODULE_NAME = "MLRNShapeSource";
33
33
 
34
34
  interface NativeProps {
35
- shape?: string;
35
+ shape?: object | string;
36
36
  }
37
37
 
38
38
  type MLRNShapeSourceRefType = Component<NativeProps> & Readonly<NativeMethods>;
@@ -164,57 +164,62 @@ export const ShapeSource = memo(
164
164
  }: ShapeSourceProps,
165
165
  ref,
166
166
  ) => {
167
- useImperativeHandle(
168
- ref,
169
- (): ShapeSourceRef => ({
170
- /**
171
- * Returns all features from the source that match the query parameters regardless of whether or not the feature is
172
- * currently rendered on the map.
173
- *
174
- * @example
175
- * shapeSource.features()
176
- *
177
- * @param {Array=} filter - an optional filter statement to filter the returned Features.
178
- * @return {GeoJSON.FeatureCollection}
179
- */
180
- features,
181
- /**
182
- * Returns the zoom needed to expand the cluster.
183
- *
184
- * @example
185
- * const zoom = await shapeSource.getClusterExpansionZoom(clusterId);
186
- *
187
- * @param {GeoJSON.Feature} feature - The feature cluster to expand.
188
- * @return {number}
189
- */
190
- getClusterExpansionZoom,
191
- /**
192
- * Returns the FeatureCollection from the cluster.
193
- *
194
- * @example
195
- * const collection = await shapeSource.getClusterLeaves(clusterId, limit, offset);
196
- *
197
- * @param {GeoJSON.Feature} feature - The feature cluster to expand.
198
- * @param {number} limit - The number of points to return.
199
- * @param {number} offset - The amount of points to skip (for pagination).
200
- * @return {GeoJSON.FeatureCollection}
201
- */
202
- getClusterLeaves,
203
- /**
204
- * Returns the FeatureCollection from the cluster (on the next zoom level).
205
- *
206
- * @example
207
- * const collection = await shapeSource.getClusterChildren(clusterId);
208
- *
209
- * @param {GeoJSON.Feature} feature - The feature cluster to expand.
210
- * @return {GeoJSON.FeatureCollection}
211
- */
212
- getClusterChildren,
213
- setNativeProps,
214
- onPress,
215
- _nativeRef: _nativeRef.current,
216
- }),
217
- );
167
+ useImperativeHandle(ref, () => ({
168
+ ..._nativeRef.current,
169
+
170
+ /**
171
+ * Returns all features from the source that match the query parameters regardless of whether or not the feature is
172
+ * currently rendered on the map.
173
+ *
174
+ * @example
175
+ * shapeSource.features()
176
+ *
177
+ * @param {Array=} filter - an optional filter statement to filter the returned Features.
178
+ * @return {GeoJSON.FeatureCollection}
179
+ */
180
+ features,
181
+
182
+ /**
183
+ * Returns the zoom needed to expand the cluster.
184
+ *
185
+ * @example
186
+ * const zoom = await shapeSource.getClusterExpansionZoom(clusterId);
187
+ *
188
+ * @param {GeoJSON.Feature} feature - The feature cluster to expand.
189
+ * @return {number}
190
+ */
191
+ getClusterExpansionZoom,
192
+
193
+ /**
194
+ * Returns the FeatureCollection from the cluster.
195
+ *
196
+ * @example
197
+ * const collection = await shapeSource.getClusterLeaves(clusterId, limit, offset);
198
+ *
199
+ * @param {GeoJSON.Feature} feature - The feature cluster to expand.
200
+ * @param {number} limit - The number of points to return.
201
+ * @param {number} offset - The amount of points to skip (for pagination).
202
+ * @return {GeoJSON.FeatureCollection}
203
+ */
204
+ getClusterLeaves,
205
+
206
+ /**
207
+ * Returns the FeatureCollection from the cluster (on the next zoom level).
208
+ *
209
+ * @example
210
+ * const collection = await shapeSource.getClusterChildren(clusterId);
211
+ *
212
+ * @param {GeoJSON.Feature} feature - The feature cluster to expand.
213
+ * @return {GeoJSON.FeatureCollection}
214
+ */
215
+ getClusterChildren,
216
+
217
+ setNativeProps,
218
+
219
+ onPress,
220
+
221
+ _nativeRef: _nativeRef.current,
222
+ }));
218
223
 
219
224
  const _nativeRef = useRef<MLRNShapeSourceRefType>();
220
225
 
@@ -297,7 +302,7 @@ export const ShapeSource = memo(
297
302
  const shallowProps = Object.assign({}, nativeProps);
298
303
 
299
304
  // Adds support for Animated
300
- if (shallowProps.shape && typeof shallowProps !== "string") {
305
+ if (shallowProps.shape && typeof shallowProps.shape !== "string") {
301
306
  shallowProps.shape = JSON.stringify(shallowProps.shape);
302
307
  }
303
308
 
@@ -1,8 +1,8 @@
1
1
  import { Animated } from "react-native";
2
2
 
3
- // see
4
- // https://github.com/facebook/react-native/blob/master/Libraries/Animated/src/nodes/AnimatedWithChildren.js
3
+ // https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Animated/nodes/AnimatedWithChildren.js
5
4
  const AnimatedWithChildren = Object.getPrototypeOf(Animated.ValueXY);
5
+
6
6
  if (__DEV__) {
7
7
  if (AnimatedWithChildren.name !== "AnimatedWithChildren") {
8
8
  console.error(
@@ -19,20 +19,21 @@ const defaultConfig = {
19
19
 
20
20
  export abstract class AbstractAnimatedCoordinates<
21
21
  State,
22
+ ToValue = AnimatedCoordinates[],
22
23
  > extends AnimatedWithChildren {
23
- constructor(coords: AnimatedCoordinates[]) {
24
+ constructor(coordinates: AnimatedCoordinates[]) {
24
25
  super();
25
26
 
26
- this.state = this.onInitialState(coords);
27
+ this.state = this.onInitialState(coordinates);
27
28
  }
28
29
 
29
30
  /**
30
31
  * Subclasses can override to calculate initial state
31
32
  *
32
- * @param {AnimatedCoordinates} coordinatesArray - to value from animate
33
33
  * @returns {object} - the state object
34
+ * @param coordinates
34
35
  */
35
- abstract onInitialState(coords: AnimatedCoordinates[]): State;
36
+ abstract onInitialState(coordinates: AnimatedCoordinates[]): State;
36
37
  /**
37
38
  * Calculates state based on startingState and progress, returns a new state
38
39
  *
@@ -45,15 +46,15 @@ export abstract class AbstractAnimatedCoordinates<
45
46
  animate(
46
47
  progressValue: Animated.Value,
47
48
  progressAnimation: Animated.CompositeAnimation,
48
- config: (
49
+ config: Omit<
49
50
  | Animated.TimingAnimationConfig
50
51
  | Animated.SpringAnimationConfig
51
- | Animated.DecayAnimationConfig
52
- ) & { toValue: AnimatedCoordinates[] },
52
+ | Animated.DecayAnimationConfig,
53
+ "toValue"
54
+ > & { toValue: ToValue },
53
55
  ): Animated.CompositeAnimation {
54
56
  const onAnimationStart = (animation: Animated.CompositeAnimation): void => {
55
57
  if (this.animation) {
56
- // there was a started but not finsihed animation
57
58
  const actProgress = this.progressValue.__getValue();
58
59
  this.animation.stop();
59
60
  this.state = this.onCalculate(this.state, actProgress);
@@ -78,8 +79,11 @@ export abstract class AbstractAnimatedCoordinates<
78
79
  }
79
80
 
80
81
  timing(
81
- config: Animated.TimingAnimationConfig & {
82
- toValue: AnimatedCoordinates[];
82
+ config: Omit<
83
+ Animated.TimingAnimationConfig,
84
+ "toValue" | "useNativeDriver"
85
+ > & {
86
+ toValue: ToValue;
83
87
  },
84
88
  ): Animated.CompositeAnimation {
85
89
  const progressValue = new Animated.Value(0.0);
@@ -90,12 +94,17 @@ export abstract class AbstractAnimatedCoordinates<
90
94
  ...config,
91
95
  toValue: 1.0,
92
96
  }),
93
- config,
97
+ {
98
+ ...defaultConfig,
99
+ ...config,
100
+ },
94
101
  );
95
102
  }
96
103
 
97
104
  spring(
98
- config: Animated.SpringAnimationConfig & { toValue: AnimatedCoordinates[] },
105
+ config: Omit<Animated.SpringAnimationConfig, "toValue"> & {
106
+ toValue: ToValue;
107
+ },
99
108
  ): Animated.CompositeAnimation {
100
109
  const progressValue = new Animated.Value(0.0);
101
110
  return this.animate(
@@ -110,7 +119,9 @@ export abstract class AbstractAnimatedCoordinates<
110
119
  }
111
120
 
112
121
  decay(
113
- config: Animated.DecayAnimationConfig & { toValue: AnimatedCoordinates[] },
122
+ config: Omit<Animated.DecayAnimationConfig, "toValue"> & {
123
+ toValue: ToValue;
124
+ },
114
125
  ): Animated.CompositeAnimation {
115
126
  const progressValue = new Animated.Value(0.0);
116
127
  return this.animate(
@@ -1,8 +1,11 @@
1
1
  import { Animated } from "react-native";
2
2
 
3
- // see
4
- // https://github.com/facebook/react-native/blob/master/Libraries/Animated/src/nodes/AnimatedWithChildren.js
3
+ import type { AnimatedCoordinates } from "./AbstractAnimatedCoordinates";
4
+ import { AnimatedRouteCoordinatesArray } from "./AnimatedRouteCoordinatesArray";
5
+
6
+ // https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Animated/nodes/AnimatedWithChildren.js
5
7
  const AnimatedWithChildren = Object.getPrototypeOf(Animated.ValueXY);
8
+
6
9
  if (__DEV__) {
7
10
  if (AnimatedWithChildren.name !== "AnimatedWithChildren") {
8
11
  console.error(
@@ -12,24 +15,25 @@ if (__DEV__) {
12
15
  }
13
16
 
14
17
  export class AnimatedExtractCoordinateFromArray extends AnimatedWithChildren {
15
- _array: AnimatedExtractCoordinateFromArray;
18
+ _array: AnimatedRouteCoordinatesArray;
16
19
 
17
20
  _index = 0;
18
21
 
19
- constructor(array: AnimatedExtractCoordinateFromArray, index: number) {
22
+ constructor(array: AnimatedRouteCoordinatesArray, index: number) {
20
23
  super();
21
24
  this._array = array;
22
25
  this._index = index;
23
26
  }
24
27
 
25
- __getValue(): AnimatedExtractCoordinateFromArray {
28
+ __getValue(): AnimatedCoordinates {
26
29
  const actArray = this._array.__getValue();
27
30
  let index = this._index;
28
31
 
29
32
  if (index < 0) {
30
33
  index += actArray.length;
31
34
  }
32
- return actArray[index];
35
+
36
+ return actArray[index]!;
33
37
  }
34
38
 
35
39
  __attach(): void {
@@ -1,9 +1,9 @@
1
1
  import distance from "@turf/distance";
2
2
  import {
3
- lineString,
4
- point,
5
3
  convertLength,
6
4
  type Coord,
5
+ lineString,
6
+ point,
7
7
  type Units,
8
8
  } from "@turf/helpers";
9
9
  import length from "@turf/length";
@@ -14,6 +14,25 @@ import {
14
14
  type AnimatedCoordinates,
15
15
  } from "./AbstractAnimatedCoordinates";
16
16
 
17
+ interface AnimatedRouteToValue {
18
+ end: /**
19
+ * Animate to this point on the coordinates array
20
+ */
21
+ | { point: Coord | AnimatedCoordinates }
22
+ /**
23
+ * Animate to this length of the coordinates array
24
+ */
25
+ | {
26
+ along: number;
27
+ units?: Units;
28
+ };
29
+
30
+ /**
31
+ * @deprecated Use `end.units` in conjunction with `end.along` instead
32
+ */
33
+ units?: Units;
34
+ }
35
+
17
36
  interface AnimatedRouteState {
18
37
  actRoute?: AnimatedCoordinates[];
19
38
  fullRoute: AnimatedCoordinates[];
@@ -21,66 +40,65 @@ interface AnimatedRouteState {
21
40
  from: number;
22
41
  current?: number;
23
42
  to: number;
24
- point?: Coord;
25
- along?: Coord;
26
- };
43
+ } & ({ point?: Coord | AnimatedCoordinates } | { along?: number });
27
44
  }
28
45
 
29
- export class AnimatedRouteCoordinatesArray extends AbstractAnimatedCoordinates<AnimatedRouteState> {
46
+ export class AnimatedRouteCoordinatesArray extends AbstractAnimatedCoordinates<
47
+ AnimatedRouteState,
48
+ AnimatedRouteToValue
49
+ > {
30
50
  /**
31
51
  * Calculate initial state
32
52
  *
33
- * @param {*} args - to value from animate
34
- * @returns {object} - the state object
53
+ * @param {AnimatedCoordinates[]} coordinatesArray
54
+ * @returns {AnimatedRouteState}
35
55
  */
36
56
  onInitialState(coordinatesArray: AnimatedCoordinates[]): AnimatedRouteState {
37
57
  return {
38
58
  fullRoute: coordinatesArray.map(
39
- (coord): AnimatedCoordinates => [coord[0], coord[1]],
59
+ (coordinates): AnimatedCoordinates => [coordinates[0], coordinates[1]],
40
60
  ),
41
61
  end: { from: 0, to: 0 },
42
62
  };
43
63
  }
44
64
 
45
65
  /**
46
- * Calculate value from state.
66
+ * Calculate value from state
47
67
  *
48
- * @param {object} state - either state from initialState and/or from calculate
49
- * @returns {object}
68
+ * @param {AnimatedRouteState} state Previous state
69
+ * @returns {AnimatedCoordinates[]}
50
70
  */
51
- onGetValue(
52
- state: AnimatedRouteState,
53
- ): AnimatedRouteState | AnimatedCoordinates[] {
71
+ onGetValue(state: AnimatedRouteState): AnimatedCoordinates[] {
54
72
  return state.actRoute || state.fullRoute;
55
73
  }
56
74
 
57
75
  /**
58
76
  * Calculates state based on startingState and progress, returns a new state
59
77
  *
60
- * @param {object} state - state object from initialState and/or from calculate
61
- * @param {number} progress - value between 0 and 1
62
- * @returns {object} next state
78
+ * @param {AnimatedRouteState} state Previous state
79
+ * @param {number} progress Value between 0 and 1
80
+ * @returns {AnimatedRouteState}
63
81
  */
64
82
  onCalculate(state: AnimatedRouteState, progress: number): AnimatedRouteState {
65
83
  const { fullRoute, end } = state;
66
84
  const currentEnd = end.from * (1.0 - progress) + progress * end.to;
67
85
 
68
- let prevsum = 0;
69
- let actsum = 0;
86
+ let prevSum = 0;
87
+ let actSum = 0;
70
88
  let i = fullRoute.length - 1;
71
- while (actsum < currentEnd && i > 0) {
72
- prevsum = actsum;
89
+ while (actSum < currentEnd && i > 0) {
90
+ prevSum = actSum;
73
91
  const start = fullRoute[i];
74
92
  const end = fullRoute[i - 1];
75
- actsum +=
93
+ actSum +=
76
94
  start && end ? distance(point(start), point(end), this.distconf) : 0;
77
95
  i -= 1;
78
96
  }
79
- if (actsum <= currentEnd) {
97
+ if (actSum <= currentEnd) {
80
98
  const actRoute = [...fullRoute.slice(0, i + 1)];
81
99
  return { fullRoute, end: { ...end, current: currentEnd }, actRoute };
82
100
  }
83
- const r = (currentEnd - prevsum) / (actsum - prevsum);
101
+ const r = (currentEnd - prevSum) / (actSum - prevSum);
84
102
  const or = 1.0 - r;
85
103
 
86
104
  const actRoute = [
@@ -96,53 +114,47 @@ export class AnimatedRouteCoordinatesArray extends AbstractAnimatedCoordinates<A
96
114
  /**
97
115
  * Subclasses can override to start a new animation
98
116
  *
117
+ * @param {AnimatedRouteState} state
99
118
  * @param {*} toValue - to value from animate
100
- * @param {*} actCoords - the current coordinates array to start from
101
119
  * @returns {object} The state
102
120
  */
103
121
  onStart(
104
122
  state: AnimatedRouteState,
105
- toValue: { end: { point?: Coord; along?: number }; units?: Units },
123
+ toValue: AnimatedRouteToValue,
106
124
  ): AnimatedRouteState {
107
125
  const { fullRoute, end } = state;
108
- let toDist = 0;
109
- if (!toValue.end) {
110
- console.error(
111
- "RouteCoordinatesArray: toValue should have end with either along or point",
112
- );
113
- }
114
- if (toValue.end.along) {
126
+ const fullRouteLineString = lineString(fullRoute);
127
+
128
+ let to: number | undefined = undefined;
129
+
130
+ if ("along" in toValue.end) {
115
131
  const { units } = toValue;
116
- const ls = lineString(fullRoute);
117
- toDist = convertLength(toValue.end.along, units);
118
- toDist = length(ls) - toDist;
119
- }
120
- if (toDist != null) {
121
- if (toValue.end.point) {
132
+
133
+ if (units !== undefined) {
122
134
  console.warn(
123
- "RouteCoordinatesArray: toValue.end: has both along and point, point is ignored",
135
+ "RouteCoordinatesArray: `toValue.units` is deprecated, use `toValue.end.units` instead.",
124
136
  );
125
137
  }
126
- } else if (toValue.end.point) {
127
- const ls = lineString(fullRoute);
128
138
 
129
- const nearest = nearestPointOnLine(ls, toValue.end.point);
130
- toDist = length(ls) - nearest.properties.location!;
139
+ to =
140
+ length(fullRouteLineString) -
141
+ convertLength(toValue.end.along, toValue.end.units ?? units);
131
142
  } else {
132
- console.warn(
133
- "RouteCoordinatesArray: toValue.end: should have either along or point",
143
+ const nearest = nearestPointOnLine(
144
+ fullRouteLineString,
145
+ toValue.end.point,
134
146
  );
147
+ to = length(fullRouteLineString) - nearest.properties.location!;
135
148
  }
136
149
 
137
- const result = {
150
+ return {
138
151
  fullRoute,
139
152
  end: {
140
153
  ...end,
141
- from: end.current != null ? end.current : end.from,
142
- to: toDist,
154
+ from: end.current ?? end.from,
155
+ to,
143
156
  },
144
157
  };
145
- return result;
146
158
  }
147
159
 
148
160
  get originalRoute(): AnimatedCoordinates[] {