react-native-maps 1.18.3 → 1.19.0

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.
@@ -152,7 +152,7 @@ public class MapManager extends ViewGroupManager<MapView> {
152
152
 
153
153
  @ReactProp(name = "initialCamera")
154
154
  public void setInitialCamera(MapView view, ReadableMap initialCamera) {
155
- // do nothing, passed as part of the InitialProps
155
+ view.setInitialCamera(initialCamera);
156
156
  }
157
157
 
158
158
  @ReactProp(name = "mapType")
@@ -444,7 +444,8 @@ public class MapManager extends ViewGroupManager<MapView> {
444
444
  "onDoublePress", MapBuilder.of("registrationName", "onDoublePress"),
445
445
  "onMapLoaded", MapBuilder.of("registrationName", "onMapLoaded"),
446
446
  "onMarkerSelect", MapBuilder.of("registrationName", "onMarkerSelect"),
447
- "onMarkerDeselect", MapBuilder.of("registrationName", "onMarkerDeselect")
447
+ "onMarkerDeselect", MapBuilder.of("registrationName", "onMarkerDeselect"),
448
+ "onRegionChangeStart", MapBuilder.of("registrationName", "onRegionChangeStart")
448
449
  ));
449
450
 
450
451
  return map;
@@ -96,19 +96,21 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
96
96
  private Boolean isMapLoaded = false;
97
97
  private Integer loadingBackgroundColor = null;
98
98
  private Integer loadingIndicatorColor = null;
99
- private final int baseMapPadding = 50;
100
99
 
101
100
  private LatLngBounds boundsToMove;
102
101
  private CameraUpdate cameraToSet;
102
+ private boolean setPaddingDeferred = false;
103
103
  private boolean showUserLocation = false;
104
104
  private boolean handlePanDrag = false;
105
105
  private boolean moveOnMarkerPress = true;
106
106
  private boolean cacheEnabled = false;
107
107
  private ReadableMap initialRegion;
108
108
  private ReadableMap region;
109
+ private ReadableMap initialCamera;
109
110
  private ReadableMap camera;
110
111
  private String customMapStyleString;
111
112
  private boolean initialRegionSet = false;
113
+ private boolean initialCameraSet = false;
112
114
  private LatLngBounds cameraLastIdleBounds;
113
115
  private int cameraMoveReason = 0;
114
116
  private MapMarker selectedMarker;
@@ -379,6 +381,10 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
379
381
  @Override
380
382
  public void onCameraMoveStarted(int reason) {
381
383
  cameraMoveReason = reason;
384
+ boolean isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == reason;
385
+ WritableMap event = new WritableNativeMap();
386
+ event.putBoolean("isGesture", isGesture);
387
+ manager.pushEvent(context, view, "onRegionChangeStart", event);
382
388
  }
383
389
  });
384
390
 
@@ -536,13 +542,24 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
536
542
  }
537
543
  }
538
544
 
