react-native-maps 1.2.0-beta.1 → 1.3.0-beta.1

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
  }
package/lib/Geojson.d.ts CHANGED
@@ -130,6 +130,17 @@ export declare type GeojsonProps = {
130
130
  * @platform — Android: Supported
131
131
  */
132
132
  title?: MarkerProps['title'];
133
+ /**
134
+ * Sets whether this marker should track view changes.
135
+ * It's recommended to turn it off whenever it's possible to improve custom marker performance.
136
+ * This is the default value for all point markers in your geojson data. It can be overriden
137
+ * on a per point basis by adding a `trackViewChanges` property to the `properties` object on the point.
138
+ *
139
+ * @default true
140
+ * @platform iOS: Google Maps only
141
+ * @platform Android: Supported
142
+ */
143
+ tracksViewChanges?: boolean;
133
144
  /**
134
145
  * The order in which this tile overlay is drawn with respect to other overlays. An overlay
135
146
  * with a larger z-index is drawn over overlays with smaller z-indices. The order of overlays
package/lib/Geojson.js CHANGED
@@ -31,14 +31,15 @@ const MapMarker_1 = __importDefault(require("./MapMarker"));
31
31
  const MapPolyline_1 = __importDefault(require("./MapPolyline"));
32
32
  const MapPolygon_1 = __importDefault(require("./MapPolygon"));
33
33
  const Geojson = (props) => {
34
- const { geojson, strokeColor, fillColor, strokeWidth, color, title, image, zIndex, onPress, lineCap, lineJoin, tappable, miterLimit, lineDashPhase, lineDashPattern, markerComponent, } = props;
34
+ const { geojson, strokeColor, fillColor, strokeWidth, color, title, image, zIndex, onPress, lineCap, lineJoin, tappable, tracksViewChanges, miterLimit, lineDashPhase, lineDashPattern, markerComponent, } = props;
35
35
  const pointOverlays = makePointOverlays(geojson.features);
36
36
  const lineOverlays = makeLineOverlays(geojson.features);
37
37
  const polygonOverlays = makePolygonOverlays(geojson.features);
38
38
  return (<React.Fragment>
39
39
  {pointOverlays.map((overlay, index) => {
40
40
  const markerColor = getColor(color, overlay, 'marker-color');
41
- return (<MapMarker_1.default key={index} coordinate={overlay.coordinates} image={image} title={title} pinColor={markerColor} zIndex={zIndex} onPress={() => onPress && onPress(overlay)}>
41
+ const pointOverlayTracksViewChanges = overlay.feature.properties?.tracksViewChanges || tracksViewChanges;
42
+ return (<MapMarker_1.default key={index} coordinate={overlay.coordinates} tracksViewChanges={pointOverlayTracksViewChanges} image={image} title={title} pinColor={markerColor} zIndex={zIndex} onPress={() => onPress && onPress(overlay)}>
42
43
  {markerComponent}
43
44
  </MapMarker_1.default>);
44
45
  })}
@@ -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,6 +276,10 @@ 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;
@@ -282,9 +287,7 @@ export declare class MapMarker extends React.Component<MapMarkerProps> {
282
287
  animateMarkerToCoordinate(coordinate: LatLng, duration?: number): void;
283
288
  redraw(): void;
284
289
  _getHandle(): number | null;
285
- _runCommand(name: NativeCommandName, args: any[]): void;
286
290
  render(): JSX.Element;
287
291
  }
288
292
  declare const _default: typeof MapMarker;
289
293
  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,39 +42,43 @@ 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', []);
75
+ if (this.marker.current) {
76
+ MapMarkerNativeComponent_1.Commands.redraw(this.marker.current);
77
+ }
61
78
  }
62
79
  _getHandle() {
63
80
  return (0, react_native_1.findNodeHandle)(this.marker.current);
64
81
  }
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
- }
76
- }
77
82
  render() {
78
83
  const { stopPropagation = false } = this.props;
79
84
  let image;
@@ -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: React.RefObject<MapMarkerNativeComponentType>['current']) => void;
8
+ hideCallout: (viewRef: React.RefObject<MapMarkerNativeComponentType>['current']) => void;
9
+ redrawCallout: (viewRef: React.RefObject<MapMarkerNativeComponentType>['current']) => void;
10
+ animateMarkerToCoordinate: (viewRef: React.RefObject<MapMarkerNativeComponentType>['current'], coordinate: LatLng, duration: number) => void;
11
+ redraw: (viewRef: 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
+ });
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,7 +663,6 @@ 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
667
  private _getHandle;
664
668
  private _runCommand;
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() {
@@ -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
@@ -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
@@ -264,10 +287,6 @@ 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
  }
@@ -275,13 +294,11 @@ class MapView extends React.Component {
275
294
  return (0, react_native_1.findNodeHandle)(this.map.current);
276
295
  }
277
296
  _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}`);
297
+ if (react_native_1.Platform.OS === 'ios') {
298
+ return this._mapManagerCommand(name)(this._getHandle(), ...args);
299
+ }
300
+ else {
301
+ return Promise.reject(`Invalid platform was passed: ${react_native_1.Platform.OS}`);
285
302
  }
286
303
  }
287
304
  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: React.RefObject<MapViewNativeComponentType>['current'], region: Region, duration: number) => void;
9
+ setCamera: (viewRef: React.RefObject<MapViewNativeComponentType>['current'], camera: Partial<Camera>) => void;
10
+ animateCamera: (viewRef: React.RefObject<MapViewNativeComponentType>['current'], camera: Partial<Camera>, duration: number) => void;
11
+ fitToElements: (viewRef: React.RefObject<MapViewNativeComponentType>['current'], edgePadding: EdgePadding, animated: boolean) => void;
12
+ fitToSuppliedMarkers: (viewRef: React.RefObject<MapViewNativeComponentType>['current'], markers: string[], edgePadding: EdgePadding, animated: boolean) => void;
13
+ fitToCoordinates: (viewRef: React.RefObject<MapViewNativeComponentType>['current'], coordinates: LatLng[], edgePadding: EdgePadding, animated: boolean) => void;
14
+ setMapBoundaries: (viewRef: React.RefObject<MapViewNativeComponentType>['current'], northEast: LatLng, southWest: LatLng) => void;
15
+ setIndoorActiveLevelIndex: (viewRef: 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.1",
8
+ "version": "1.3.0-beta.1",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",