react-native-maps 1.21.0-alpha.11 → 1.21.0-alpha.13

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.
@@ -10,6 +10,7 @@
10
10
  #import <React/RCTBridge.h>
11
11
  #import "AIRGMSPolygon.h"
12
12
  #import "AIRGoogleMapCoordinate.h"
13
+ #import "AIRGoogleMap.h"
13
14
 
14
15
  @interface AIRGoogleMapPolygon : UIView
15
16
 
@@ -26,7 +27,7 @@
26
27
  @property (nonatomic, assign) BOOL geodesic;
27
28
  @property (nonatomic, assign) int zIndex;
28
29
  @property (nonatomic, assign) BOOL tappable;
29
-
30
+ - (void) didInsertInMap:(AIRGoogleMap *) map;
30
31
  @end
31
32
 
32
33
  #endif
@@ -9,6 +9,7 @@
9
9
  #import "AIRGoogleMapPolygon.h"
10
10
  #import "AIRGMSPolygon.h"
11
11
  #import <GoogleMaps/GoogleMaps.h>
12
+ #import "AIRGoogleMap.h"
12
13
 
13
14
  @implementation AIRGoogleMapPolygon
14
15
  {
@@ -41,6 +42,32 @@
41
42
  _polygon.strokeWidth = _strokeWidth;
42
43
  }
43
44
  }
45
+ - (void) didInsertInMap:(AIRGoogleMap *) map
46
+ {
47
+ _polygon = [AIRGMSPolygon new];
48
+
49
+ if (_identifier){
50
+ [_polygon setIdentifier:_identifier];
51
+ }
52
+
53
+ [_polygon setTappable:_tappable];
54
+ if (_strokeColor){
55
+ _polygon.strokeColor = _strokeColor;
56
+ }
57
+ if (_fillColor){
58
+ _polygon.fillColor = _fillColor;
59
+ }
60
+ if (_strokeWidth){
61
+ _polygon.strokeWidth = _strokeWidth;
62
+ }
63
+ if (_coordinates){
64
+ [self setCoordinates:_coordinates];
65
+ }
66
+ if (_holes){
67
+ [self setHoles:_holes];
68
+ }
69
+ [_polygon setMap:map];
70
+ }
44
71
 
45
72
  - (void)setCoordinates:(NSArray<AIRGoogleMapCoordinate *> *)coordinates
46
73
  {
@@ -33,6 +33,8 @@
33
33
 
34
34
  + (AIRGoogleMapCoordinate *)AIRGoogleMapCoordinate:(id)json
35
35
  {
36
+ // empty coordinates
37
+ if ([json isKindOfClass:[NSArray class]] && [json count] == 0) return nil;
36
38
  AIRGoogleMapCoordinate *coord = [AIRGoogleMapCoordinate new];
37
39
  coord.coordinate = [self CLLocationCoordinate2D:json];
38
40
  return coord;
@@ -43,11 +43,8 @@ using namespace facebook::react;
43
43
  - (void)animateToRegion:(NSString *)regionJSON duration:(NSInteger)duration{
44
44
  NSDictionary* regionDic = [RCTConvert dictonaryFromString:regionJSON];
45
45
  MKCoordinateRegion region = [RCTConvert MKCoordinateRegion:regionDic];
46
- [CATransaction begin];
47
- [CATransaction setAnimationDuration:duration/1000];
48
46
  GMSCameraPosition *camera = [AIRGoogleMap makeGMSCameraPositionFromMap:_view andMKCoordinateRegion:region];
49
- [self->_view animateToCameraPosition:camera];
50
- [CATransaction commit];
47
+ [_view animateToCameraPosition:camera];
51
48
  }
52
49
  - (void)setCamera:(NSString *)cameraJSON{
53
50
  NSDictionary* cameraDic = [RCTConvert dictonaryFromString:cameraJSON];
@@ -389,8 +386,11 @@ using namespace facebook::react;
389
386
  } else {
390
387
  [_pendingInsertsSubviews setObject:paperView forKey:[NSNumber numberWithInteger:index]];
391
388
  }
389
+ } else {
390
+ [_view insertReactSubview:childComponentView atIndex:index];
392
391
  }
393
392
  }
393
+
394
394
  - (void) unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
395
395
  {
396
396
  id<RCTComponent> paperView = [childComponentView getPaperViewFromChildComponentView];
@@ -400,8 +400,20 @@ using namespace facebook::react;
400
400
  } else {
401
401
  [_pendingInsertsSubviews removeObjectForKey:[NSNumber numberWithInteger:index]];
402
402
  }
403
+ } else {
404
+ [_view removeReactSubview:childComponentView];
403
405
  }
404
406
  }
407
+ - (void) prepareForRecycle
408
+ {
409
+ [super prepareForRecycle];
410
+ static const auto defaultProps = std::make_shared<const RNMapsGoogleMapViewProps>();
411
+ _props = defaultProps;
412
+ _legacyMapManager = [[AIRGoogleMapManager alloc] init];
413
+ _pendingInsertsSubviews = [NSMutableDictionary new];
414
+ [_view removeFromSuperview];
415
+ _view = nil;
416
+ }
405
417
 
406
418
 
407
419
  - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
@@ -474,20 +486,6 @@ using namespace facebook::react;
474
486
  _view.name = region; \
475
487
  }
476
488
 