545
+ public void setInitialCamera(ReadableMap initialCamera) {
546
+ this.initialCamera = initialCamera;
547
+ if (!initialCameraSet && map != null) {
548
+ moveToCamera(initialCamera);
549
+ initialCameraSet = true;
550
+ }
551
+ }
552
+
539
553
  private void applyBridgedProps() {
540
554
  if(initialRegion != null) {
541
555
  moveToRegion(initialRegion);
542
556
  initialRegionSet = true;
543
557
  } else if(region != null) {
544
558
  moveToRegion(region);
545
- } else {
559
+ } else if (initialCamera != null) {
560
+ moveToCamera(initialCamera);
561
+ initialCameraSet = true;
562
+ } else if (camera != null) {
546
563
  moveToCamera(camera);
547
564
  }
548
565
  if(customMapStyleString != null) {
@@ -845,6 +862,21 @@ public static CameraPosition cameraPositionFromMap(ReadableMap camera){
845
862
  }
846
863
 
847
864
  public void updateExtraData(Object extraData) {
865
+ if (setPaddingDeferred && super.getHeight() > 0 && super.getWidth() > 0) {
866
+ CameraUpdate cu = CameraUpdateFactory.newCameraPosition(map.getCameraPosition());
867
+
868
+ map.setPadding(edgeLeftPadding + baseLeftMapPadding,
869
+ edgeTopPadding + baseTopMapPadding,
870
+ edgeRightPadding + baseRightMapPadding,
871
+ edgeBottomPadding + baseBottomMapPadding);
872
+ map.moveCamera(cu);
873
+
874
+ // Move the google logo to the default base padding value.
875
+ map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
876
+
877
+ setPaddingDeferred = false;
878
+ }
879
+
848
880
  // if boundsToMove is not null, we now have the MapView's width/height, so we can apply
849
881
  // a proper camera move
850
882
  if (boundsToMove != null) {
@@ -922,10 +954,10 @@ public static CameraPosition cameraPositionFromMap(ReadableMap camera){
922
954
  }
923
955
  if (addedPosition) {
924
956
  LatLngBounds bounds = builder.build();
925
- CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, baseMapPadding);
957
+ CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
926
958
 
927
959
  if (edgePadding != null) {
928
- map.setPadding(edgePadding.getInt("left"), edgePadding.getInt("top"),
960
+ appendMapPadding(edgePadding.getInt("left"), edgePadding.getInt("top"),
929
961
  edgePadding.getInt("right"), edgePadding.getInt("bottom"));
930
962
  }
931
963
 
@@ -934,6 +966,8 @@ public static CameraPosition cameraPositionFromMap(ReadableMap camera){
934
966
  } else {
935
967
  map.moveCamera(cu);
936
968
  }
969
+ // Move the google logo to the default base padding value.
970
+ map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
937
971
  }
938
972
  }
939
973
 
@@ -964,10 +998,10 @@ public static CameraPosition cameraPositionFromMap(ReadableMap camera){
964
998
 
965
999
  if (addedPosition) {
966
1000
  LatLngBounds bounds = builder.build();
967
- CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, baseMapPadding);
1001
+ CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
968
1002
 
969
1003
  if (edgePadding != null) {
970
- map.setPadding(edgePadding.getInt("left"), edgePadding.getInt("top"),
1004
+ appendMapPadding(edgePadding.getInt("left"), edgePadding.getInt("top"),
971
1005
  edgePadding.getInt("right"), edgePadding.getInt("bottom"));
972
1006
  }
973
1007
 
@@ -976,20 +1010,54 @@ public static CameraPosition cameraPositionFromMap(ReadableMap camera){
976
1010
  } else {
977
1011
  map.moveCamera(cu);
978
1012
  }
1013
+ // Move the google logo to the default base padding value.
1014
+ map.setPadding(baseLeftMapPadding, baseTopMapPadding, baseRightMapPadding, baseBottomMapPadding);
979
1015
  }
980
1016
  }
981
1017
 
1018
+ // padding configured by 'mapPadding' property
982
1019
  int baseLeftMapPadding;
983
1020
  int baseRightMapPadding;
984
1021
  int baseTopMapPadding;
985
1022
  int baseBottomMapPadding;
1023
+ // extra padding specified by 'edgePadding' option of fitToElements/fitToSuppliedMarkers/fitToCoordinates
1024
+ int edgeLeftPadding;
1025
+ int edgeRightPadding;
1026
+ int edgeTopPadding;
1027
+ int edgeBottomPadding;
986
1028
 
987
1029
  public void applyBaseMapPadding(int left, int top, int right, int bottom){
988
- this.map.setPadding(left, top, right, bottom);
1030
+ if (super.getHeight() <= 0 || super.getWidth() <= 0) {
1031
+ // the map is not laid out yet and calling setPadding() now has no effect
1032
+ baseLeftMapPadding = left;
1033
+ baseRightMapPadding = right;
1034
+ baseTopMapPadding = top;
1035
+ baseBottomMapPadding = bottom;
1036
+ setPaddingDeferred = true;
1037
+ return;
1038
+ }
1039
+
1040
+ // retrieve current camera with current edge paddings configured
1041
+ map.setPadding(edgeLeftPadding + baseLeftMapPadding,
1042
+ edgeTopPadding + baseTopMapPadding,
1043
+ edgeRightPadding + baseRightMapPadding,
1044
+ edgeBottomPadding + baseBottomMapPadding);
1045
+ CameraUpdate cu = CameraUpdateFactory.newCameraPosition(map.getCameraPosition());
1046
+
989
1047
  baseLeftMapPadding = left;
990
1048
  baseRightMapPadding = right;
991
1049
  baseTopMapPadding = top;
992
1050
  baseBottomMapPadding = bottom;
1051
+
1052
+ // apply base paddings and restore center position of the map
1053
+ map.setPadding(edgeLeftPadding + left,
1054
+ edgeTopPadding + top,
1055
+ edgeRightPadding + right,
1056
+ edgeBottomPadding + bottom);
1057
+ map.moveCamera(cu);
1058
+
1059
+ // Move the google logo to the default base padding value.
1060
+ map.setPadding(left, top, right, bottom);
993
1061
  }
994
1062
 
995
1063
  public void fitToCoordinates(ReadableArray coordinatesArray, ReadableMap edgePadding,
@@ -1006,7 +1074,7 @@ public static CameraPosition cameraPositionFromMap(ReadableMap camera){
1006
1074
  }
1007
1075
 
1008
1076
  LatLngBounds bounds = builder.build();
1009
- CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, baseMapPadding);
1077
+ CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
1010
1078
 
1011
1079
  if (edgePadding != null) {
1012
1080
  appendMapPadding(edgePadding.getInt("left"), edgePadding.getInt("top"), edgePadding.getInt("right"), edgePadding.getInt("bottom"));
@@ -1022,21 +1090,17 @@ public static CameraPosition cameraPositionFromMap(ReadableMap camera){
1022
1090
  }
1023
1091
 
1024
1092
  private void appendMapPadding(int iLeft,int iTop, int iRight, int iBottom) {
1025
- int left;
1026
- int top;
1027
- int right;
1028
- int bottom;
1029
1093
  double density = getResources().getDisplayMetrics().density;
1030
1094
 
1031
- left = (int) (iLeft * density);
1032
- top = (int) (iTop * density);
1033
- right = (int) (iRight * density);
1034
- bottom = (int) (iBottom * density);
1095
+ edgeLeftPadding = (int) (iLeft * density);
1096
+ edgeTopPadding = (int) (iTop * density);
1097
+ edgeRightPadding = (int) (iRight * density);
1098
+ edgeBottomPadding = (int) (iBottom * density);
1035
1099
 
1036
- map.setPadding(left + baseLeftMapPadding,
1037
- top + baseTopMapPadding,
1038
- right + baseRightMapPadding,
1039
- bottom + baseBottomMapPadding);
1100
+ map.setPadding(edgeLeftPadding + baseLeftMapPadding,
1101
+ edgeTopPadding + baseTopMapPadding,
1102
+ edgeRightPadding + baseRightMapPadding,
1103
+ edgeBottomPadding + baseBottomMapPadding);
1040
1104
  }
1041
1105
 
1042
1106
  public double[][] getMapBoundaries() {
@@ -38,6 +38,7 @@
38
38
  @property (nonatomic, copy) RCTBubblingEventBlock onMarkerDeselect;
39
39
  @property (nonatomic, copy) RCTBubblingEventBlock onChange;
40
40
  @property (nonatomic, copy) RCTBubblingEventBlock onPoiClick;
41
+ @property (nonatomic, copy) RCTDirectEventBlock onRegionChangeStart;
41
42
  @property (nonatomic, copy) RCTDirectEventBlock onRegionChange;
42
43
  @property (nonatomic, copy) RCTDirectEventBlock onRegionChangeComplete;
43
44
  @property (nonatomic, copy) RCTDirectEventBlock onIndoorLevelActivated;
@@ -72,6 +73,7 @@
72
73
  - (void)didTapPolygon:(GMSPolygon *)polygon;
73
74
  - (void)didTapAtCoordinate:(CLLocationCoordinate2D)coordinate;
74
75
  - (void)didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate;
76
+ - (void)willMove:(BOOL)gesture;
75
77
  - (void)didChangeCameraPosition:(GMSCameraPosition *)position isGesture:(BOOL)isGesture;
76
78
  - (void)idleAtCameraPosition:(GMSCameraPosition *)position isGesture:(BOOL)isGesture;
77
79
  - (void)didTapPOIWithPlaceID:(NSString *)placeID name:(NSString *) name location:(CLLocationCoordinate2D) location;
@@ -97,7 +97,6 @@ id regionAsJSON(MKCoordinateRegion region) {
97
97
  _tiles = [NSMutableArray array];
98
98
  _overlays = [NSMutableArray array];
99
99
  _initialCamera = nil;
100
- _cameraProp = nil;
101
100
  _initialRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake(0.0, 0.0), MKCoordinateSpanMake(0.0, 0.0));
102
101
  _region = MKCoordinateRegionMake(CLLocationCoordinate2DMake(0.0, 0.0), MKCoordinateSpanMake(0.0, 0.0));
103
102
  _initialRegionSet = false;
@@ -315,9 +314,19 @@ id regionAsJSON(MKCoordinateRegion region) {
315
314
  _googleMapId = googleMapId;
316
315
  }
317
316
 
317
+ - (GMSCameraPosition *)cameraProp {
318
+ if(_didLayoutSubviews) {
319
+ return self.camera;
320
+ } else {
321
+ return _initialCamera;
322
+ }
323
+ }
324
+
318
325
  - (void)setCameraProp:(GMSCameraPosition*)camera {
319
326
  _initialCamera = camera;
320
- self.camera = camera;
327
+ if(_didLayoutSubviews) {
328
+ self.camera = camera;
329
+ }
321
330
  }
322
331
 
323
332
  - (void)setOnMapReady:(RCTBubblingEventBlock)onMapReady {
@@ -394,6 +403,11 @@ id regionAsJSON(MKCoordinateRegion region) {
394
403
  self.onLongPress([self eventFromCoordinate:coordinate]);
395
404
  }
396
405
 
406
+ - (void)willMove:(BOOL)gesture {
407
+ id event = @{@"isGesture": [NSNumber numberWithBool:gesture]};
408
+ if (self.onRegionChangeStart) self.onRegionChangeStart(event);
409
+ }
410
+
397
411
  - (void)didChangeCameraPosition:(GMSCameraPosition *)position isGesture:(BOOL)isGesture{
398
412
  id event = @{@"continuous": @YES,
399
413
  @"region": regionAsJSON([AIRGoogleMap makeGMSCameraPositionFromMap:self andGMSCameraPosition:position]),
@@ -117,6 +117,7 @@ RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
117
117
  RCT_EXPORT_VIEW_PROPERTY(onMarkerPress, RCTDirectEventBlock)
118
118
  RCT_EXPORT_VIEW_PROPERTY(onMarkerSelect, RCTDirectEventBlock)
119
119
  RCT_EXPORT_VIEW_PROPERTY(onMarkerDeselect, RCTDirectEventBlock)
120
+ RCT_EXPORT_VIEW_PROPERTY(onRegionChangeStart, RCTDirectEventBlock)
120
121
  RCT_EXPORT_VIEW_PROPERTY(onRegionChange, RCTDirectEventBlock)
121
122
  RCT_EXPORT_VIEW_PROPERTY(onRegionChangeComplete, RCTDirectEventBlock)
122
123
  RCT_EXPORT_VIEW_PROPERTY(onPoiClick, RCTDirectEventBlock)
@@ -160,8 +161,8 @@ RCT_EXPORT_METHOD(setCamera:(nonnull NSNumber *)reactTag
160
161
  RCTLogError(@"Invalid view returned from registry, expecting AIRGoogleMap, got: %@", view);
161
162
  } else {
162
163
  AIRGoogleMap *mapView = (AIRGoogleMap *)view;
163
- GMSCameraPosition *camera = [RCTConvert GMSCameraPositionWithDefaults:json existingCamera:[mapView camera]];
164
- [mapView setCamera:camera];
164
+ GMSCameraPosition *camera = [RCTConvert GMSCameraPositionWithDefaults:json existingCamera:[mapView cameraProp]];
165
+ [mapView setCameraProp:camera];
165
166
  }
166
167
  }];
167
168
  }
@@ -179,7 +180,7 @@ RCT_EXPORT_METHOD(animateCamera:(nonnull NSNumber *)reactTag
179
180
  [CATransaction begin];
180
181
  [CATransaction setAnimationDuration:duration/1000];
181
182
  AIRGoogleMap *mapView = (AIRGoogleMap *)view;
182
- GMSCameraPosition *camera = [RCTConvert GMSCameraPositionWithDefaults:json existingCamera:[mapView camera]];
183
+ GMSCameraPosition *camera = [RCTConvert GMSCameraPositionWithDefaults:json existingCamera:[mapView cameraProp]];
183
184
  [mapView animateToCameraPosition:camera];
184
185
  [CATransaction commit];
185
186
  }
@@ -511,8 +512,10 @@ RCT_EXPORT_METHOD(setIndoorActiveLevelIndex:(nonnull NSNumber *)reactTag
511
512
  return @{ @"legalNotice": [GMSServices openSourceLicenseInfo] };
512
513
  }
513
514
 
514
- - (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture{
515
- self.isGesture = gesture;
515
+ - (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture {
516
+ self.isGesture = gesture;
517
+ AIRGoogleMap *googleMapView = (AIRGoogleMap *)mapView;
518
+ [googleMapView willMove:gesture];
516
519
  }
517
520
 
518
521
  - (void)mapViewDidStartTileRendering:(GMSMapView *)mapView {
@@ -67,6 +67,7 @@ extern const NSInteger AIRMapMaxZoomLevel;
67
67
  @property (nonatomic, copy) RCTDirectEventBlock onMarkerDragEnd;
68
68
 
69
69
  @property (nonatomic, copy) RCTDirectEventBlock onCalloutPress;
70
+ @property (nonatomic, copy) RCTDirectEventBlock onRegionChangeStart;
70
71
  @property (nonatomic, copy) RCTDirectEventBlock onRegionChange;
71
72
  @property (nonatomic, copy) RCTBubblingEventBlock onUserLocationChange;
72
73
 
@@ -113,6 +113,7 @@ RCT_EXPORT_VIEW_PROPERTY(mapType, MKMapType)
113
113
  RCT_EXPORT_VIEW_PROPERTY(cameraZoomRange, NSDictionary)
114
114
  RCT_EXPORT_VIEW_PROPERTY(onMapReady, RCTBubblingEventBlock)
115
115
  RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
116
+ RCT_EXPORT_VIEW_PROPERTY(onRegionChangeStart, RCTDirectEventBlock)
116
117
  RCT_EXPORT_VIEW_PROPERTY(onPanDrag, RCTBubblingEventBlock)
117
118
  RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
118
119
  RCT_EXPORT_VIEW_PROPERTY(onLongPress, RCTBubblingEventBlock)
@@ -935,6 +936,11 @@ static int kDragCenterContext;
935
936
 
936
937
  }
937
938
 
939
+ - (void)mapView:(AIRMap *)mapView regionWillChangeAnimated:(BOOL)animated
940
+ {
941
+ if (mapView.onRegionChangeStart) mapView.onRegionChangeStart(@{});
942
+ }
943
+
938
944
  - (void)mapViewDidChangeVisibleRegion:(AIRMap *)mapView
939
945
  {
940
946
  [self _regionChanged:mapView];
package/lib/MapView.d.ts CHANGED
@@ -314,6 +314,15 @@ export type MapViewProps = ViewProps & {
314
314
  * @platform Android: Supported
315
315
  */
316
316
  onPress?: (event: MapPressEvent) => void;
317
+ /**
318
+ * Callback that is called once before the region changes, such as when the user starts moving the map.
319
+ * `isGesture` property indicates if the move was from the user (true) or an animation (false).
320
+ * **Note**: `isGesture` is supported by Google Maps only.
321
+ *
322
+ * @platform iOS: Supported
323
+ * @platform Android: Supported
324
+ */
325
+ onRegionChangeStart?: (event: NativeSyntheticEvent<Details>) => void;
317
326
  /**
318
327
  * Callback that is called continuously when the region changes, such as when a user is dragging the map.
319
328
  * `isGesture` property indicates if the move was from the user (true) or an animation (false).
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.18.3",
8
+ "version": "1.19.0",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",