@rnmapbox/maps 10.0.0-beta.42 → 10.0.0-beta.44

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 (54) hide show
  1. package/android/install.md +69 -2
  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/components/camera/CameraStop.kt +6 -6
  6. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.kt +1 -0
  7. package/android/rctmgl/src/main/java-v10/com/mapbox/rctmgl/modules/RCTMGLSnapshotModule.java +1 -1
  8. package/docs/HeadingIndicator.md +1 -1
  9. package/docs/ShapeSource.md +13 -9
  10. package/docs/SymbolLayer.md +4 -3
  11. package/docs/docs.json +41 -67
  12. package/index.d.ts +16 -128
  13. package/ios/RCTMGL-v10/RCTMGLCamera.swift +5 -21
  14. package/ios/install.md +3 -2
  15. package/javascript/components/AbstractLayer.tsx +72 -0
  16. package/javascript/components/AbstractSource.tsx +23 -0
  17. package/javascript/components/BackgroundLayer.js +1 -1
  18. package/javascript/components/CircleLayer.js +1 -1
  19. package/javascript/components/FillExtrusionLayer.js +1 -1
  20. package/javascript/components/FillLayer.js +1 -1
  21. package/javascript/components/{HeadingIndicator.js → HeadingIndicator.tsx} +6 -7
  22. package/javascript/components/HeatmapLayer.js +1 -1
  23. package/javascript/components/Images.js +1 -1
  24. package/javascript/components/LineLayer.js +1 -1
  25. package/javascript/components/MapView.js +5 -2
  26. package/javascript/components/MarkerView.tsx +1 -0
  27. package/javascript/components/NativeBridgeComponent.tsx +20 -14
  28. package/javascript/components/PointAnnotation.tsx +2 -1
  29. package/javascript/components/RasterLayer.js +1 -1
  30. package/javascript/components/RasterSource.js +1 -1
  31. package/javascript/components/ShapeSource.tsx +412 -0
  32. package/javascript/components/SkyLayer.js +1 -1
  33. package/javascript/components/Style.js +2 -2
  34. package/javascript/components/SymbolLayer.tsx +111 -0
  35. package/javascript/components/Terrain.tsx +0 -60
  36. package/javascript/components/UserLocation.js +1 -1
  37. package/javascript/components/VectorSource.js +6 -3
  38. package/javascript/components/annotations/Annotation.js +1 -1
  39. package/javascript/global.d.ts +4 -0
  40. package/javascript/index.js +2 -2
  41. package/javascript/utils/MapboxStyles.ts +157 -50
  42. package/javascript/utils/StyleValue.ts +8 -6
  43. package/javascript/utils/animated/Animated.js +2 -2
  44. package/javascript/utils/deprecation.ts +7 -4
  45. package/javascript/utils/{filterUtils.js → filterUtils.tsx} +1 -1
  46. package/javascript/utils/index.d.ts +16 -3
  47. package/package.json +1 -1
  48. package/scripts/autogenHelpers/DocJSONBuilder.js +2 -3
  49. package/scripts/autogenHelpers/globals.js +18 -7
  50. package/scripts/templates/MapboxStyles.ts.ejs +7 -2
  51. package/javascript/components/AbstractLayer.js +0 -46
  52. package/javascript/components/AbstractSource.js +0 -15
  53. package/javascript/components/ShapeSource.js +0 -373
  54. package/javascript/components/SymbolLayer.js +0 -120
package/index.d.ts CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  FeatureCollection,
23
23
  } from '@turf/helpers';
24
24
 