477
- #define REMAP_GOOGLEMAPVIEW_CAMERA_PROP(name) \
478
- if (newViewProps.name.center.latitude != oldViewProps.name.center.latitude || \
479
- newViewProps.name.center.longitude != oldViewProps.name.center.longitude || \
480
- newViewProps.name.heading != oldViewProps.name.heading || \
481
- newViewProps.name.pitch != oldViewProps.name.pitch || \
482
- newViewProps.name.zoom != oldViewProps.name.zoom) { \
483
- GMSCameraPosition* camera = [GMSCameraPosition cameraWithLatitude:newViewProps.name.center.latitude \
484
- longitude:newViewProps.name.center.longitude \
485
- zoom:newViewProps.name.zoom \
486
- bearing:newViewProps.name.heading \
487
- viewingAngle:newViewProps.name.pitch]; \
488
- _view.name = camera; \
489
- }
490
-
491
489
 
492
490
  #define REMAP_MAPVIEW_EDGEINSETS_PROP(name) \
493
491
  if (newViewProps.name.top != oldViewProps.name.top || \
@@ -520,7 +518,18 @@ using namespace facebook::react;
520
518
  REMAP_MAPVIEW_REGION_PROP(region)
521
519
  REMAP_MAPVIEW_REGION_PROP(initialRegion)
522
520
 
523
- REMAP_GOOGLEMAPVIEW_CAMERA_PROP(camera)
521
+ if (newViewProps.camera.center.latitude != oldViewProps.camera.center.latitude ||
522
+ newViewProps.camera.center.longitude != oldViewProps.camera.center.longitude ||
523
+ newViewProps.camera.heading != oldViewProps.camera.heading ||
524
+ newViewProps.camera.pitch != oldViewProps.camera.pitch ||
525
+ newViewProps.camera.zoom != oldViewProps.camera.zoom) {
526
+ GMSCameraPosition* camera = [GMSCameraPosition cameraWithLatitude:newViewProps.camera.center.latitude
527
+ longitude:newViewProps.camera.center.longitude
528
+ zoom:newViewProps.camera.zoom
529
+ bearing:newViewProps.camera.heading
530
+ viewingAngle:newViewProps.camera.pitch];
531
+ _view.cameraProp = camera;
532
+ }
524
533
 
525
534
 
526
535
  REMAP_MAPVIEW_EDGEINSETS_PROP(mapPadding)
@@ -536,8 +545,10 @@ using namespace facebook::react;
536
545
  break;
537
546
  case RNMapsGoogleMapViewMapType::Terrain:
538
547
  _view.mapType = kGMSTypeTerrain;
548
+ break;
539
549
  case RNMapsGoogleMapViewMapType::Hybrid:
540
550
  _view.mapType = kGMSTypeHybrid;
551
+ break;
541
552
  default:
542
553
  _view.mapType = kGMSTypeNormal;
543
554
  break;
@@ -75,6 +75,7 @@ extern const NSInteger AIRMapMaxZoomLevel;
75
75
 
76
76
  - (void)cacheViewIfNeeded;
77
77
  - (void)beginLoading;
78
+ - (void)didSetRegion;
78
79
  - (void)finishLoading;
79
80
  - (double)getZoomLevel;
80
81
  - (NSArray *)getMapBoundaries;
@@ -52,6 +52,7 @@ const NSInteger AIRMapMaxZoomLevel = 20;
52
52
  UIView *_legalLabel;
53
53
  BOOL _initialRegionSet;
54
54
  BOOL _initialCameraSet;
55
+ BOOL _initialized;
55
56
 
56
57
  // Array to manually track RN subviews
57
58
  //
@@ -90,6 +91,7 @@ const NSInteger AIRMapMaxZoomLevel = 20;
90
91
  self.maxZoom = AIRMapMaxZoomLevel;
91
92
  self.compassOffset = CGPointMake(0, 0);
92
93
  self.legacyZoomConstraintsEnabled = YES;
94
+ _initialized = YES;
93
95
  }
94
96
  return self;
95
97
  }
@@ -101,6 +103,9 @@ const NSInteger AIRMapMaxZoomLevel = 20;
101
103
  [super addSubview:view];
102
104
  }
103
105
  }
106
+ - (void) didSetRegion {
107
+ _initialRegionSet = YES;
108
+ }
104
109
 
105
110
  #pragma clang diagnostic push
106
111
  #pragma clang diagnostic ignored "-Wobjc-missing-super-calls"
@@ -562,6 +567,9 @@ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordina
562
567
  }
563
568
 
564
569
  - (void)setInitialRegion:(MKCoordinateRegion)initialRegion {
570
+ if (!CLLocationCoordinate2DIsValid(initialRegion.center)) {
571
+ return;
572
+ }
565
573
  if (!_initialRegionSet) {
566
574
  _initialRegionSet = YES;
567
575
  [self setRegion:initialRegion animated:NO];
@@ -951,6 +951,8 @@ static int kDragCenterContext;
951
951
 
952
952
  mapView.pendingCenter = mapView.region.center;
953
953
  mapView.pendingSpan = mapView.region.span;
954
+ // reset original state (checkout setCamera / region animated)
955
+ mapView.ignoreRegionChanges = NO;
954
956
  }
955
957
 
956
958
  - (void)mapViewWillStartRenderingMap:(AIRMap *)mapView
@@ -965,6 +967,7 @@ static int kDragCenterContext;
965
967
  - (void)mapViewDidFinishRenderingMap:(AIRMap *)mapView fullyRendered:(BOOL)fullyRendered
966
968
  {
967
969
  [mapView finishLoading];
970
+ mapView.ignoreRegionChanges = NO;
968
971
  }
969
972
 
970
973
  #pragma mark Private