react-native-maps 1.2.0-beta.2 → 1.3.0-beta.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.
@@ -2,6 +2,7 @@ package com.airbnb.android.react.maps;
2
2
 
3
3
  import android.view.View;
4
4
 
5
+ import androidx.annotation.NonNull;
5
6
  import androidx.annotation.Nullable;
6
7
 
7
8
  import com.facebook.react.bridge.Arguments;
@@ -22,21 +23,11 @@ import com.google.android.gms.maps.GoogleMapOptions;
22
23
  import com.google.android.gms.maps.model.LatLng;
23
24
  import com.google.android.gms.maps.model.LatLngBounds;
24
25
 
25
- import java.util.HashMap;
26
26
  import java.util.Map;
27
27
 
28
28
  public class AirMapManager extends ViewGroupManager<AirMapView> {
29
29
 
30
30
  private static final String REACT_CLASS = "AIRMap";
31
- private static final int ANIMATE_TO_REGION = 1;
32
- private static final int FIT_TO_ELEMENTS = 2;
33
- private static final int FIT_TO_SUPPLIED_MARKERS = 3;
34
- private static final int FIT_TO_COORDINATES = 4;
35
- private static final int SET_MAP_BOUNDARIES = 5;
36
- private static final int SET_INDOOR_ACTIVE_LEVEL_INDEX = 6;
37
- private static final int SET_CAMERA = 7;
38
- private static final int ANIMATE_CAMERA = 8;
39
-
40
31
 
41
32
  private final Map<String, Integer> MAP_TYPES = MapBuilder.of(
42
33
  "standard", GoogleMap.MAP_TYPE_NORMAL,
@@ -286,30 +277,37 @@ public class AirMapManager extends ViewGroupManager<AirMapView> {
286
277
  }
287
278
 
288
279
  @Override
289
- public void receiveCommand(AirMapView view, int commandId, @Nullable ReadableArray args) {
290
- Integer duration;
291
- Double lat;
292
- Double lng;
293
- Double lngDelta;
294
- Double latDelta;
295
- float bearing;
296
- float angle;
280
+ public void receiveCommand(@NonNull AirMapView view, String commandId, @Nullable ReadableArray args) {
281
+ int duration;
282
+ double lat;
283
+ double lng;
284
+ double lngDelta;
285
+ double latDelta;
297
286
  ReadableMap region;
298
287
  ReadableMap camera;
299
288
 
300
289
  switch (commandId) {
301
- case SET_CAMERA:
290
+ case "setCamera":
291
+ if(args == null) {
292
+ break;
293
+ }
302
294
  camera = args.getMap(0);
303
295
  view.animateToCamera(camera, 0);
304
296
  break;
305
297
 
306
- case ANIMATE_CAMERA:
298
+ case "animateCamera":
299
+ if(args == null) {
300
+ break;
301
+ }
307
302
  camera = args.getMap(0);
308
303
  duration = args.getInt(1);
309
304
  view.animateToCamera(camera, duration);
310
305
  break;
311
306
 
312
- case ANIMATE_TO_REGION:
307
+ case "animateToRegion":
308
+ if(args == null) {
309
+ break;
310
+ }
313
311
  region = args.getMap(0);
314
312
  duration = args.getInt(1);
315
313
  lng = region.getDouble("longitude");
@@ -323,23 +321,38 @@ public class AirMapManager extends ViewGroupManager<AirMapView> {
323
321
  view.animateToRegion(bounds, duration);
324
322
  break;
325
323
 
326
- case FIT_TO_ELEMENTS:
324
+ case "fitToElements":
325
+ if(args == null) {
326
+ break;
327
+ }
327
328
  view.fitToElements(args.getMap(0), args.getBoolean(1));
328
329
  break;
329
330
 
330
- case FIT_TO_SUPPLIED_MARKERS:
331
+ case "fitToSuppliedMarkers":
332
+ if(args == null) {
333
+ break;
334
+ }
331
335
  view.fitToSuppliedMarkers(args.getArray(0), args.getMap(1), args.getBoolean(2));
332
336
  break;
333
337
 
334
- case FIT_TO_COORDINATES:
338
+ case "fitToCoordinates":
339
+ if(args == null) {
340
+ break;
341
+ }
335
342
  view.fitToCoordinates(args.getArray(0), args.getMap(1), args.getBoolean(2));
336
343
  break;
337
344
 
338
- case SET_MAP_BOUNDARIES:
345
+ case "setMapBoundaries":
346
+ if(args == null) {
347
+ break;
348
+ }
339
349
  view.setMapBoundaries(args.getMap(0), args.getMap(1));
340
350
  break;
341
351
 
342
- case SET_INDOOR_ACTIVE_LEVEL_INDEX:
352
+ case "setIndoorActiveLevelIndex":
353
+ if(args == null) {
354
+ break;
355
+ }
343
356
  view.setIndoorActiveLevelIndex(args.getInt(0));
344
357
  break;
345
358
  }
@@ -377,38 +390,6 @@ public class AirMapManager extends ViewGroupManager<AirMapView> {
377
390
 
378
391
  return map;
379
392
  }
380
-
381
- @Nullable
382
- @Override
383
- public Map<String, Integer> getCommandsMap() {
384
- Map<String, Integer> map = this.CreateMap(
385
- "setCamera", SET_CAMERA,
386
- "animateCamera", ANIMATE_CAMERA,
387
- "animateToRegion", ANIMATE_TO_REGION,
388
- "fitToElements", FIT_TO_ELEMENTS,
389
- "fitToSuppliedMarkers", FIT_TO_SUPPLIED_MARKERS,
390
- "fitToCoordinates", FIT_TO_COORDINATES
391
- );
392
-
393
- map.putAll(MapBuilder.of(
394
- "setMapBoundaries", SET_MAP_BOUNDARIES,
395
- "setIndoorActiveLevelIndex", SET_INDOOR_ACTIVE_LEVEL_INDEX
396
- ));
397
-
398
- return map;
399
- }
400
-
401
- public static <K, V> Map<K, V> CreateMap(
402
- K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) {
403
- Map map = new HashMap<K, V>();
404
- map.put(k1, v1);
405
- map.put(k2, v2);
406
- map.put(k3, v3);
407
- map.put(k4, v4);
408
- map.put(k5, v5);
409
- map.put(k6, v6);
410
- return map;
411
- }
412
393
 
413
394
  @Override
414
395
  public LayoutShadowNode createShadowNodeInstance() {
@@ -4,6 +4,7 @@ import android.graphics.Bitmap;
4
4
  import android.graphics.Color;
5
5
  import android.view.View;
6
6
 
7
+ import androidx.annotation.NonNull;
7
8
  import androidx.annotation.Nullable;
8
9
 
9
10
  import com.facebook.react.bridge.ReadableArray;
@@ -24,11 +25,6 @@ import java.util.concurrent.ConcurrentHashMap;
24
25
 
25
26
  public class AirMapMarkerManager extends ViewGroupManager<AirMapMarker> {
26
27
 
27
- private static final int SHOW_INFO_WINDOW = 1;
28
- private static final int HIDE_INFO_WINDOW = 2;
29
- private static final int ANIMATE_MARKER_TO_COORDINATE = 3;
30
- private static final int REDRAW = 4;
31
-
32
28
  public static class AirMapMarkerSharedIcon {
33
29
  private BitmapDescriptor iconBitmapDescriptor;
34
30
  private Bitmap bitmap;
@@ -289,33 +285,25 @@ public class AirMapMarkerManager extends ViewGroupManager<AirMapMarker> {
289
285
  }
290
286
 
291
287
  @Override
292
- @Nullable
293
- public Map<String, Integer> getCommandsMap() {
294
- return MapBuilder.of(
295
- "showCallout", SHOW_INFO_WINDOW,
296
- "hideCallout", HIDE_INFO_WINDOW,
297
- "animateMarkerToCoordinate", ANIMATE_MARKER_TO_COORDINATE,
298
- "redraw", REDRAW
299
- );
300
- }
301
-
302
- @Override
303
- public void receiveCommand(AirMapMarker view, int commandId, @Nullable ReadableArray args) {
304
- Integer duration;
305
- Double lat;
306
- Double lng;
288
+ public void receiveCommand(@NonNull AirMapMarker view, String commandId, @Nullable ReadableArray args) {
289
+ int duration;
290
+ double lat;
291
+ double lng;
307
292
  ReadableMap region;
308
293
 
309
294
  switch (commandId) {
310
- case SHOW_INFO_WINDOW:
295
+ case "showCallout":
311
296
  ((Marker) view.getFeature()).showInfoWindow();
312
297
  break;
313
298
 
314
- case HIDE_INFO_WINDOW:
299
+ case "hideCallout":
315
300
  ((Marker) view.getFeature()).hideInfoWindow();
316
301
  break;
317
302
 
318
- case ANIMATE_MARKER_TO_COORDINATE:
303
+ case "animateMarkerToCoordinate":
304
+ if(args == null) {
305
+ break;
306
+ }
319
307
  region = args.getMap(0);
320
308
  duration = args.getInt(1);
321
309
 
@@ -324,7 +312,7 @@ public class AirMapMarkerManager extends ViewGroupManager<AirMapMarker> {
324
312
  view.animateToCoodinate(new LatLng(lat, lng), duration);
325
313
  break;
326
314
 
327
- case REDRAW:
315
+ case "redraw":
328
316
  view.updateMarkerIcon();
329
317
  break;
330
318
  }
@@ -14,9 +14,9 @@
14
14
  @property (nonatomic, strong) GMSCircle *circle;
15
15
  @property (nonatomic, assign) double radius;
16
16
  @property (nonatomic, assign) CLLocationCoordinate2D centerCoordinate;
17
- @property (nonatomic, assign) UIColor *strokeColor;
17
+ @property (nonatomic, strong) UIColor *strokeColor;
18
18
  @property (nonatomic, assign) double strokeWidth;
19
- @property (nonatomic, assign) UIColor *fillColor;
19
+ @property (nonatomic, strong) UIColor *fillColor;
20
20
  @property (nonatomic, assign) int zIndex;
21
21
 
22
22
  @end
@@ -11,15 +11,34 @@
11
11
  #import <React/RCTUtils.h>
12
12
 
13
13
  @implementation AIRGoogleMapCircle
14
+ {
15
+ BOOL _didMoveToWindow;
16
+ }
14
17
 
15
18
  - (instancetype)init
16
19
  {
17
20
  if (self = [super init]) {
21
+ _didMoveToWindow = false;
18
22
  _circle = [[GMSCircle alloc] init];
19
23
  }
20
24
  return self;
21
25
  }
22
26
 
27
+ - (void)didMoveToWindow {
28
+ [super didMoveToWindow];
29
+ if(_didMoveToWindow) return;
30
+ _didMoveToWindow = true;
31
+ if(_fillColor) {
32
+ _circle.fillColor = _fillColor;
33
+ }
34
+ if(_strokeColor) {
35
+ _circle.strokeColor = _strokeColor;
36
+ }
37
+ if(_strokeWidth) {
38
+ _circle.strokeWidth = _strokeWidth;
39
+ }
40
+ }
41
+
23
42
  - (void)setRadius:(double)radius
24
43
  {
25
44
  _radius = radius;
@@ -35,19 +54,25 @@
35
54
  -(void)setStrokeColor:(UIColor *)strokeColor
36
55
  {
37
56
  _strokeColor = strokeColor;
38
- _circle.strokeColor = strokeColor;
57
+ if(_didMoveToWindow) {
58
+ _circle.strokeColor = strokeColor;
59
+ }
39
60
  }
40
61
 
41
62
  -(void)setStrokeWidth:(double)strokeWidth
42
63
  {
43
64
  _strokeWidth = strokeWidth;
44
- _circle.strokeWidth = strokeWidth;
65
+ if(_didMoveToWindow) {
66
+ _circle.strokeWidth = strokeWidth;
67
+ }
45
68
  }
46
69
 
47
70
  -(void)setFillColor:(UIColor *)fillColor
48
71
  {
49
72
  _fillColor = fillColor;
50
- _circle.fillColor = fillColor;
73
+ if(_didMoveToWindow) {
74
+ _circle.fillColor = fillColor;
75
+ }
51
76
  }
52
77
 
53
78
  -(void)setZIndex:(int)zIndex
@@ -20,9 +20,9 @@
20
20
  @property (nonatomic, strong) NSArray<NSArray<AIRMapCoordinate *> *> *holes;
21
21
  @property (nonatomic, copy) RCTBubblingEventBlock onPress;
22
22
 
23
- @property (nonatomic, assign) UIColor *fillColor;
23
+ @property (nonatomic, strong) UIColor *fillColor;
24
24
  @property (nonatomic, assign) double strokeWidth;
25
- @property (nonatomic, assign) UIColor *strokeColor;
25
+ @property (nonatomic, strong) UIColor *strokeColor;
26
26
  @property (nonatomic, assign) BOOL geodesic;
27
27
  @property (nonatomic, assign) int zIndex;
28
28
  @property (nonatomic, assign) BOOL tappable;
@@ -11,16 +11,35 @@
11
11
  #import <GoogleMaps/GoogleMaps.h>
12
12
 
13
13
  @implementation AIRGoogleMapPolygon
14
+ {
15
+ BOOL _didMoveToWindow;
16
+ }
14
17
 
15
18
  - (instancetype)init
16
19
  {
17
20
  if (self = [super init]) {
21
+ _didMoveToWindow = false;
18
22
  _polygon = [[AIRGMSPolygon alloc] init];
19
23
  }
20
24
 
21
25
  return self;
22
26
  }
23
27
 
28
+ - (void)didMoveToWindow {
29
+ [super didMoveToWindow];
30
+ if(_didMoveToWindow) return;
31
+ _didMoveToWindow = true;
32
+ if(_fillColor) {
33
+ _polygon.fillColor = _fillColor;
34
+ }
35
+ if(_strokeColor) {
36
+ _polygon.strokeColor = _strokeColor;
37
+ }
38
+ if(_strokeWidth) {
39
+ _polygon.strokeWidth = _strokeWidth;
40
+ }
41
+ }
42
+
24
43
  - (void)setCoordinates:(NSArray<AIRMapCoordinate *> *)coordinates
25
44
  {
26
45
  _coordinates = coordinates;
@@ -58,19 +77,25 @@
58
77
  -(void)setFillColor:(UIColor *)fillColor
59
78
  {
60
79
  _fillColor = fillColor;
61
- _polygon.fillColor = fillColor;
80
+ if(_didMoveToWindow) {
81
+ _polygon.fillColor = fillColor;
82
+ }
62
83
  }
63
84
 
64
85
  -(void)setStrokeWidth:(double)strokeWidth
65
86
  {
66
87
  _strokeWidth = strokeWidth;
67
- _polygon.strokeWidth = strokeWidth;
88
+ if(_didMoveToWindow) {
89
+ _polygon.strokeWidth = strokeWidth;
90
+ }
68
91
  }
69
92
 
70
93
  -(void)setStrokeColor:(UIColor *) strokeColor
71
94
  {
72
95
  _strokeColor = strokeColor;
73
- _polygon.strokeColor = strokeColor;
96
+ if(_didMoveToWindow) {
97
+ _polygon.strokeColor = strokeColor;
98
+ }
74
99
  }
75
100
 
76
101
  -(void)setGeodesic:(BOOL)geodesic
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
- import { Animated, ViewProps, ImageURISource, ImageRequireSource, View } from 'react-native';
2
+ import { Animated, ViewProps, ImageURISource, ImageRequireSource } from 'react-native';
3
3
  import { MapManagerCommand, NativeComponent, ProviderContext, UIManagerCommand } from './decorateMapComponent';
4
+ import { MapMarkerNativeComponentType } from './MapMarkerNativeComponent';
4
5
  import { CalloutPressEvent, LatLng, MarkerDeselectEvent, MarkerDragEvent, MarkerDragStartEndEvent, MarkerPressEvent, MarkerSelectEvent, Point } from './sharedTypes';
5
6
  import { Modify } from './sharedTypesInternal';
6
7
  export declare type MapMarkerProps = ViewProps & {
@@ -261,11 +262,11 @@ export declare type MapMarkerProps = ViewProps & {
261
262
  zIndex?: number;
262
263
  };
263
264
  declare type OmittedProps = Omit<MapMarkerProps, 'stopPropagation'>;
264
- declare type NativeProps = Modify<OmittedProps, {
265
+ export declare type NativeProps = Modify<OmittedProps, {
265
266
  icon?: string;
266
267
  image?: MapMarkerProps['image'] | string;
267
268
  }> & {
268
- ref: React.RefObject<View>;
269
+ ref: React.RefObject<MapMarkerNativeComponentType>;
269
270
  };
270
271
  export declare class MapMarker extends React.Component<MapMarkerProps> {
271
272
  context: React.ContextType<typeof ProviderContext>;
@@ -275,16 +276,17 @@ export declare class MapMarker extends React.Component<MapMarkerProps> {
275
276
  static Animated: Animated.AnimatedComponent<typeof MapMarker>;
276
277
  private marker;
277
278
  constructor(props: MapMarkerProps);
279
+ /**
280
+ * @deprecated Will be removed in v2.0.0, as setNativeProps is not a thing in fabric.
281
+ * See https://reactnative.dev/docs/new-architecture-library-intro#migrating-off-setnativeprops
282
+ */
278
283
  setNativeProps(props: Partial<NativeProps>): void;
279
284
  showCallout(): void;
280
285
  hideCallout(): void;
281
286
  redrawCallout(): void;
282
287
  animateMarkerToCoordinate(coordinate: LatLng, duration?: number): void;
283
288
  redraw(): void;
284
- _getHandle(): number | null;
285
- _runCommand(name: NativeCommandName, args: any[]): void;
286
289
  render(): JSX.Element;
287
290
  }
288
291
  declare const _default: typeof MapMarker;
289
292
  export default _default;
290
- declare type NativeCommandName = 'showCallout' | 'hideCallout' | 'redrawCallout' | 'animateMarkerToCoordinate' | 'redraw';
package/lib/MapMarker.js CHANGED
@@ -27,6 +27,7 @@ exports.MapMarker = void 0;
27
27
  const React = __importStar(require("react"));
28
28
  const react_native_1 = require("react-native");
29
29
  const decorateMapComponent_1 = __importStar(require("./decorateMapComponent"));
30
+ const MapMarkerNativeComponent_1 = require("./MapMarkerNativeComponent");
30
31
  class MapMarker extends React.Component {
31
32
  getNativeComponent;
32
33
  getMapManagerCommand;
@@ -41,37 +42,38 @@ class MapMarker extends React.Component {
41
42
  this.redrawCallout = this.redrawCallout.bind(this);
42
43
  this.animateMarkerToCoordinate = this.animateMarkerToCoordinate.bind(this);
43
44
  }
45
+ /**
46
+ * @deprecated Will be removed in v2.0.0, as setNativeProps is not a thing in fabric.
47
+ * See https://reactnative.dev/docs/new-architecture-library-intro#migrating-off-setnativeprops
48
+ */
44
49
  setNativeProps(props) {
50
+ console.warn('setNativeProps is deprecated and will be removed in next major release');
51
+ // @ts-ignore
45
52
  this.marker.current?.setNativeProps(props);
46
53
  }
47
54
  showCallout() {
48
- this._runCommand('showCallout', []);
55
+ if (this.marker.current) {
56
+ MapMarkerNativeComponent_1.Commands.showCallout(this.marker.current);
57
+ }
49
58
  }
50
59
  hideCallout() {
51
- this._runCommand('hideCallout', []);
60
+ if (this.marker.current) {
61
+ MapMarkerNativeComponent_1.Commands.hideCallout(this.marker.current);
62
+ }
52
63
  }
53
64
  redrawCallout() {
54
- this._runCommand('redrawCallout', []);
65
+ if (this.marker.current) {
66
+ MapMarkerNativeComponent_1.Commands.redrawCallout(this.marker.current);
67
+ }
55
68
  }
56
69
  animateMarkerToCoordinate(coordinate, duration = 500) {
57
- this._runCommand('animateMarkerToCoordinate', [coordinate, duration]);
70
+ if (this.marker.current) {
71
+ MapMarkerNativeComponent_1.Commands.animateMarkerToCoordinate(this.marker.current, coordinate, duration);
72
+ }
58
73
  }
59
74
  redraw() {
60
- this._runCommand('redraw', []);
61
- }
62
- _getHandle() {
63
- return (0, react_native_1.findNodeHandle)(this.marker.current);
64
- }
65
- _runCommand(name, args) {
66
- switch (react_native_1.Platform.OS) {
67
- case 'android':
68
- react_native_1.UIManager.dispatchViewManagerCommand(this._getHandle(), this.getUIManagerCommand(name), args);
69
- break;
70
- case 'ios':
71
- this.getMapManagerCommand(name)(this._getHandle(), ...args);
72
- break;
73
- default:
74
- break;
75
+ if (this.marker.current) {
76
+ MapMarkerNativeComponent_1.Commands.redraw(this.marker.current);
75
77
  }
76
78
  }
77
79
  render() {
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import type { HostComponent } from 'react-native';
3
+ import { NativeProps } from './MapMarker';
4
+ import { LatLng } from './sharedTypes';
5
+ export declare type MapMarkerNativeComponentType = HostComponent<NativeProps>;
6
+ interface NativeCommands {
7
+ showCallout: (viewRef: NonNullable<React.RefObject<MapMarkerNativeComponentType>['current']>) => void;
8
+ hideCallout: (viewRef: NonNullable<React.RefObject<MapMarkerNativeComponentType>['current']>) => void;
9
+ redrawCallout: (viewRef: NonNullable<React.RefObject<MapMarkerNativeComponentType>['current']>) => void;
10
+ animateMarkerToCoordinate: (viewRef: NonNullable<React.RefObject<MapMarkerNativeComponentType>['current']>, coordinate: LatLng, duration: number) => void;
11
+ redraw: (viewRef: NonNullable<React.RefObject<MapMarkerNativeComponentType>['current']>) => void;
12
+ }
13
+ export declare const Commands: NativeCommands;
14
+ export {};
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Commands = void 0;
7
+ const codegenNativeCommands_1 = __importDefault(require("react-native/Libraries/Utilities/codegenNativeCommands"));
8
+ exports.Commands = (0, codegenNativeCommands_1.default)({
9
+ supportedCommands: [
10
+ 'showCallout',
11
+ 'hideCallout',
12
+ 'redrawCallout',
13
+ 'animateMarkerToCoordinate',
14
+ 'redraw',
15
+ ],
16
+ });
@@ -133,7 +133,6 @@ export declare class MapPolygon extends React.Component<MapPolygonProps> {
133
133
  private polygon;
134
134
  constructor(props: MapPolygonProps);
135
135
  setNativeProps(props: Partial<MapPolygonProps>): void;
136
- updateNativeProps(): () => void;
137
136
  render(): JSX.Element;
138
137
  }
139
138
  declare const _default: typeof MapPolygon;
package/lib/MapPolygon.js CHANGED
@@ -26,7 +26,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.MapPolygon = void 0;
27
27
  const React = __importStar(require("react"));
28
28
  const decorateMapComponent_1 = __importStar(require("./decorateMapComponent"));
29
- const ProviderConstants = __importStar(require("./ProviderConstants"));
30
29
  class MapPolygon extends React.Component {
31
30
  getNativeComponent;
32
31
  getMapManagerCommand;
@@ -39,30 +38,10 @@ class MapPolygon extends React.Component {
39
38
  setNativeProps(props) {
40
39
  this.polygon.current?.setNativeProps(props);
41
40
  }
42
- updateNativeProps() {
43
- return () => {
44
- const { fillColor, strokeColor, strokeWidth } = this.props;
45
- let polygonNativeProps = {};
46
- if (fillColor) {
47
- polygonNativeProps.fillColor = fillColor;
48
- }
49
- if (strokeColor) {
50
- polygonNativeProps.strokeColor = strokeColor;
51
- }
52
- if (strokeWidth) {
53
- polygonNativeProps.strokeWidth = strokeWidth;
54
- }
55
- if (polygonNativeProps) {
56
- this.setNativeProps(polygonNativeProps);
57
- }
58
- };
59
- }
60
41
  render() {
61
42
  const { strokeColor = '#000', strokeWidth = 1 } = this.props;
62
43
  const AIRMapPolygon = this.getNativeComponent();
63
- return (<AIRMapPolygon {...this.props} strokeColor={strokeColor} strokeWidth={strokeWidth} ref={this.polygon} onLayout={this.context === ProviderConstants.PROVIDER_GOOGLE
64
- ? this.updateNativeProps()
65
- : undefined}/>);
44
+ return (<AIRMapPolygon {...this.props} strokeColor={strokeColor} strokeWidth={strokeWidth} ref={this.polygon}/>);
66
45
  }
67
46
  }
68
47
  exports.MapPolygon = MapPolygon;
package/lib/MapView.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as React from 'react';
2
- import { Animated as RNAnimated, Animated, NativeSyntheticEvent, View, ViewProps } from 'react-native';
2
+ import { Animated as RNAnimated, Animated, NativeSyntheticEvent, ViewProps } from 'react-native';
3
3
  import { CalloutPressEvent, ClickEvent, Frame, LatLng, MarkerDeselectEvent, MarkerDragEvent, MarkerDragStartEndEvent, MarkerPressEvent, MarkerSelectEvent, Point, Provider, Region } from './sharedTypes';
4
4
  import { Address, BoundingBox, Camera, ChangeEvent, Details, EdgePadding, FitToOptions, IndoorBuildingEvent, IndoorLevelActivatedEvent, KmlMapEvent, LongPressEvent, MapPressEvent, MapStyleElement, MapType, MapTypes, PanDragEvent, PoiClickEvent, SnapshotOptions, UserLocationChangeEvent } from './MapView.types';
5
5
  import { Modify } from './sharedTypesInternal';
6
+ import { MapViewNativeComponentType } from './MapViewNativeComponent';
6
7
  export declare const MAP_TYPES: MapTypes;
7
8
  export declare type MapViewProps = ViewProps & {
8
9
  /**
@@ -559,8 +560,8 @@ declare type ModifiedProps = Modify<MapViewProps, {
559
560
  region?: MapViewProps['region'] | null;
560
561
  initialRegion?: MapViewProps['initialRegion'] | null;
561
562
  }>;
562
- declare type NativeProps = Omit<ModifiedProps, 'customMapStyle' | 'onRegionChange' | 'onRegionChangeComplete'> & {
563
- ref: React.RefObject<View>;
563
+ export declare type NativeProps = Omit<ModifiedProps, 'customMapStyle' | 'onRegionChange' | 'onRegionChangeComplete'> & {
564
+ ref: React.RefObject<MapViewNativeComponentType>;
564
565
  customMapStyleString?: string;
565
566
  handlePanDrag?: boolean;
566
567
  onChange?: (e: ChangeEvent) => void;
@@ -572,6 +573,10 @@ declare class MapView extends React.Component<MapViewProps, State> {
572
573
  static Animated: Animated.AnimatedComponent<typeof MapView>;
573
574
  private map;
574
575
  constructor(props: MapViewProps);
576
+ /**
577
+ * @deprecated Will be removed in v2.0.0, as setNativeProps is not a thing in fabric.
578
+ * See https://reactnative.dev/docs/new-architecture-library-intro#migrating-off-setnativeprops
579
+ */
575
580
  setNativeProps(props: Partial<NativeProps>): void;
576
581
  private _onMapReady;
577
582
  private _onChange;
@@ -658,9 +663,7 @@ declare class MapView extends React.Component<MapViewProps, State> {
658
663
  * @return Object Object bounding box ({ northEast: <LatLng>, southWest: <LatLng> })
659
664
  */
660
665
  boundingBoxForRegion(region: Region): BoundingBox;
661
- private _uiManagerCommand;
662
666
  private _mapManagerCommand;
663
- private _getHandle;
664
667
  private _runCommand;
665
668
  render(): JSX.Element;
666
669
  }
package/lib/MapView.js CHANGED
@@ -28,6 +28,7 @@ const React = __importStar(require("react"));
28
28
  const react_native_1 = require("react-native");
29
29
  const decorateMapComponent_1 = require("./decorateMapComponent");
30
30
  const ProviderConstants = __importStar(require("./ProviderConstants"));
31
+ const MapViewNativeComponent_1 = require("./MapViewNativeComponent");
31
32
  exports.MAP_TYPES = {
32
33
  STANDARD: 'standard',
33
34
  SATELLITE: 'satellite',
@@ -49,7 +50,13 @@ class MapView extends React.Component {
49
50
  this._onMapReady = this._onMapReady.bind(this);
50
51
  this._onChange = this._onChange.bind(this);
51
52
  }
53
+ /**
54
+ * @deprecated Will be removed in v2.0.0, as setNativeProps is not a thing in fabric.
55
+ * See https://reactnative.dev/docs/new-architecture-library-intro#migrating-off-setnativeprops
56
+ */
52
57
  setNativeProps(props) {
58
+ console.warn('setNativeProps is deprecated and will be removed in next major release');
59
+ // @ts-ignore
53
60
  this.map.current?.setNativeProps(props);
54
61
  }
55
62
  _onMapReady() {
@@ -74,7 +81,7 @@ class MapView extends React.Component {
74
81
  }
75
82
  getCamera() {
76
83
  if (react_native_1.Platform.OS === 'android') {
77
- return react_native_1.NativeModules.AirMapModule.getCamera(this._getHandle());
84
+ return react_native_1.NativeModules.AirMapModule.getCamera(this.map.current);
78
85
  }
79
86
  else if (react_native_1.Platform.OS === 'ios') {
80
87
  return this._runCommand('getCamera', []);
@@ -82,25 +89,37 @@ class MapView extends React.Component {
82
89
  return Promise.reject('getCamera not supported on this platform');
83
90
  }
84
91
  setCamera(camera) {
85
- this._runCommand('setCamera', [camera]);
92
+ if (this.map.current) {
93
+ MapViewNativeComponent_1.Commands.setCamera(this.map.current, camera);
94
+ }
86
95
  }
87
96
  animateCamera(camera, opts) {
88
- this._runCommand('animateCamera', [camera, opts ? opts.duration : 500]);
97
+ if (this.map.current) {
98
+ MapViewNativeComponent_1.Commands.animateCamera(this.map.current, camera, opts?.duration ? opts.duration : 500);
99
+ }
89
100
  }
90
101
  animateToRegion(region, duration = 500) {
91
- this._runCommand('animateToRegion', [region, duration]);
102
+ if (this.map.current) {
103
+ MapViewNativeComponent_1.Commands.animateToRegion(this.map.current, region, duration);
104
+ }
92
105
  }
93
106
  fitToElements(options = {}) {
94
- const { edgePadding = { top: 0, right: 0, bottom: 0, left: 0 }, animated = true, } = options;
95
- this._runCommand('fitToElements', [edgePadding, animated]);
107
+ if (this.map.current) {
108
+ const { edgePadding = { top: 0, right: 0, bottom: 0, left: 0 }, animated = true, } = options;
109
+ MapViewNativeComponent_1.Commands.fitToElements(this.map.current, edgePadding, animated);
110
+ }
96
111
  }
97
112
  fitToSuppliedMarkers(markers, options = {}) {
98
- const { edgePadding = { top: 0, right: 0, bottom: 0, left: 0 }, animated = true, } = options;
99
- this._runCommand('fitToSuppliedMarkers', [markers, edgePadding, animated]);
113
+ if (this.map.current) {
114
+ const { edgePadding = { top: 0, right: 0, bottom: 0, left: 0 }, animated = true, } = options;
115
+ MapViewNativeComponent_1.Commands.fitToSuppliedMarkers(this.map.current, markers, edgePadding, animated);
116
+ }
100
117
  }
101
118
  fitToCoordinates(coordinates = [], options = {}) {
102
- const { edgePadding = { top: 0, right: 0, bottom: 0, left: 0 }, animated = true, } = options;
103
- this._runCommand('fitToCoordinates', [coordinates, edgePadding, animated]);
119
+ if (this.map.current) {
120
+ const { edgePadding = { top: 0, right: 0, bottom: 0, left: 0 }, animated = true, } = options;
121
+ MapViewNativeComponent_1.Commands.fitToCoordinates(this.map.current, coordinates, edgePadding, animated);
122
+ }
104
123
  }
105
124
  /**
106
125
  * Get visible boudaries
@@ -109,7 +128,7 @@ class MapView extends React.Component {
109
128
  */
110
129
  async getMapBoundaries() {
111
130
  if (react_native_1.Platform.OS === 'android') {
112
- return await react_native_1.NativeModules.AirMapModule.getMapBoundaries(this._getHandle());
131
+ return await react_native_1.NativeModules.AirMapModule.getMapBoundaries(this.map.current);
113
132
  }
114
133
  else if (react_native_1.Platform.OS === 'ios') {
115
134
  return await this._runCommand('getMapBoundaries', []);
@@ -117,10 +136,14 @@ class MapView extends React.Component {
117
136
  return Promise.reject('getMapBoundaries not supported on this platform');
118
137
  }
119
138
  setMapBoundaries(northEast, southWest) {
120
- this._runCommand('setMapBoundaries', [northEast, southWest]);
139
+ if (this.map.current) {
140
+ MapViewNativeComponent_1.Commands.setMapBoundaries(this.map.current, northEast, southWest);
141
+ }
121
142
  }
122
143
  setIndoorActiveLevelIndex(activeLevelIndex) {
123
- this._runCommand('setIndoorActiveLevelIndex', [activeLevelIndex]);
144
+ if (this.map.current) {
145
+ MapViewNativeComponent_1.Commands.setIndoorActiveLevelIndex(this.map.current, activeLevelIndex);
146
+ }
124
147
  }
125
148
  /**
126
149
  * Takes a snapshot of the map and saves it to a picture
@@ -154,7 +177,7 @@ class MapView extends React.Component {
154
177
  }
155
178
  // Call native function
156
179
  if (react_native_1.Platform.OS === 'android') {
157
- return react_native_1.NativeModules.AirMapModule.takeSnapshot(this._getHandle(), config);
180
+ return react_native_1.NativeModules.AirMapModule.takeSnapshot(this.map.current, config);
158
181
  }
159
182
  else if (react_native_1.Platform.OS === 'ios') {
160
183
  return new Promise((resolve, reject) => {
@@ -189,7 +212,7 @@ class MapView extends React.Component {
189
212
  */
190
213
  addressForCoordinate(coordinate) {
191
214
  if (react_native_1.Platform.OS === 'android') {
192
- return react_native_1.NativeModules.AirMapModule.getAddressFromCoordinates(this._getHandle(), coordinate);
215
+ return react_native_1.NativeModules.AirMapModule.getAddressFromCoordinates(this.map.current, coordinate);
193
216
  }
194
217
  else if (react_native_1.Platform.OS === 'ios') {
195
218
  return this._runCommand('getAddressFromCoordinates', [coordinate]);
@@ -207,7 +230,7 @@ class MapView extends React.Component {
207
230
  */
208
231
  pointForCoordinate(coordinate) {
209
232
  if (react_native_1.Platform.OS === 'android') {
210
- return react_native_1.NativeModules.AirMapModule.pointForCoordinate(this._getHandle(), coordinate);
233
+ return react_native_1.NativeModules.AirMapModule.pointForCoordinate(this.map.current, coordinate);
211
234
  }
212
235
  else if (react_native_1.Platform.OS === 'ios') {
213
236
  return this._runCommand('pointForCoordinate', [coordinate]);
@@ -225,7 +248,7 @@ class MapView extends React.Component {
225
248
  */
226
249
  coordinateForPoint(point) {
227
250
  if (react_native_1.Platform.OS === 'android') {
228
- return react_native_1.NativeModules.AirMapModule.coordinateForPoint(this._getHandle(), point);
251
+ return react_native_1.NativeModules.AirMapModule.coordinateForPoint(this.map.current, point);
229
252
  }
230
253
  else if (react_native_1.Platform.OS === 'ios') {
231
254
  return this._runCommand('coordinateForPoint', [point]);
@@ -264,24 +287,15 @@ class MapView extends React.Component {
264
287
  },
265
288
  };
266
289
  }
267
- _uiManagerCommand(name) {
268
- const componentName = (0, decorateMapComponent_1.getNativeMapName)(this.props.provider);
269
- return react_native_1.UIManager.getViewManagerConfig(componentName).Commands[name];
270
- }
271
290
  _mapManagerCommand(name) {
272
291
  return react_native_1.NativeModules[`${(0, decorateMapComponent_1.getNativeMapName)(this.props.provider)}Manager`][name];
273
292
  }
274
- _getHandle() {
275
- return (0, react_native_1.findNodeHandle)(this.map.current);
276
- }
277
293
  _runCommand(name, args) {
278
- switch (react_native_1.Platform.OS) {
279
- case 'android':
280
- return react_native_1.UIManager.dispatchViewManagerCommand(this._getHandle(), this._uiManagerCommand(name), args);
281
- case 'ios':
282
- return this._mapManagerCommand(name)(this._getHandle(), ...args);
283
- default:
284
- return Promise.reject(`Invalid platform was passed: ${react_native_1.Platform.OS}`);
294
+ if (react_native_1.Platform.OS === 'ios') {
295
+ return this._mapManagerCommand(name)(this.map.current, ...args);
296
+ }
297
+ else {
298
+ return Promise.reject(`Invalid platform was passed: ${react_native_1.Platform.OS}`);
285
299
  }
286
300
  }
287
301
  render() {
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ import type { HostComponent } from 'react-native';
3
+ import { NativeProps } from './MapView';
4
+ import { Camera, EdgePadding } from './MapView.types';
5
+ import { LatLng, Region } from './sharedTypes';
6
+ export declare type MapViewNativeComponentType = HostComponent<NativeProps>;
7
+ interface NativeCommands {
8
+ animateToRegion: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, region: Region, duration: number) => void;
9
+ setCamera: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, camera: Partial<Camera>) => void;
10
+ animateCamera: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, camera: Partial<Camera>, duration: number) => void;
11
+ fitToElements: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, edgePadding: EdgePadding, animated: boolean) => void;
12
+ fitToSuppliedMarkers: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, markers: string[], edgePadding: EdgePadding, animated: boolean) => void;
13
+ fitToCoordinates: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, coordinates: LatLng[], edgePadding: EdgePadding, animated: boolean) => void;
14
+ setMapBoundaries: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, northEast: LatLng, southWest: LatLng) => void;
15
+ setIndoorActiveLevelIndex: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, activeLevelIndex: number) => void;
16
+ }
17
+ export declare const Commands: NativeCommands;
18
+ export {};
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Commands = void 0;
7
+ const codegenNativeCommands_1 = __importDefault(require("react-native/Libraries/Utilities/codegenNativeCommands"));
8
+ exports.Commands = (0, codegenNativeCommands_1.default)({
9
+ supportedCommands: [
10
+ 'animateToRegion',
11
+ 'setCamera',
12
+ 'animateCamera',
13
+ 'fitToElements',
14
+ 'fitToSuppliedMarkers',
15
+ 'fitToCoordinates',
16
+ 'setMapBoundaries',
17
+ 'setIndoorActiveLevelIndex',
18
+ ],
19
+ });
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "main": "lib/index.js",
6
6
  "author": "Leland Richardson <leland.m.richardson@gmail.com>",
7
7
  "homepage": "https://github.com/react-native-maps/react-native-maps#readme",
8
- "version": "1.2.0-beta.2",
8
+ "version": "1.3.0-beta.2",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",