@rnmapbox/maps 10.0.0-beta.43 → 10.0.0-beta.45

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 (58) hide show
  1. package/android/install.md +49 -1
  2. package/android/rctmgl/src/main/java-mapboxgl/common/com/mapbox/rctmgl/components/camera/CameraStop.java +4 -4
  3. package/android/rctmgl/src/main/java-mapboxgl/common/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java +3 -3
  4. package/android/rctmgl/src/main/java-mapboxgl/common/com/mapbox/rctmgl/modules/RCTMGLSnapshotModule.java +1 -1
  5. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/RCTMGLPackage.java +0 -2
  6. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerView.kt +162 -51
  7. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerViewManager.kt +10 -0
  8. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLPointAnnotation.kt +6 -6
  9. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/camera/CameraStop.kt +11 -7
  10. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/images/RCTMGLImages.kt +22 -2
  11. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +17 -19
  12. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/styles/RCTMGLStyle.kt +1 -1
  13. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLSnapshotModule.java +1 -1
  14. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/utils/DownloadMapImageTask.kt +2 -1
  15. package/docs/MapboxGL.md +1 -1
  16. package/docs/MarkerView.md +17 -10
  17. package/docs/PointAnnotation.md +1 -1
  18. package/docs/ShapeSource.md +13 -9
  19. package/docs/SymbolLayer.md +1 -1
  20. package/docs/docs.json +145 -161
  21. package/index.d.ts +7 -56
  22. package/ios/RCTMGL-v10/RCTLog.swift +5 -5
  23. package/ios/RCTMGL-v10/RCTMGLCamera.swift +2 -2
  24. package/ios/RCTMGL-v10/RCTMGLMapViewManager.swift +2 -2
  25. package/ios/RCTMGL-v10/RCTMGLMarkerView.swift +186 -105
  26. package/ios/RCTMGL-v10/RCTMGLMarkerViewManager.m +2 -1
  27. package/ios/RCTMGL-v10/RCTMGLShapeSourceManager.swift +1 -1
  28. package/ios/RCTMGL-v10/RCTMGLUtils.swift +1 -1
  29. package/ios/RCTMGL-v10/RCTMGLVectorLayer.swift +1 -1
  30. package/ios/install.md +3 -2
  31. package/javascript/components/AbstractLayer.tsx +9 -6
  32. package/javascript/components/AbstractSource.tsx +23 -0
  33. package/javascript/components/HeadingIndicator.tsx +1 -1
  34. package/javascript/components/Images.js +1 -1
  35. package/javascript/components/MapView.js +5 -2
  36. package/javascript/components/MarkerView.tsx +81 -76
  37. package/javascript/components/NativeBridgeComponent.tsx +20 -14
  38. package/javascript/components/PointAnnotation.tsx +3 -2
  39. package/javascript/components/RasterSource.js +1 -1
  40. package/javascript/components/ShapeSource.tsx +412 -0
  41. package/javascript/components/Style.js +2 -2
  42. package/javascript/components/SymbolLayer.tsx +3 -5
  43. package/javascript/components/VectorSource.js +6 -3
  44. package/javascript/components/annotations/Annotation.js +1 -1
  45. package/javascript/index.js +2 -2
  46. package/javascript/utils/animated/Animated.js +2 -2
  47. package/javascript/utils/deprecation.ts +7 -4
  48. package/javascript/utils/filterUtils.tsx +1 -1
  49. package/javascript/utils/index.d.ts +19 -6
  50. package/package.json +1 -1
  51. package/scripts/autogenHelpers/DocJSONBuilder.js +17 -1
  52. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerViewWrapper.kt +0 -8
  53. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/annotation/RCTMGLMarkerViewWrapperManager.kt +0 -21
  54. package/ios/RCTMGL-v10/RCTMGLMarkerViewWrapper.swift +0 -24
  55. package/ios/RCTMGL-v10/RCTMGLMarkerViewWrapperManager.m +0 -8
  56. package/ios/RCTMGL-v10/RCTMGLMarkerViewWrapperManager.swift +0 -14
  57. package/javascript/components/AbstractSource.js +0 -15
  58. package/javascript/components/ShapeSource.js +0 -373
