react-native-maps 1.11.2 → 1.12.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.
@@ -392,8 +392,6 @@ public class MapManager extends ViewGroupManager<MapView> {
392
392
  "onPress", MapBuilder.of("registrationName", "onPress"),
393
393
  "onLongPress", MapBuilder.of("registrationName", "onLongPress"),
394
394
  "onMarkerPress", MapBuilder.of("registrationName", "onMarkerPress"),
395
- "onMarkerSelect", MapBuilder.of("registrationName", "onMarkerSelect"),
396
- "onMarkerDeselect", MapBuilder.of("registrationName", "onMarkerDeselect"),
397
395
  "onCalloutPress", MapBuilder.of("registrationName", "onCalloutPress")
398
396
  );
399
397
 
@@ -411,7 +409,9 @@ public class MapManager extends ViewGroupManager<MapView> {
411
409
  "onIndoorLevelActivated", MapBuilder.of("registrationName", "onIndoorLevelActivated"),
412
410
  "onIndoorBuildingFocused", MapBuilder.of("registrationName", "onIndoorBuildingFocused"),
413
411
  "onDoublePress", MapBuilder.of("registrationName", "onDoublePress"),
414
- "onMapLoaded", MapBuilder.of("registrationName", "onMapLoaded")
412
+ "onMapLoaded", MapBuilder.of("registrationName", "onMapLoaded"),
413
+ "onMarkerSelect", MapBuilder.of("registrationName", "onMarkerSelect"),
414
+ "onMarkerDeselect", MapBuilder.of("registrationName", "onMarkerDeselect")
415
415
  ));
416
416
 
417
417
  return map;
@@ -276,6 +276,10 @@ public class MapMarker extends MapFeature {
276
276
  }
277
277
  }
278
278
 
279
+ public LatLng getPosition() {
280
+ return position;
281
+ }
282
+
279
283
  public boolean updateCustomForTracking() {
280
284
  if (!tracksViewChangesActive)
281
285
  return false;
@@ -326,7 +326,9 @@ public class MapMarkerManager extends ViewGroupManager<MapMarker> {
326
326
  "onCalloutPress", MapBuilder.of("registrationName", "onCalloutPress"),
327
327
  "onDragStart", MapBuilder.of("registrationName", "onDragStart"),
328
328
  "onDrag", MapBuilder.of("registrationName", "onDrag"),
329
- "onDragEnd", MapBuilder.of("registrationName", "onDragEnd")
329
+ "onDragEnd", MapBuilder.of("registrationName", "onDragEnd"),
330
+ "onSelect", MapBuilder.of("registrationName", "onSelect"),
331
+ "onDeselect", MapBuilder.of("registrationName", "onDeselect")
330
332
  );
331
333
 
332
334
  map.putAll(MapBuilder.of(
@@ -112,6 +112,7 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
112
112
  private boolean initialCameraSet = false;
113
113
  private LatLngBounds cameraLastIdleBounds;
114
114
  private int cameraMoveReason = 0;
115
+ private MapMarker selectedMarker;
115
116
 
116
117
  private static final String[] PERMISSIONS = new String[]{
117
118
  "android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION"};
@@ -296,6 +297,8 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
296
297
  event.putString("id", airMapMarker.getIdentifier());
297
298
  manager.pushEvent(context, airMapMarker, "onPress", event);
298
299
 
300
+ handleMarkerSelection(airMapMarker);
301
+
299
302
  // Return false to open the callout info window and center on the marker
300
303
  // https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap
301
304
  // .OnMarkerClickListener
@@ -351,6 +354,8 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
351
354
  WritableMap event = makeClickEventData(point);
352
355
  event.putString("action", "press");
353
356
  manager.pushEvent(context, view, "onPress", event);
357
+
358
+ handleMarkerSelection(null);
354
359
  }
355
360
  });
356
361
 
@@ -463,6 +468,40 @@ public class MapView extends com.google.android.gms.maps.MapView implements Goog
463
468
  context.addLifecycleEventListener(lifecycleListener);
464
469
  }
465
470
 