25
+ import type { SymbolLayerStyleProps } from './javascript/utils/MapboxStyles';
25
26
  import {
26
27
  Camera as _Camera,
27
28
  CameraStop as _CameraStop,
@@ -38,6 +39,14 @@ import {
38
39
  import { MarkerView as _MarkerView } from './javascript/components/MarkerView';
39
40
  import { PointAnnotation as _PointAnnotation } from './javascript/components/PointAnnotation';
40
41
  import { Atmosphere as _Atmosphere } from './javascript/components/Atmosphere';
42
+ import {
43
+ SymbolLayer as _SymbolLayer,
44
+ Props as _SymbolLayerProps,
45
+ } from './javascript/components/SymbolLayer';
46
+ import {
47
+ ShapeSource as _ShapeSource,
48
+ Props as _ShapeSourceProps,
49
+ } from './javascript/components/ShapeSource';
41
50
  import type {
42
51
  MapboxGLEvent as _MapboxGLEvent,
43
52
  AnimatedPoint as _AnimatedPoint,
@@ -96,7 +105,7 @@ type AutoAlignment = Alignment | 'auto';
96
105
 
97
106
  type NamedStyles<T> = {
98
107
  [P in keyof T]:
99
- | SymbolLayerStyle
108
+ | SymbolLayerStyleProps
100
109
  | RasterLayerStyle
101
110
  | LineLayerStyle
102
111
  | FillLayerStyle
@@ -142,6 +151,8 @@ declare namespace MapboxGL {
142
151
  const Atmosphere = _Atmosphere;
143
152
  const MarkerView = _MarkerView;
144
153
  const PointAnnotation = _PointAnnotation;
154
+ const SymbolLayer = _SymbolLayer;
155
+ const ShapeSource = _ShapeSource;
145
156
 
146
157
  type MapboxGLEvent = _MapboxGLEvent;
147
158
  type UserTrackingMode = _UserTrackingMode;
@@ -238,7 +249,7 @@ declare namespace MapboxGL {
238
249
 
239
250
  namespace Animated {
240
251
  // sources
241
- class ShapeSource extends Component<ShapeSourceProps> {}
252
+ class ShapeSource extends Component<_ShapeSourceProps> {}
242
253
  class ImageSource extends Component<ImageSourceProps> {}
243
254
 
244
255
  // layers
@@ -246,7 +257,7 @@ declare namespace MapboxGL {
246
257
  class FillExtrusionLayer extends Component<FillExtrusionLayerProps> {}
247
258
  class LineLayer extends Component<LineLayerProps> {}
248
259
  class CircleLayer extends Component<CircleLayerProps> {}
249
- class SymbolLayer extends Component<SymbolLayerProps> {}
260
+ class SymbolLayer extends Component<_SymbolLayerProps> {}
250
261
  class RasterLayer extends Component<RasterLayerProps> {}
251
262
  class BackgroundLayer extends Component<BackgroundLayerProps> {}
252
263
  }
@@ -358,33 +369,6 @@ declare namespace MapboxGL {
358
369
  * Sources
359
370
  */
360
371
  class VectorSource extends Component<VectorSourceProps> {}
361
- class ShapeSource extends Component<ShapeSourceProps> {
362
- features(
363
- filter?: Expression,
364
- ): Promise<FeatureCollection<Geometry, Properties>>;
365
-
366
- getClusterExpansionZoom(
367
- feature: Feature<Geometry, Properties> | number,
368
- ): Promise<number>;
369
- /**
370
- * Returns all the leaves of a cluster with pagination support.
371
- * @param cluster feature cluster
372
- * @param limit the number of leaves to return
373
- * @param offset the amount of points to skip (for pagination)
374
- */
375
- getClusterLeaves: (
376
- feature: Feature<Geometry, Properties> | number,
377
- limit: number,
378
- offset: number,
379
- ) => Promise<FeatureCollection<Geometry, Properties>>;
380
- /**
381
- * Returns the children of a cluster (on the next zoom level).
382
- * @param cluster feature cluster
383
- */
384
- getClusterChildren: (
385
- feature: Feature<Geometry, Properties> | number,
386
- ) => Promise<FeatureCollection<Geometry, Properties>>;
387
- }
388
372
  class RasterSource extends Component<RasterSourceProps> {}
389
373
  class RasterDemSource extends Component<RasterSourceProps> {}
390
374
 
@@ -397,7 +381,6 @@ declare namespace MapboxGL {
397
381
  class FillLayer extends Component<FillLayerProps> {}
398
382
  class LineLayer extends Component<LineLayerProps> {}
399
383
  class RasterLayer extends Component<RasterLayerProps> {}
400
- class SymbolLayer extends Component<SymbolLayerProps> {}
401
384
  class HeatmapLayer extends Component<HeatmapLayerProps> {}
402
385
  class Images extends Component<ImagesProps> {}
403
386
  class ImageSource extends Component<ImageSourceProps> {}
@@ -752,75 +735,8 @@ export type TextVariableAnchorValues =
752
735
  | 'bottom-left'
753
736
  | 'bottom-right';
754
737
 
755
- export interface SymbolLayerStyle {
756
- symbolPlacement?: 'point' | 'line' | Expression;
757
- symbolSpacing?: number | Expression;
758
- symbolAvoidEdges?: boolean | Expression;
759
- symbolSortKey?: number | Expression;
760
- symbolZOrder?: 'auto' | 'viewport-y' | 'source' | Expression;
761
- iconAllowOverlap?: boolean | Expression;
762
- iconIgnorePlacement?: boolean | Expression;
763
- iconOptional?: boolean | Expression;
764
- iconRotationAlignment?: AutoAlignment | Expression;
765
- iconSize?: number | Expression;
766
- iconTextFit?: 'none' | 'width' | 'height' | 'both' | Expression;
767
- iconTextFitPadding?: Array<number> | Expression;
768
- iconImage?: string | Expression;
769
- iconRotate?: number | Expression;
770
- iconPadding?: number | Expression;
771
- iconKeepUpright?: boolean | Expression;
772
- iconOffset?: Array<number> | Expression;
773
- iconAnchor?: Anchor | Expression;
774
- iconPitchAlignment?: AutoAlignment | Expression;
775
- textPitchAlignment?: AutoAlignment | Expression;
776
- textRotationAlignment?: AutoAlignment | Expression;
777
- textField?: string | Expression;
778
- textFont?: Array<string> | Expression;
779
- textSize?: number | Expression;
780
- textMaxWidth?: number | Expression;
781
- textLineHeight?: number | Expression;
782
- textLetterSpacing?: number | Expression;
783
- textJustify?: 'left' | 'center' | 'right' | Expression;
784
- textAnchor?: Anchor | Expression;
785
- textMaxAngle?: number | Expression;
786
- textRotate?: number | Expression;
787
- textPadding?: number | Expression;
788
- textKeepUpright?: boolean | Expression;
789
- textTransform?: 'none' | 'uppercase' | 'lowercase' | Expression;
790
- textOffset?: Array<number> | Expression;
791
- textAllowOverlap?: boolean | Expression;
792
- textIgnorePlacement?: boolean | Expression;
793
- textOptional?: boolean | Expression;
794
- textVariableAnchor?: Array<TextVariableAnchorValues>;
795
- textRadialOffset?: number | Expression;
796
- visibility?: Visibility | Expression;
797
- iconOpacity?: number | Expression;
798
- iconOpacityTransition?: Transition | Expression;
799
- iconColor?: string | Expression;
800
- iconColorTransition?: Transition | Expression;
801
- iconHaloColor?: string | Expression;
802
- iconHaloColorTransition?: Transition | Expression;
803
- iconHaloWidth?: number | Expression;
804
- iconHaloWidthTransition?: Transition | Expression;
805
- iconHaloBlur?: number | Expression;
806
- iconHaloBlurTransition?: Transition | Expression;
807
- iconTranslate?: Array<number> | Expression;
808
- iconTranslateTransition?: Transition | Expression;
809
- iconTranslateAnchor?: Alignment | Expression;
810
- textOpacity?: number | Expression;
811
- textOpacityTransition?: Transition | Expression;
812
- textColor?: string | Expression;
813
- textColorTransition?: Transition | Expression;
814
- textHaloColor?: string | Expression;
815
- textHaloColorTransition?: Transition | Expression;
816
- textHaloWidth?: number | Expression;
817
- textHaloWidthTransition?: Transition | Expression;
818
- textHaloBlur?: number | Expression;
819
- textHaloBlurTransition?: Transition | Expression;
820
- textTranslate?: Array<number> | Expression;
821
- textTranslateTransition?: Transition | Expression;
822
- textTranslateAnchor?: Alignment | Expression;
823
- }
738
+ /** @deprecated Will be removed in next betas */
739
+ export type SymbolLayerStyle = SymbolLayerStyleProps;
824
740
 
825
741
  export interface HeatmapLayerStyle {
826
742
  visibility?: Visibility | Expression;
@@ -872,30 +788,6 @@ export interface VectorSourceProps extends TileSourceProps {
872
788
  };
873
789
  }
874
790
 
875
- export interface ShapeSourceProps extends ViewProps {
876
- id: string;
877
- url?: string;
878
- shape?:
879
- | GeoJSON.GeometryCollection
880
- | GeoJSON.Feature
881
- | GeoJSON.FeatureCollection
882
- | GeoJSON.Geometry;
883
- cluster?: boolean;
884
- clusterRadius?: number;
885
- clusterMaxZoomLevel?: number;
886
- clusterProperties?: object;
887
- maxZoomLevel?: number;
888
- buffer?: number;
889
- tolerance?: number;
890
- lineMetrics?: boolean;
891
- images?: { assets?: string[] } & { [key: string]: ImageSourcePropType };
892
- onPress?: (event: OnPressEvent) => void;
893
- hitbox?: {
894
- width: number;
895
- height: number;
896
- };
897
- }
898
-
899
791
  export interface RasterSourceProps extends TileSourceProps {
900
792
  tileSize?: number;
901
793
  }
@@ -937,10 +829,6 @@ export interface RasterLayerProps extends LayerBaseProps {
937
829
  style?: StyleProp<RasterLayerStyle>;
938
830
  }
939
831
 
940
- export interface SymbolLayerProps extends LayerBaseProps {
941
- style?: StyleProp<SymbolLayerStyle>;
942
- }
943
-
944
832
  export interface HeatmapLayerProps extends LayerBaseProps {
945
833
  style?: StyleProp<HeatmapLayerStyle>;
946
834
  }
@@ -1,8 +1,8 @@
1
1
  import Foundation
2
- @_spi(Experimental) import MapboxMaps
2
+ import MapboxMaps
3
3
  import Turf
4
4
 
5
- protocol RCTMGLMapComponent : class {
5
+ protocol RCTMGLMapComponent : AnyObject {
6
6
  func addToMap(_ map: RCTMGLMapView, style: Style)
7
7
  func removeFromMap(_ map: RCTMGLMapView)
8
8
 
@@ -14,7 +14,7 @@ enum CameraMode: String, CaseIterable {
14
14
  }
15
15
 
16
16
  enum UserTrackingMode: String {
17
- case none,compass, course, normal
17
+ case none, compass, course, normal
18
18
  }
19
19
 
20
20
  struct CameraUpdateItem {
@@ -29,10 +29,7 @@ struct CameraUpdateItem {
29
29
  }
30
30
  switch mode {
31
31
  case .flight:
32
- var _camera = camera
33
- _camera.padding = nil
34
- map.camera.fly(to: _camera, duration: duration)
35
- changePadding(map: map, cameraAnimator: &cameraAnimator, curve: .linear)
32
+ map.camera.fly(to: camera, duration: duration)
36
33
  case .ease:
37
34
  map.camera.ease(to: camera, duration: duration ?? 0, curve: .easeInOut, completion: nil)
38
35
  case .linear:
@@ -42,18 +39,6 @@ struct CameraUpdateItem {
42
39
  }
43
40
  }
44
41
  }
45
-
46
- /// Padding is not currently animatable on the camera's `fly(to:)` method, so we create a separate animator instead.
47
- /// If this changes, remove this and call `fly(to:)` with an unmodified `camera`.
48
- func changePadding(map: RCTMGLMapView, cameraAnimator: inout BasicCameraAnimator?, curve: UIView.AnimationCurve) {
49
- if let cameraAnimator = cameraAnimator {
50
- cameraAnimator.stopAnimation()
51
- }
52
- cameraAnimator = map.camera.makeAnimator(duration: duration ?? 0, curve: curve) { (transition) in
53
- transition.padding.toValue = camera.padding
54
- }
55
- cameraAnimator?.startAnimation()
56
- }
57
42
  }
58
43
 
59
44
  class CameraUpdateQueue {
@@ -203,7 +188,7 @@ class RCTMGLCamera : RCTMGLMapComponentBase, LocationConsumer {
203
188
 
204
189
  func _updateCameraFromTrackingMode() {
205
190
  withMapView { map in
206
- let userTrackingMode = UserTrackingMode(rawValue: self.followUserMode ?? "none")
191
+ let userTrackingMode = UserTrackingMode(rawValue: self.followUserMode ?? UserTrackingMode.normal.rawValue)
207
192
  guard let userTrackingMode = userTrackingMode else {
208
193
  Logger.error("RCTMGLCamera: Unexpected followUserMode \(optional: self.followUserMode)")
209
194
  self._disableUsetTracking(map)
@@ -454,7 +439,6 @@ class RCTMGLCamera : RCTMGLMapComponentBase, LocationConsumer {
454
439
  }
455
440
  }
456
441
 
457
- /// Converts milliseconds to seconds.
458
442
  private func toSeconds(_ ms: Double) -> TimeInterval {
459
443
  return ms * 0.001
460
444
  }
package/ios/install.md CHANGED
@@ -56,10 +56,11 @@ Add the following to the beginning of your podfile
56
56
  $RNMapboxMapsImpl = 'mapbox'
57
57
  ```
58
58
 
59
- You can also specify the version to use. *Warning:* if you set a version, then later update, the `rnamapbox/maps` library it's possible that you'll end up using Mapbox older version than supported. Make sure you revise this value with `rnmapbox/maps` updates.
59
+ You can also override the version to use. *Warning:* if you set a version, then later update, the `rnamapbox/maps` library it's possible that you'll end up using Mapbox older version than supported. Make sure you revise this value with `rnmapbox/maps` updates.
60
60
 
61
61
  ```ruby
62
- $RNMapboxMapsVersion = '~> 10.9.0'
62
+ # Warning: only for advanced use cases, only do this if you know what you're doing.
63
+ # $RNMapboxMapsVersion = '~> 10.9.0'
63
64
  ```
64
65
 
65
66
  You will need to authorize your download of the Maps SDK with a secret access token with the `DOWNLOADS:READ` scope. This [guide](https://docs.mapbox.com/ios/maps/guides/install/#configure-credentials) explains how to configure the secret token under section `Configure your secret token`.
@@ -0,0 +1,72 @@
1
+ /* eslint react/prop-types:0 */
2
+ import React from 'react';
3
+ import { NativeMethods, processColor } from 'react-native';
4
+
5
+ import { getFilter } from '../utils/filterUtils';
6
+ import { transformStyle } from '../utils/StyleValue';
7
+ import { AllLayerStyleProps } from '../utils/MapboxStyles';
8
+
9
+ type PropsBase = {
10
+ id: string;
11
+ sourceID?: string;
12
+ minZoomLevel?: number;
13
+ maxZoomLevel?: number;
14
+ aboveLayerID?: string;
15
+ belowLayerID?: string;
16
+ layerIndex?: number;
17
+ filter?: string[];
18
+ style: AllLayerStyleProps;
19
+ };
20
+
21
+ class AbstractLayer<
22
+ PropsType extends PropsBase,
23
+ NativePropsType,
24
+ > extends React.PureComponent<PropsType> {
25
+ get baseProps(): PropsType {
26
+ return {
27
+ ...this.props,
28
+ id: this.props.id,
29
+ sourceID: this.props.sourceID,
30
+ reactStyle: this.getStyle(this.props.style),
31
+ minZoomLevel: this.props.minZoomLevel,
32
+ maxZoomLevel: this.props.maxZoomLevel,
33
+ aboveLayerID: this.props.aboveLayerID,
34
+ belowLayerID: this.props.belowLayerID,
35
+ layerIndex: this.props.layerIndex,
36
+ filter: getFilter(this.props.filter),
37
+ style: undefined,
38
+ };
39
+ }
40
+
41
+ nativeLayer:
42
+ | (React.Component<NativePropsType> & Readonly<NativeMethods>)
43
+ | undefined = undefined;
44
+
45
+ setNativeLayer = (
46
+ instance: React.Component<NativePropsType> & Readonly<NativeMethods>,
47
+ ) => {
48
+ this.nativeLayer = instance;
49
+ };
50
+
51
+ getStyleTypeFormatter(styleType: string) {
52
+ if (styleType === 'color') {
53
+ return processColor;
54
+ }
55
+ }
56
+
57
+ getStyle(style: AllLayerStyleProps) {
58
+ return transformStyle(style);
59
+ }
60
+
61
+ setNativeProps(props: { [key: string]: unknown }) {
62
+ if (this.nativeLayer) {
63
+ let propsToPass = props;
64
+ if (props.style) {
65
+ propsToPass = { ...props, reactStyle: this.getStyle(props.style) };
66
+ }
67
+ this.nativeLayer?.setNativeProps(propsToPass);
68
+ }
69
+ }
70
+ }
71
+
72
+ export default AbstractLayer;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { NativeMethods } from 'react-native';
3
+
4
+ class AbstractSource<
5
+ PropsType,
6
+ NativePropsType extends object,
7
+ > extends React.PureComponent<PropsType> {
8
+ _nativeRef?: React.Component<NativePropsType> & Readonly<NativeMethods>;
9
+
10
+ setNativeProps(props: NativePropsType) {
11
+ if (this._nativeRef) {
12
+ this._nativeRef.setNativeProps(props);
13
+ }
14
+ }
15
+
16
+ setNativeRef: (
17
+ instance: React.Component<NativePropsType> & Readonly<NativeMethods>,
18
+ ) => void = (instance) => {
19
+ this._nativeRef = instance;
20
+ };
21
+ }
22
+
23
+ export default AbstractSource;
@@ -79,7 +79,7 @@ class BackgroundLayer extends AbstractLayer {
79
79
  return (
80
80
  <RCTMGLBackgroundLayer
81
81
  testID="rctmglBackgroundLayer"
82
- ref="nativeLayer"
82
+ ref={this.setNativeLayer}
83
83
  {...this.baseProps}
84
84
  />
85
85
  );
@@ -83,7 +83,7 @@ class CircleLayer extends AbstractLayer {
83
83
  return (
84
84
  <RCTMGLCircleLayer
85
85
  testID="rctmglCircleLayer"
86
- ref="nativeLayer"
86
+ ref={this.setNativeLayer}
87
87
  {...this.baseProps}
88
88
  />
89
89
  );
@@ -83,7 +83,7 @@ class FillExtrusionLayer extends AbstractLayer {
83
83
  ...this.baseProps,
84
84
  sourceLayerID: this.props.sourceLayerID,
85
85
  };
86
- return <RCTMGLFillExtrusionLayer ref="nativeLayer" {...props} />;
86
+ return <RCTMGLFillExtrusionLayer ref={this.setNativeLayer} {...props} />;
87
87
  }
88
88
  }
89
89
 
@@ -83,7 +83,7 @@ class FillLayer extends AbstractLayer {
83
83
  ...this.baseProps,
84
84
  sourceLayerID: this.props.sourceLayerID,
85
85
  };
86
- return <RCTMGLFillLayer ref="nativeLayer" {...props} />;
86
+ return <RCTMGLFillLayer ref={this.setNativeLayer} {...props} />;
87
87
  }
88
88
  }
89
89
 
@@ -1,18 +1,21 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
2
 
4
3
  import headingIcon from '../../assets/heading.png';
5
4
 
6
- import SymbolLayer from './SymbolLayer';
5
+ import { SymbolLayer } from './SymbolLayer';
7
6
 
8
7
  const style = {
9
8
  iconImage: headingIcon,
10
9
  iconAllowOverlap: true,
11
10
  iconPitchAlignment: 'map',
12
11
  iconRotationAlignment: 'map',
12
+ } as const;
13
+
14
+ type Props = {
15
+ heading?: number;
13
16
  };
14
17
 
15
- const HeadingIndicator = (heading) => (
18
+ const HeadingIndicator = ({ heading }: Props) => (
16
19
  <SymbolLayer
17
20
  key="mapboxUserLocationHeadingIndicator"
18
21
  id="mapboxUserLocationHeadingIndicator"
@@ -24,8 +27,4 @@ const HeadingIndicator = (heading) => (
24
27
  />
25
28
  );
26
29
 
27
- HeadingIndicator.propTypes = {
28
- heading: PropTypes.number,
29
- };
30
-
31
30
  export default HeadingIndicator;
@@ -84,7 +84,7 @@ class HeatmapLayer extends AbstractLayer {
84
84
  ...this.baseProps,
85
85
  sourceLayerID: this.props.sourceLayerID,
86
86
  };
87
- return <RCTMGLHeatmapLayer ref="nativeLayer" {...props} />;
87
+ return <RCTMGLHeatmapLayer ref={this.setNativeLayer} {...props} />;
88
88
  }
89
89
  }
90
90
 
@@ -4,7 +4,7 @@ import { requireNativeComponent, Image } from 'react-native';
4
4
 
5
5
  import { viewPropTypes } from '../utils';
6
6
 
7
- import ShapeSource from './ShapeSource';
7
+ import { ShapeSource } from './ShapeSource';
8
8
 
9
9
  export const NATIVE_MODULE_NAME = 'RCTMGLImages';
10
10
 
@@ -83,7 +83,7 @@ class LineLayer extends AbstractLayer {
83
83
  ...this.baseProps,
84
84
  sourceLayerID: this.props.sourceLayerID,
85
85
  };
86
- return <RCTMGLLineLayer ref="nativeLayer" {...props} />;
86
+ return <RCTMGLLineLayer ref={this.setNativeLayer} {...props} />;
87
87
  }
88
88
  }
89
89
 
@@ -42,7 +42,10 @@ const defaultStyleURL = MapboxGL.StyleURL.Street;
42
42
  /**
43
43
  * MapView backed by Mapbox Native GL
44
44
  */
45
- class MapView extends NativeBridgeComponent(React.Component) {
45
+ class MapView extends NativeBridgeComponent(
46
+ React.Component,
47
+ NATIVE_MODULE_NAME,
48
+ ) {
46
49
  static propTypes = {
47
50
  ...viewPropTypes,
48
51
 
@@ -306,7 +309,7 @@ class MapView extends NativeBridgeComponent(React.Component) {
306
309
  };
307
310
 
308
311
  constructor(props) {
309
- super(props, NATIVE_MODULE_NAME);
312
+ super(props);
310
313
 
311
314
  this.logger = Logger.sharedInstance();
312
315
  this.logger.start();
@@ -97,6 +97,7 @@ class MarkerView extends React.PureComponent<{
97
97
  <RCTMGLMarkerViewWrapper
98
98
  style={{
99
99
  alignSelf: 'flex-start',
100
+ position: 'absolute',
100
101
  }}
101
102
  >
102
103
  {child}
@@ -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
  }
@@ -120,6 +120,7 @@ type PointAnnotationProps = {
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);
@@ -80,7 +80,7 @@ class RasterLayer extends AbstractLayer {
80
80
  ...this.baseProps,
81
81
  sourceLayerID: this.props.sourceLayerID,
82
82
  };
83
- return <RCTMGLRasterLayer ref="nativeLayer" {...props} />;
83
+ return <RCTMGLRasterLayer ref={this.setNativeLayer} {...props} />;
84
84
  }
85
85
  }
86
86
 
@@ -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
  })}