@@ -1,10 +1,11 @@
1
- import React, { ReactNode, ReactElement } from 'react';
1
+ import React from 'react';
2
2
  import {
3
3
  Platform,
4
4
  NativeModules,
5
5
  requireNativeComponent,
6
6
  HostComponent,
7
7
  type ViewProps,
8
+ View,
8
9
  } from 'react-native';
9
10
 
10
11
  import { toJSONString } from '../utils';
@@ -16,46 +17,55 @@ const Mapbox = NativeModules.MGLModule;
16
17
 
17
18
  export const NATIVE_MODULE_NAME = 'RCTMGLMarkerView';
18
19
 
19
- /**
20
- * MarkerView allows you to place a interactive react native marker to the map.
21
- *
22
- * If you have static view consider using PointAnnotation or SymbolLayer they'll offer much better performance
23
- * .
24
- * This is based on [MakerView plugin](https://docs.mapbox.com/android/plugins/overview/markerview/) on Android
25
- * and PointAnnotation on iOS.
26
- */
27
- class MarkerView extends React.PureComponent<{
20
+ type Props = ViewProps & {
28
21
  /**
29
22
  * The center point (specified as a map coordinate) of the marker.
30
- * See also #anchor.
31
23
  */
32
24
  coordinate: [number, number];
33
25
 
34
26
  /**
35
- * Specifies the anchor being set on a particular point of the annotation.
36
- * The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0],
37
- * where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner.
38
- * Note this is only for custom annotations not the default pin view.
39
- * Defaults to the center of the view.
27
+ * Any coordinate between (0, 0) and (1, 1), where (0, 0) is the top-left corner of
28
+ * the view, and (1, 1) is the bottom-right corner. Defaults to the center at (0.5, 0.5).
40
29
  */
41
30
  anchor: {
42
- /**
43
- * `x` of anchor
44
- */
45
31
  x: number;
46
- /**
47
- * `y` of anchor
48
- */
49
32
  y: number;
50
33
  };
51
34
 
52
35
  /**
53
- * Expects one child - can be container with multiple elements
36
+ * @v10
37
+ *
38
+ * Whether or not nearby markers on the map should all be displayed. If false, adjacent
39
+ * markers will 'collapse' and only one will be shown. Defaults to false.
40
+ */
41
+ allowOverlap: boolean;
42
+
43
+ isSelected: boolean;
44
+
45
+ /**
46
+ * One or more valid React Native views.
54
47
  */
55
48
  children: React.ReactElement;
56
- }> {
57
- static defaultProps = {
49
+ };
50
+
51
+ /**
52
+ * MarkerView represents an interactive React Native marker on the map.
53
+ *
54
+ * If you have static views, consider using PointAnnotation or SymbolLayer to display
55
+ * an image, as they'll offer much better performance. Mapbox suggests using this
56
+ * component for a maximum of around 100 views displayed at one time.
57
+ *
58
+ * This is implemented with view annotations on [Android](https://docs.mapbox.com/android/maps/guides/annotations/view-annotations/)
59
+ * and [iOS](https://docs.mapbox.com/ios/maps/guides/annotations/view-annotations).
60
+ *
61
+ * This component has no dedicated `onPress` method. Instead, you should handle gestures
62
+ * with the React views passed in as `children`.
63
+ */
64
+ class MarkerView extends React.PureComponent<Props> {
65
+ static defaultProps: Partial<Props> = {
58
66
  anchor: { x: 0.5, y: 0.5 },
67
+ allowOverlap: false,
68
+ isSelected: false,
59
69
  };
60
70
 
61
71
  static lastId = 0;
@@ -69,68 +79,63 @@ class MarkerView extends React.PureComponent<{
69
79
  return this.__idForPointAnnotation;
70
80
  }
71
81
 
72
- render() {
73
- const { props } = this;
74
- if (Platform.OS === 'ios' && !Mapbox.MapboxV10) {
75
- return <PointAnnotation id={this._idForPointAnnotation()} {...props} />;
82
+ _getCoordinate(coordinate: [number, number]): string | undefined {
83
+ if (!coordinate) {
84
+ return undefined;
76
85
  }
86
+ return toJSONString(makePoint(coordinate));
87
+ }
77
88
 
78
- function _getCoordinate(coordinate: [number, number]): string | undefined {
79
- if (!coordinate) {
80
- return undefined;
81
- }
82
- return toJSONString(makePoint(coordinate));
89
+ render() {
90
+ if (
91
+ this.props.anchor.x < 0 ||
92
+ this.props.anchor.y < 0 ||
93
+ this.props.anchor.x > 1 ||
94
+ this.props.anchor.y > 1
95
+ ) {
96
+ console.warn(
97
+ `[MarkerView] Anchor with value (${this.props.anchor.x}, ${this.props.anchor.y}) should not be outside the range [(0, 0), (1, 1)]`,
98
+ );
83
99
  }
84
100
 
85
- const { anchor = { x: 0.5, y: 0.5 } } = props;
86
- const { children } = props;
87
-
88
- const actProps = {
89
- anchor,
90
- coordinate: _getCoordinate(props.coordinate),
91
- };
92
-
93
- const wrapChildern =
94
- RCTMGLMarkerViewWrapper === undefined
95
- ? (child: ReactNode | ReactNode[]) => child
96
- : (child: ReactNode | ReactNode[]) => (
97
- <RCTMGLMarkerViewWrapper
98
- style={{
99
- alignSelf: 'flex-start',
100
- }}
101
- >
102
- {child}
103
- </RCTMGLMarkerViewWrapper>
104
- );
105
-
106
- if (RCTMGLMarkerView === undefined) {
107
- throw new Error(
108
- 'internal error RCTMGLMarkerView should not be null on v10 or non ios',
101
+ if (Platform.OS === 'ios' && !Mapbox.MapboxV10) {
102
+ return (
103
+ <PointAnnotation id={this._idForPointAnnotation()} {...this.props} />
109
104
  );
110
105
  }
106
+
107
+ const { anchor = { x: 0.5, y: 0.5 } } = this.props;
108
+
111
109
  return (
112
- <RCTMGLMarkerView {...actProps}>
113
- {wrapChildern(children)}
110
+ <RCTMGLMarkerView
111
+ style={[
112
+ {
113
+ flex: 0,
114
+ alignSelf: 'flex-start',
115
+ },
116
+ this.props.style,
117
+ ]}
118
+ coordinate={this._getCoordinate(this.props.coordinate)}
119
+ anchor={anchor}
120
+ allowOverlap={this.props.allowOverlap}
121
+ isSelected={this.props.isSelected}
122
+ >
123
+ <View style={{ flex: 0, alignSelf: 'flex-start' }}>
124
+ {this.props.children}
125
+ </View>
114
126
  </RCTMGLMarkerView>
115
127
  );
116
128
  }
117
129
  }
118
130
 
119
- const RCTMGLMarkerView:
120
- | HostComponent<{
121
- anchor: { x: number; y: number };
122
- coordinate: string | undefined;
123
- }>
124
- | undefined =
125
- Platform.OS === 'android'
126
- ? requireNativeComponent(NATIVE_MODULE_NAME)
127
- : Mapbox.MapboxV10
128
- ? requireNativeComponent(NATIVE_MODULE_NAME)
129
- : undefined;
130
-
131
- const RCTMGLMarkerViewWrapper: HostComponent<ViewProps> | undefined =
132
- Mapbox.MapboxV10
133
- ? requireNativeComponent('RCTMGLMarkerViewWrapper')
134
- : undefined;
131
+ type NativeProps = ViewProps & {
132
+ coordinate: string | undefined;
133
+ anchor: { x: number; y: number };
134
+ allowOverlap: boolean;
135
+ isSelected: boolean;
136
+ };
137
+
138
+ const RCTMGLMarkerView: HostComponent<NativeProps> =
139
+ requireNativeComponent(NATIVE_MODULE_NAME);
135
140
 
136
141
  export default MarkerView;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { runNativeCommand, isAndroid } from '../utils';
3
+ import { type NativeArg, runNativeCommand, isAndroid } from '../utils';
4
4
 
5
5
  let callbackIncrement = 0;
6
6
 
@@ -9,18 +9,24 @@ export type RNMBEvent<PayloadType = { [key: string]: string }> = {
9
9
  type: string;
10
10
  };
11
11
 
12
- const NativeBridgeComponent = <T,>(B: React.ComponentClass<T>) =>
13
- class extends B {
12
+ const NativeBridgeComponent = <
13
+ Props extends object,
14
+ BaseComponent extends new (...ags: any[]) => React.Component<Props>,
15
+ >(
16
+ Base: BaseComponent,
17
+ nativeModuleName: string,
18
+ ) =>
19
+ class extends Base {
14
20
  _nativeModuleName: string;
15
21
  _onAndroidCallback: (e: any) => void;
16
22
  _callbackMap: Map<string, any>;
17
23
  _preRefMapMethodQueue: Array<{
18
- method: { name: string; args: Array<string> };
19
- resolver: (value: unknown) => void;
24
+ method: { name: string; args: NativeArg[] };
25
+ resolver: (value: NativeArg) => void;
20
26
  }>;
21
27
 
22
- constructor(props: T, nativeModuleName: string) {
23
- super(props);
28
+ constructor(...args: any[]) {
29
+ super(...args);
24
30
 
25
31
  this._nativeModuleName = nativeModuleName;
26
32
  this._onAndroidCallback = this._onAndroidCallbackO.bind(this);
@@ -28,9 +34,9 @@ const NativeBridgeComponent = <T,>(B: React.ComponentClass<T>) =>
28
34
  this._preRefMapMethodQueue = [];
29
35
  }
30
36
 
31
- _addAddAndroidCallback(
37
+ _addAddAndroidCallback<ReturnType>(
32
38
  id: string,
33
- resolve: (value: string) => void,
39
+ resolve: (value: ReturnType) => void,
34
40
  reject: (error: Error) => void,
35
41
  ) {
36
42
  this._callbackMap.set(id, { resolve, reject });
@@ -74,16 +80,16 @@ const NativeBridgeComponent = <T,>(B: React.ComponentClass<T>) =>
74
80
  }
75
81
  }
76
82
 
77
- _runNativeCommand<RefType>(
83
+ _runNativeCommand<RefType, ReturnType = NativeArg>(
78
84
  methodName: string,
79
85
  nativeRef: RefType,
80
- args: string[] = [],
81
- ) {
86
+ args: NativeArg[] = [],
87
+ ): Promise<ReturnType> {
82
88
  if (!nativeRef) {
83
- return new Promise((resolve) => {
89
+ return new Promise<ReturnType>((resolve) => {
84
90
  this._preRefMapMethodQueue.push({
85
91
  method: { name: methodName, args },
86
- resolver: resolve,
92
+ resolver: resolve as (args: NativeArg) => void,
87
93
  });
88
94
  });
89
95
  }
@@ -116,10 +116,11 @@ type PointAnnotationProps = {
116
116
  * they'll offer much better performance.
117
117
  *
118
118
  * If you need interactive views please use MarkerView,
119
- * as with PointAnnotation on Android child views are rendered onto a bitmap for better performance.
119
+ * as with PointAnnotation child views are rendered onto a bitmap
120
120
  */
121
121
  class PointAnnotation extends NativeBridgeComponent(
122
122
  React.PureComponent<PointAnnotationProps>,
123
+ NATIVE_MODULE_NAME,
123
124
  ) {
124
125
  static defaultProps = {
125
126
  anchor: { x: 0.5, y: 0.5 },
@@ -129,7 +130,7 @@ class PointAnnotation extends NativeBridgeComponent(
129
130
  _nativeRef: NativePointAnnotationRef | null = null;
130
131
 
131
132
  constructor(props: PointAnnotationProps) {
132
- super(props, NATIVE_MODULE_NAME);
133
+ super(props);
133
134
  this._onSelected = this._onSelected.bind(this);
134
135
  this._onDeselected = this._onDeselected.bind(this);
135
136
  this._onDragStart = this._onDragStart.bind(this);
@@ -107,7 +107,7 @@ class RasterSource extends AbstractSource {
107
107
  attribution: this.props.attribution,
108
108
  };
109
109
  return (
110
- <RCTMGLRasterSource ref="nativeSource" {...props}>
110
+ <RCTMGLRasterSource ref={this.setNativeRef} {...props}>
111
111
  {cloneReactChildrenWithProps(this.props.children, {
112
112
  sourceID: this.props.id,
113
113
  })}