471
+ private synchronized void handleMarkerSelection(MapMarker target) {
472
+ if (selectedMarker == target) {
473
+ return;
474
+ }
475
+
476
+ WritableMap event;
477
+
478
+ if (selectedMarker != null) {
479
+ event = makeClickEventData(selectedMarker.getPosition());
480
+ event.putString("action", "marker-deselect");
481
+ event.putString("id", selectedMarker.getIdentifier());
482
+ manager.pushEvent(context, selectedMarker, "onDeselect", event);
483
+
484
+ event = makeClickEventData(selectedMarker.getPosition());
485
+ event.putString("action", "marker-deselect");
486
+ event.putString("id", selectedMarker.getIdentifier());
487
+ manager.pushEvent(context, this, "onMarkerDeselect", event);
488
+ }
489
+
490
+ if (target != null) {
491
+ event = makeClickEventData(target.getPosition());
492
+ event.putString("action", "marker-select");
493
+ event.putString("id", target.getIdentifier());
494
+ manager.pushEvent(context, target, "onSelect", event);
495
+
496
+ event = makeClickEventData(target.getPosition());
497
+ event.putString("action", "marker-select");
498
+ event.putString("id", target.getIdentifier());
499
+ manager.pushEvent(context, this, "onMarkerSelect", event);
500
+ }
501
+
502
+ selectedMarker = target;
503
+ }
504
+
466
505
  private boolean hasPermissions() {
467
506
  return checkSelfPermission(getContext(), PERMISSIONS[0]) == PermissionChecker.PERMISSION_GRANTED ||
468
507
  checkSelfPermission(getContext(), PERMISSIONS[1]) == PermissionChecker.PERMISSION_GRANTED;
@@ -16,6 +16,8 @@
16
16
  @property (nonatomic, strong) NSString *identifier;
17
17
  @property (nonatomic, weak) AIRGoogleMapMarker *fakeMarker;
18
18
  @property (nonatomic, copy) RCTBubblingEventBlock onPress;
19
+ @property (nonatomic, copy) RCTDirectEventBlock onSelect;
20
+ @property (nonatomic, copy) RCTDirectEventBlock onDeselect;
19
21
  @end
20
22
 
21
23
 
@@ -34,6 +34,8 @@
34
34
  @property (nonatomic, copy) RCTBubblingEventBlock onPanDrag;
35
35
  @property (nonatomic, copy) RCTBubblingEventBlock onUserLocationChange;
36
36
  @property (nonatomic, copy) RCTBubblingEventBlock onMarkerPress;
37
+ @property (nonatomic, copy) RCTBubblingEventBlock onMarkerSelect;
38
+ @property (nonatomic, copy) RCTBubblingEventBlock onMarkerDeselect;
37
39
  @property (nonatomic, copy) RCTBubblingEventBlock onChange;
38
40
  @property (nonatomic, copy) RCTBubblingEventBlock onPoiClick;
39
41
  @property (nonatomic, copy) RCTDirectEventBlock onRegionChange;
@@ -80,7 +82,6 @@
80
82
 
81
83
  - (NSDictionary*) getMarkersFramesWithOnlyVisible:(BOOL)onlyVisible;
82
84
  - (instancetype) initWithMapId:(NSString *) mapId;
83
-
84
85
  @end
85
86
 
86
87
  #endif
@@ -354,6 +354,7 @@ id regionAsJSON(MKCoordinateRegion region) {
354
354
 
355
355
  // TODO: not sure why this is necessary
356
356
  [self setSelectedMarker:marker];
357
+
357
358
  return NO;
358
359
  }
359
360
 
@@ -582,6 +583,33 @@ id regionAsJSON(MKCoordinateRegion region) {
582
583
  return self.settings.indoorPicker;
583
584
  }
584
585
 
586
+ -(void)setSelectedMarker:(AIRGMSMarker *)selectedMarker {
587
+ if (selectedMarker == self.selectedMarker) {
588
+ return;
589
+ }
590
+ AIRGMSMarker *airMarker = (AIRGMSMarker *) self.selectedMarker;
591
+ AIRGoogleMapMarker *fakeAirMarker = (AIRGoogleMapMarker *) airMarker.fakeMarker;
592
+ AIRGoogleMapMarker *fakeSelectedMarker = (AIRGoogleMapMarker *) selectedMarker.fakeMarker;
593
+
594
+ if (airMarker && airMarker.onDeselect) {
595
+ airMarker.onDeselect([fakeAirMarker makeEventData:@"marker-deselect"]);
596
+ }
597
+
598
+ if (airMarker && self.onMarkerDeselect) {
599
+ self.onMarkerDeselect([fakeAirMarker makeEventData:@"marker-deselect"]);
600
+ }
601
+
602
+ if (selectedMarker && selectedMarker.onSelect) {
603
+ selectedMarker.onSelect([fakeSelectedMarker makeEventData:@"marker-select"]);
604
+ }
605
+
606
+ if (selectedMarker && self.onMarkerSelect) {
607
+ self.onMarkerSelect([fakeSelectedMarker makeEventData:@"marker-select"]);
608
+ }
609
+
610
+ [super setSelectedMarker:selectedMarker];
611
+ }
612
+
585
613
  + (MKCoordinateRegion) makeGMSCameraPositionFromMap:(GMSMapView *)map andGMSCameraPosition:(GMSCameraPosition *)position {
586
614
  // solution from here: http://stackoverflow.com/a/16587735/1102215
587
615
  GMSVisibleRegion visibleRegion = map.projection.visibleRegion;
@@ -740,16 +768,19 @@ id regionAsJSON(MKCoordinateRegion region) {
740
768
  BOOL isTap = [gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] || [gestureRecognizer isMemberOfClass:[UITapGestureRecognizer class]];
741
769
  if (isTap) {
742
770
  BOOL isTapInsideBubble = NO;
743
- CGPoint tapPoint = CGPointZero;
744
- CGPoint tapPointInBubble = CGPointZero;
745
-
746
- NSArray* touches = [gestureRecognizer valueForKey:@"touches"];
747
- UITouch* oneTouch = [touches firstObject];
748
- NSArray* delayedTouches = [gestureRecognizer valueForKey:@"delayedTouches"];
749
- NSObject* delayedTouch = [delayedTouches firstObject]; //UIGestureDeleayedTouch
750
- UITouch* tapTouch = [delayedTouch valueForKey:@"stateWhenDelayed"];
751
- if (!tapTouch)
752
- tapTouch = oneTouch;
771
+ CGPoint tapPoint = CGPointZero;
772
+ CGPoint tapPointInBubble = CGPointZero;
773
+
774
+ NSArray* touches = [gestureRecognizer valueForKey:@"touches"];
775
+ UITouch* oneTouch = [touches firstObject];
776
+ NSArray* delayedTouches = [gestureRecognizer valueForKey:@"delayedTouches"];
777
+ NSObject* delayedTouch = [delayedTouches firstObject]; //UIGestureDeleayedTouch
778
+ UITouch* tapTouch = [delayedTouch valueForKey:@"stateWhenDelayed"];
779
+
780
+ if (!tapTouch) {
781
+ tapTouch = oneTouch;
782
+ };
783
+
753
784
  tapPoint = [tapTouch locationInView:self];
754
785
  isTapInsideBubble = tapTouch != nil && CGRectContainsPoint(bubbleFrame, tapPoint);
755
786
  if (isTapInsideBubble) {
@@ -101,6 +101,8 @@ RCT_EXPORT_VIEW_PROPERTY(onPanDrag, RCTBubblingEventBlock)
101
101
  RCT_EXPORT_VIEW_PROPERTY(onUserLocationChange, RCTBubblingEventBlock)
102
102
  RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
103
103
  RCT_EXPORT_VIEW_PROPERTY(onMarkerPress, RCTDirectEventBlock)
104
+ RCT_EXPORT_VIEW_PROPERTY(onMarkerSelect, RCTDirectEventBlock)
105
+ RCT_EXPORT_VIEW_PROPERTY(onMarkerDeselect, RCTDirectEventBlock)
104
106
  RCT_EXPORT_VIEW_PROPERTY(onRegionChange, RCTDirectEventBlock)
105
107
  RCT_EXPORT_VIEW_PROPERTY(onRegionChangeComplete, RCTDirectEventBlock)
106
108
  RCT_EXPORT_VIEW_PROPERTY(onPoiClick, RCTDirectEventBlock)
@@ -51,6 +51,8 @@
51
51
  - (void)didBeginDraggingMarker:(AIRGMSMarker *)marker;
52
52
  - (void)didEndDraggingMarker:(AIRGMSMarker *)marker;
53
53
  - (void)didDragMarker:(AIRGMSMarker *)marker;
54
+ - (id)makeEventData;
55
+ - (id)makeEventData:(NSString *)action;
54
56
  @end
55
57
 
56
58
  #endif
@@ -24,7 +24,6 @@ CGRect unionRect(CGRect a, CGRect b) {
24
24
  }
25
25
 
26
26
  @interface AIRGoogleMapMarker ()
27
- - (id)eventFromMarker:(AIRGMSMarker*)marker;
28
27
  @end
29
28
 
30
29
  @implementation AIRGoogleMapMarker {
@@ -60,23 +59,7 @@ CGRect unionRect(CGRect a, CGRect b) {
60
59
  [_iconView setFrame:CGRectMake(0, 0, width, height)];
61
60
  }
62
61
 
63
- - (id)eventFromMarker:(AIRGMSMarker*)marker {
64
62
 
65
- CLLocationCoordinate2D coordinate = marker.position;
66
- CGPoint position = [self.realMarker.map.projection pointForCoordinate:coordinate];
67
-
68
- return @{
69
- @"id": marker.identifier ?: @"unknown",
70
- @"position": @{
71
- @"x": @(position.x),
72
- @"y": @(position.y),
73
- },
74
- @"coordinate": @{
75
- @"latitude": @(coordinate.latitude),
76
- @"longitude": @(coordinate.longitude),
77
- }
78
- };
79
- }
80
63
 
81
64
  - (void)iconViewInsertSubview:(UIView*)subview atIndex:(NSInteger)atIndex {
82
65
  if (!_realMarker.iconView) {
@@ -199,17 +182,17 @@ CGRect unionRect(CGRect a, CGRect b) {
199
182
 
200
183
  - (void)didBeginDraggingMarker:(AIRGMSMarker *)marker {
201
184
  if (!self.onDragStart) return;
202
- self.onDragStart([self eventFromMarker:marker]);
185
+ self.onDragStart([self makeEventData]);
203
186
  }
204
187
 
205
188
  - (void)didEndDraggingMarker:(AIRGMSMarker *)marker {
206
189
  if (!self.onDragEnd) return;
207
- self.onDragEnd([self eventFromMarker:marker]);
190
+ self.onDragEnd([self makeEventData]);
208
191
  }
209
192
 
210
193
  - (void)didDragMarker:(AIRGMSMarker *)marker {
211
194
  if (!self.onDrag) return;
212
- self.onDrag([self eventFromMarker:marker]);
195
+ self.onDrag([self makeEventData]);
213
196
  }
214
197
 
215
198
  - (void)setCoordinate:(CLLocationCoordinate2D)coordinate {
@@ -244,6 +227,22 @@ CGRect unionRect(CGRect a, CGRect b) {
244
227
  return _realMarker.onPress;
245
228
  }
246
229
 
230
+ - (void)setOnSelect:(RCTDirectEventBlock)onSelect {
231
+ _realMarker.onSelect = onSelect;
232
+ }
233
+
234
+ - (RCTDirectEventBlock)onSelect {
235
+ return _realMarker.onSelect;
236
+ }
237
+
238
+ - (void)setOnDeselect:(RCTDirectEventBlock)onDeselect {
239
+ _realMarker.onDeselect = onDeselect;
240
+ }
241
+
242
+ - (RCTDirectEventBlock)onDeselect {
243
+ return _realMarker.onDeselect;
244
+ }
245
+
247
246
  - (void)setOpacity:(double)opacity
248
247
  {
249
248
  _realMarker.opacity = opacity;
@@ -429,6 +428,29 @@ CGRect unionRect(CGRect a, CGRect b) {
429
428
  return _realMarker.tracksInfoWindowChanges;
430
429
  }
431
430
 
431
+
432
+ - (id)makeEventData:(NSString *)action {
433
+ CLLocationCoordinate2D coordinate = self.realMarker.position;
434
+ CGPoint position = [self.realMarker.map.projection pointForCoordinate:coordinate];
435
+
436
+ return @{
437
+ @"id": self.identifier ?: @"unknown",
438
+ @"position": @{
439
+ @"x": @(position.x),
440
+ @"y": @(position.y),
441
+ },
442
+ @"coordinate": @{
443
+ @"latitude": @(coordinate.latitude),
444
+ @"longitude": @(coordinate.longitude),
445
+ },
446
+ @"action": action,
447
+ };
448
+ }
449
+
450
+ - (id)makeEventData {
451
+ return [self makeEventData:@"unknown"];
452
+ }
453
+
432
454
  @end
433
455
 
434
456
  #endif
@@ -52,6 +52,8 @@ RCT_EXPORT_VIEW_PROPERTY(opacity, double)
52
52
  RCT_EXPORT_VIEW_PROPERTY(onDragStart, RCTDirectEventBlock)
53
53
  RCT_EXPORT_VIEW_PROPERTY(onDrag, RCTDirectEventBlock)
54
54
  RCT_EXPORT_VIEW_PROPERTY(onDragEnd, RCTDirectEventBlock)
55
+ RCT_EXPORT_VIEW_PROPERTY(onSelect, RCTDirectEventBlock)
56
+ RCT_EXPORT_VIEW_PROPERTY(onDeselect, RCTDirectEventBlock)
55
57
 
56
58
  RCT_EXPORT_METHOD(showCallout:(nonnull NSNumber *)reactTag)
57
59
  {
@@ -168,8 +168,8 @@ export type MapMarkerProps = ViewProps & {
168
168
  * Callback that is called when the marker becomes selected.
169
169
  * This will be called when the callout for that marker is about to be shown.
170
170
  *
171
- * @platform iOS: Apple Maps only.
172
- * @platform Android: Not supported
171
+ * @platform iOS: Supported.
172
+ * @platform Android: Supported
173
173
  */
174
174
  onSelect?: (event: MarkerSelectEvent) => void;
175
175
  /**
package/lib/MapView.d.ts CHANGED
@@ -4,6 +4,7 @@ import { CalloutPressEvent, ClickEvent, Frame, LatLng, MarkerDeselectEvent, Mark
4
4
  import { Address, BoundingBox, Camera, CameraZoomRange, 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
6
  import { MapViewNativeComponentType } from './MapViewNativeComponent';
7
+ import AnimatedRegion from './AnimatedRegion';
7
8
  export declare const MAP_TYPES: MapTypes;
8
9
  export type MapViewProps = ViewProps & {
9
10
  /**
@@ -242,8 +243,8 @@ export type MapViewProps = ViewProps & {
242
243
  * Callback that is called when a marker on the map becomes deselected.
243
244
  * This will be called when the callout for that marker is about to be hidden.
244
245
  *
245
- * @platform iOS: Apple Maps only
246
- * @platform Android: Not supported
246
+ * @platform iOS: Supported
247
+ * @platform Android: Supported
247
248
  */
248
249
  onMarkerDeselect?: (event: MarkerDeselectEvent) => void;
249
250
  /**
@@ -279,8 +280,8 @@ export type MapViewProps = ViewProps & {
279
280
  * Callback that is called when a marker on the map becomes selected.
280
281
  * This will be called when the callout for that marker is about to be shown.
281
282
  *
282
- * @platform iOS: Apple Maps only.
283
- * @platform Android: Not supported
283
+ * @platform iOS: Supported.
284
+ * @platform Android: Supported
284
285
  */
285
286
  onMarkerSelect?: (event: MarkerSelectEvent) => void;
286
287
  /**
@@ -362,7 +363,7 @@ export type MapViewProps = ViewProps & {
362
363
  * @platform iOS: Supported
363
364
  * @platform Android: Supported
364
365
  */
365
- region?: Region;
366
+ region?: Region | AnimatedRegion;
366
367
  /**
367
368
  * If `false` the user won't be able to adjust the camera’s pitch angle.
368
369
  *
@@ -12,6 +12,7 @@ import { MapPolygon } from './MapPolygon';
12
12
  import { MapPolyline } from './MapPolyline';
13
13
  import { MapUrlTile } from './MapUrlTile';
14
14
  import { MapWMSTile } from './MapWMSTile';
15
+ import { Commands } from './MapViewNativeComponent';
15
16
  export declare const SUPPORTED: ImplementationStatus;
16
17
  export declare const USES_DEFAULT_IMPLEMENTATION: ImplementationStatus;
17
18
  export declare const NOT_SUPPORTED: ImplementationStatus;
@@ -28,7 +29,7 @@ type Providers = {
28
29
  };
29
30
  };
30
31
  export type UIManagerCommand = number;
31
- export type MapManagerCommand = any;
32
+ export type MapManagerCommand = keyof typeof Commands;
32
33
  export type NativeComponent<H = unknown> = HostComponent<H> | ReturnType<typeof createNotSupportedComponent>;
33
34
  type Component = typeof MapCallout | typeof MapCalloutSubview | typeof MapCircle | typeof MapHeatmap | typeof MapLocalTile | typeof MapMarker | typeof MapOverlay | typeof MapPolygon | typeof MapPolyline | typeof MapUrlTile | typeof MapWMSTile;
34
35
  type ComponentName = 'Callout' | 'CalloutSubview' | 'Circle' | 'Heatmap' | 'LocalTile' | 'Marker' | 'Overlay' | 'Polygon' | 'Polyline' | 'UrlTile' | 'WMSTile';
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.11.2",
8
+ "version": "1.12.0",
9
9
  "license": "MIT",
10
10
  "scripts": {
11
11
  "lint": "eslint . --max-warnings 0",