@lugg/maps 0.2.0-alpha.21 → 0.2.0-alpha.23

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.
Files changed (45) hide show
  1. package/README.md +5 -0
  2. package/android/src/main/java/com/luggmaps/LuggMapView.kt +201 -0
  3. package/android/src/main/java/com/luggmaps/{LuggGoogleMapViewManager.kt → LuggMapViewManager.kt} +39 -29
  4. package/android/src/main/java/com/luggmaps/LuggPackage.kt +1 -4
  5. package/android/src/main/java/com/luggmaps/{LuggGoogleMapView.kt → core/GoogleMapProvider.kt} +174 -189
  6. package/android/src/main/java/com/luggmaps/core/MapProviderDelegate.kt +51 -0
  7. package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +28 -24
  8. package/ios/LuggMapView.h +9 -0
  9. package/ios/LuggMapView.mm +303 -0
  10. package/ios/core/AppleMapProvider.h +15 -0
  11. package/ios/{LuggAppleMapView.mm → core/AppleMapProvider.mm} +317 -410
  12. package/ios/core/GMSPolylineAnimator.m +16 -4
  13. package/ios/core/GoogleMapProvider.h +13 -0
  14. package/ios/{LuggGoogleMapView.mm → core/GoogleMapProvider.mm} +179 -218
  15. package/ios/core/MapProviderDelegate.h +68 -0
  16. package/lib/module/MapView.js +9 -12
  17. package/lib/module/MapView.js.map +1 -1
  18. package/lib/module/MapView.web.js +4 -1
  19. package/lib/module/MapView.web.js.map +1 -1
  20. package/lib/module/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +4 -1
  21. package/lib/typescript/src/MapView.d.ts +0 -1
  22. package/lib/typescript/src/MapView.d.ts.map +1 -1
  23. package/lib/typescript/src/MapView.types.d.ts +6 -1
  24. package/lib/typescript/src/MapView.types.d.ts.map +1 -1
  25. package/lib/typescript/src/MapView.web.d.ts.map +1 -1
  26. package/lib/typescript/src/fabric/{LuggGoogleMapViewNativeComponent.d.ts → LuggMapViewNativeComponent.d.ts} +4 -2
  27. package/lib/typescript/src/fabric/LuggMapViewNativeComponent.d.ts.map +1 -0
  28. package/lib/typescript/src/index.d.ts +1 -1
  29. package/lib/typescript/src/index.d.ts.map +1 -1
  30. package/lib/typescript/src/types.d.ts +4 -0
  31. package/lib/typescript/src/types.d.ts.map +1 -1
  32. package/package.json +5 -3
  33. package/src/MapView.tsx +11 -21
  34. package/src/MapView.types.ts +6 -1
  35. package/src/MapView.web.tsx +10 -0
  36. package/src/fabric/{LuggGoogleMapViewNativeComponent.ts → LuggMapViewNativeComponent.ts} +4 -1
  37. package/src/index.ts +1 -0
  38. package/src/types.ts +5 -0
  39. package/ios/LuggAppleMapView.h +0 -16
  40. package/ios/LuggGoogleMapView.h +0 -13
  41. package/lib/module/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
  42. package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts +0 -54
  43. package/lib/typescript/src/fabric/LuggAppleMapViewNativeComponent.d.ts.map +0 -1
  44. package/lib/typescript/src/fabric/LuggGoogleMapViewNativeComponent.d.ts.map +0 -1
  45. package/src/fabric/LuggAppleMapViewNativeComponent.ts +0 -83
@@ -1,6 +1,8 @@
1
1
  #import "GMSPolylineAnimator.h"
2
2
  #import <QuartzCore/QuartzCore.h>
3
3
 
4
+ static const NSUInteger kMaxAnimationSpans = 16;
5
+
4
6
  @interface GMSDisplayLinkProxy : NSObject
5
7
  @property(nonatomic, weak) id target;
6
8
  @property(nonatomic, assign) SEL selector;
@@ -245,12 +247,22 @@
245
247
  }
246
248
 
247
249
  NSUInteger pathCount = path.count;
248
- for (NSUInteger i = 0; i < pathCount - 1; i++) {
249
- CGFloat segMidDist = tailDist + visibleLength * ((CGFloat)i + 0.5) / (CGFloat)(pathCount - 1);
250
- CGFloat gradientPos = (segMidDist - tailDist) / visibleLength;
250
+ NSUInteger segmentCount = pathCount - 1;
251
+
252
+ if (self.strokeColors.count <= 1) {
253
+ _polyline.path = path;
254
+ _polyline.strokeColor = self.strokeColors.firstObject ?: [UIColor blackColor];
255
+ return;
256
+ }
257
+
258
+ NSUInteger spanCount = MIN(segmentCount, kMaxAnimationSpans);
259
+ double segmentsPerSpan = (double)segmentCount / spanCount;
260
+
261
+ for (NSUInteger i = 0; i < spanCount; i++) {
262
+ CGFloat gradientPos = ((CGFloat)i + 0.5) / spanCount;
251
263
  UIColor *color = [self colorAtGradientPosition:gradientPos];
252
264
  GMSStrokeStyle *style = [GMSStrokeStyle solidColor:color];
253
- [spans addObject:[GMSStyleSpan spanWithStyle:style]];
265
+ [spans addObject:[GMSStyleSpan spanWithStyle:style segments:segmentsPerSpan]];
254
266
  }
255
267
 
256
268
  _polyline.path = path;
@@ -0,0 +1,13 @@
1
+ #import "MapProviderDelegate.h"
2
+ #import <GoogleMaps/GoogleMaps.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @interface GoogleMapProvider : NSObject <MapProvider, GMSMapViewDelegate>
7
+
8
+ @property(nonatomic, copy, nullable) NSString *mapId;
9
+ @property(nonatomic, readonly, nullable) GMSMapView *mapView;
10
+
11
+ @end
12
+
13
+ NS_ASSUME_NONNULL_END
@@ -1,137 +1,53 @@
1
- #import "LuggGoogleMapView.h"
2
- #import "LuggMarkerView.h"
3
- #import "LuggPolylineView.h"
4
- #import "core/GMSPolylineAnimator.h"
5
- #import "core/PolylineAnimatorBase.h"
6
- #import "events/CameraIdleEvent.h"
7
- #import "events/CameraMoveEvent.h"
8
- #import "events/ReadyEvent.h"
9
-
10
- #import <react/renderer/components/RNMapsSpec/ComponentDescriptors.h>
11
- #import <react/renderer/components/RNMapsSpec/EventEmitters.h>
12
- #import <react/renderer/components/RNMapsSpec/Props.h>
13
- #import <react/renderer/components/RNMapsSpec/RCTComponentViewHelpers.h>
14
-
15
- #import "RCTFabricComponentsPlugins.h"
16
-
17
- using namespace facebook::react;
18
- using namespace luggmaps::events;
19
-
20
- #import "LuggMapWrapperView.h"
1
+ #import "GoogleMapProvider.h"
2
+ #import "../LuggMarkerView.h"
3
+ #import "../LuggPolylineView.h"
4
+ #import "GMSPolylineAnimator.h"
5
+ #import "PolylineAnimatorBase.h"
21
6
 
22
7
  static NSString *const kDemoMapId = @"DEMO_MAP_ID";
23
8
 
24
- @interface LuggGoogleMapView () <RCTLuggGoogleMapViewViewProtocol,
25
- GMSMapViewDelegate, LuggMarkerViewDelegate,
9
+ @interface GoogleMapProvider () <LuggMarkerViewDelegate,
26
10
  LuggPolylineViewDelegate>
27
11
  @end
28
12
 
29
- @implementation LuggGoogleMapView {
13
+ @implementation GoogleMapProvider {
30
14
  GMSMapView *_mapView;
31
- LuggMapWrapperView *_mapWrapperView;
32
15
  BOOL _isMapReady;
33
16
  BOOL _isDragging;
34
- NSString *_mapId;
17
+ NSString *_theme;
35
18
  NSMutableArray<LuggMarkerView *> *_pendingMarkerViews;
36
19
  NSMutableArray<LuggPolylineView *> *_pendingPolylineViews;
37
20
  NSMapTable<LuggPolylineView *, GMSPolylineAnimator *> *_polylineAnimators;
38
21
  }
39
22
 
40
- + (ComponentDescriptorProvider)componentDescriptorProvider {
41
- return concreteComponentDescriptorProvider<
42
- LuggGoogleMapViewComponentDescriptor>();
43
- }
44
-
45
- - (instancetype)initWithFrame:(CGRect)frame {
46
- if (self = [super initWithFrame:frame]) {
47
- static const auto defaultProps =
48
- std::make_shared<const LuggGoogleMapViewProps>();
49
- _props = defaultProps;
23
+ @synthesize delegate = _delegate;
50
24
 
25
+ - (instancetype)init {
26
+ if (self = [super init]) {
51
27
  _isMapReady = NO;
52
28
  _mapId = kDemoMapId;
53
29
  _pendingMarkerViews = [NSMutableArray array];
54
30
  _pendingPolylineViews = [NSMutableArray array];
55
31
  _polylineAnimators = [NSMapTable weakToStrongObjectsMapTable];
56
32
  }
57
-
58
33
  return self;
59
34
  }
60
35
 
61
- #pragma mark - View Lifecycle
62
-
63
- - (void)mountChildComponentView:
64
- (UIView<RCTComponentViewProtocol> *)childComponentView
65
- index:(NSInteger)index {
66
- [super mountChildComponentView:childComponentView index:index];
67
-
68
- if ([childComponentView isKindOfClass:[LuggMapWrapperView class]]) {
69
- _mapWrapperView = (LuggMapWrapperView *)childComponentView;
70
- } else if ([childComponentView isKindOfClass:[LuggMarkerView class]]) {
71
- LuggMarkerView *markerView = (LuggMarkerView *)childComponentView;
72
- markerView.delegate = self;
73
- [self syncMarkerView:markerView caller:@"mountChildComponentView"];
74
- } else if ([childComponentView isKindOfClass:[LuggPolylineView class]]) {
75
- LuggPolylineView *polylineView = (LuggPolylineView *)childComponentView;
76
- polylineView.delegate = self;
77
- [self syncPolylineView:polylineView];
78
- }
36
+ - (BOOL)isMapReady {
37
+ return _isMapReady;
79
38
  }
80
39
 
81
- - (void)unmountChildComponentView:
82
- (UIView<RCTComponentViewProtocol> *)childComponentView
83
- index:(NSInteger)index {
84
- if ([childComponentView isKindOfClass:[LuggMarkerView class]]) {
85
- LuggMarkerView *markerView = (LuggMarkerView *)childComponentView;
86
- GMSAdvancedMarker *marker = (GMSAdvancedMarker *)markerView.marker;
87
- if (marker) {
88
- marker.iconView = nil;
89
- marker.map = nil;
90
- markerView.marker = nil;
91
- }
92
- [markerView resetIconViewTransform];
93
- } else if ([childComponentView isKindOfClass:[LuggPolylineView class]]) {
94
- LuggPolylineView *polylineView = (LuggPolylineView *)childComponentView;
95
- [_polylineAnimators removeObjectForKey:polylineView];
96
- GMSPolyline *polyline = (GMSPolyline *)polylineView.polyline;
97
- if (polyline) {
98
- polyline.map = nil;
99
- polylineView.polyline = nil;
100
- }
101
- }
102
-
103
- [super unmountChildComponentView:childComponentView index:index];
104
- }
105
-
106
- - (void)didMoveToWindow {
107
- [super didMoveToWindow];
108
- if (self.window && !_mapView && _mapWrapperView) {
109
- [self initializeMap];
110
- }
111
- }
112
-
113
- - (void)prepareForRecycle {
114
- [super prepareForRecycle];
115
-
116
- [_pendingMarkerViews removeAllObjects];
117
- [_pendingPolylineViews removeAllObjects];
118
- [_polylineAnimators removeAllObjects];
119
- [_mapView clear];
120
- [_mapView removeFromSuperview];
121
- _mapView = nil;
122
- _mapWrapperView = nil;
123
- _isMapReady = NO;
40
+ - (GMSMapView *)mapView {
41
+ return _mapView;
124
42
  }
125
43
 
126
- #pragma mark - Map Initialization
44
+ #pragma mark - MapProvider
127
45
 
128
- - (void)initializeMap {
129
- if (_mapView || !_mapWrapperView) {
46
+ - (void)initializeMapInView:(UIView *)wrapperView
47
+ initialCoordinate:(CLLocationCoordinate2D)coordinate
48
+ initialZoom:(double)zoom {
49
+ if (_mapView)
130
50
  return;
131
- }
132
-
133
- const auto &viewProps =
134
- *std::static_pointer_cast<LuggGoogleMapViewProps const>(_props);
135
51
 
136
52
  GMSMapID *gmsMapId;
137
53
  if ([_mapId isEqualToString:kDemoMapId] || _mapId.length == 0) {
@@ -140,13 +56,13 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
140
56
  gmsMapId = [GMSMapID mapIDWithIdentifier:_mapId];
141
57
  }
142
58
 
143
- GMSCameraPosition *camera = [GMSCameraPosition
144
- cameraWithLatitude:viewProps.initialCoordinate.latitude
145
- longitude:viewProps.initialCoordinate.longitude
146
- zoom:viewProps.initialZoom];
59
+ GMSCameraPosition *camera =
60
+ [GMSCameraPosition cameraWithLatitude:coordinate.latitude
61
+ longitude:coordinate.longitude
62
+ zoom:zoom];
147
63
 
148
64
  GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init];
149
- options.frame = _mapWrapperView.bounds;
65
+ options.frame = wrapperView.bounds;
150
66
  options.camera = camera;
151
67
  options.mapID = gmsMapId;
152
68
 
@@ -156,34 +72,84 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
156
72
  _mapView.delegate = self;
157
73
  _mapView.paddingAdjustmentBehavior =
158
74
  kGMSMapViewPaddingAdjustmentBehaviorNever;
159
- _mapView.settings.zoomGestures = viewProps.zoomEnabled;
160
- _mapView.settings.scrollGestures = viewProps.scrollEnabled;
161
- _mapView.settings.rotateGestures = viewProps.rotateEnabled;
162
- _mapView.settings.tiltGestures = viewProps.pitchEnabled;
163
- _mapView.myLocationEnabled = viewProps.userLocationEnabled;
164
-
165
- if (viewProps.minZoom > 0) {
166
- [_mapView setMinZoom:(float)viewProps.minZoom maxZoom:_mapView.maxZoom];
167
- }
168
- if (viewProps.maxZoom > 0) {
169
- [_mapView setMinZoom:_mapView.minZoom maxZoom:(float)viewProps.maxZoom];
170
- }
171
75
 
172
- _mapView.padding =
173
- UIEdgeInsetsMake(viewProps.padding.top, viewProps.padding.left,
174
- viewProps.padding.bottom, viewProps.padding.right);
76
+ [wrapperView addSubview:_mapView];
175
77
 
176
- [_mapWrapperView addSubview:_mapView];
78
+ [self applyTheme];
177
79
 
178
80
  _isMapReady = YES;
179
81
  [self processPendingMarkers];
180
82
  [self processPendingPolylines];
181
83
 
182
- ReadyEvent::emit<LuggGoogleMapViewEventEmitter>(_eventEmitter);
84
+ [_delegate mapProviderDidReady];
183
85
  }
184
86
 
185
- - (GMSMapView *)mapView {
186
- return _mapView;
87
+ - (void)destroy {
88
+ [_pendingMarkerViews removeAllObjects];
89
+ [_pendingPolylineViews removeAllObjects];
90
+ [_polylineAnimators removeAllObjects];
91
+ [_mapView clear];
92
+ [_mapView removeFromSuperview];
93
+ _mapView = nil;
94
+ _isMapReady = NO;
95
+ }
96
+
97
+ #pragma mark - Props
98
+
99
+ - (void)setZoomEnabled:(BOOL)enabled {
100
+ _mapView.settings.zoomGestures = enabled;
101
+ }
102
+
103
+ - (void)setScrollEnabled:(BOOL)enabled {
104
+ _mapView.settings.scrollGestures = enabled;
105
+ }
106
+
107
+ - (void)setRotateEnabled:(BOOL)enabled {
108
+ _mapView.settings.rotateGestures = enabled;
109
+ }
110
+
111
+ - (void)setPitchEnabled:(BOOL)enabled {
112
+ _mapView.settings.tiltGestures = enabled;
113
+ }
114
+
115
+ - (void)setUserLocationEnabled:(BOOL)enabled {
116
+ _mapView.myLocationEnabled = enabled;
117
+ }
118
+
119
+ - (void)setTheme:(NSString *)theme {
120
+ _theme = [theme copy];
121
+ [self applyTheme];
122
+ }
123
+
124
+ - (void)applyTheme {
125
+ if (!_mapView)
126
+ return;
127
+
128
+ if ([_theme isEqualToString:@"dark"]) {
129
+ _mapView.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
130
+ } else if ([_theme isEqualToString:@"light"]) {
131
+ _mapView.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
132
+ } else {
133
+ _mapView.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
134
+ }
135
+ }
136
+
137
+ - (void)setMinZoom:(double)minZoom {
138
+ if (!_mapView)
139
+ return;
140
+ float min = minZoom > 0 ? (float)minZoom : _mapView.minZoom;
141
+ [_mapView setMinZoom:min maxZoom:_mapView.maxZoom];
142
+ }
143
+
144
+ - (void)setMaxZoom:(double)maxZoom {
145
+ if (!_mapView)
146
+ return;
147
+ float max = maxZoom > 0 ? (float)maxZoom : _mapView.maxZoom;
148
+ [_mapView setMinZoom:_mapView.minZoom maxZoom:max];
149
+ }
150
+
151
+ - (void)setPadding:(UIEdgeInsets)padding oldPadding:(UIEdgeInsets)oldPadding {
152
+ _mapView.padding = padding;
187
153
  }
188
154
 
189
155
  #pragma mark - GMSMapViewDelegate
@@ -199,9 +165,10 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
199
165
 
200
166
  - (void)mapView:(GMSMapView *)mapView
201
167
  didChangeCameraPosition:(GMSCameraPosition *)position {
202
- CameraMoveEvent{position.target.latitude, position.target.longitude,
203
- position.zoom, _isDragging}
204
- .emit<LuggGoogleMapViewEventEmitter>(_eventEmitter);
168
+ [_delegate mapProviderDidMoveCamera:position.target.latitude
169
+ longitude:position.target.longitude
170
+ zoom:position.zoom
171
+ gesture:_isDragging];
205
172
  }
206
173
 
207
174
  - (void)mapView:(GMSMapView *)mapView
@@ -213,59 +180,46 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
213
180
  [animator resume];
214
181
  }
215
182
  }
216
- CameraIdleEvent{position.target.latitude, position.target.longitude,
217
- position.zoom, static_cast<bool>(wasDragging)}
218
- .emit<LuggGoogleMapViewEventEmitter>(_eventEmitter);
219
- }
220
-
221
- #pragma mark - PolylineViewDelegate
222
-
223
- - (void)polylineViewDidUpdate:(LuggPolylineView *)polylineView {
224
- [self syncPolylineView:polylineView];
183
+ [_delegate mapProviderDidIdleCamera:position.target.latitude
184
+ longitude:position.target.longitude
185
+ zoom:position.zoom
186
+ gesture:wasDragging];
225
187
  }
226
188
 
227
189
  #pragma mark - MarkerViewDelegate
228
190
 
229
191
  - (void)markerViewDidLayout:(LuggMarkerView *)markerView {
230
- [self syncMarkerView:markerView caller:@"markerViewDidLayout"];
192
+ [self syncMarkerView:markerView];
231
193
  }
232
194
 
233
195
  - (void)markerViewDidUpdate:(LuggMarkerView *)markerView {
234
- [self syncMarkerView:markerView caller:@"markerViewDidUpdate"];
196
+ [self syncMarkerView:markerView];
197
+ }
198
+
199
+ #pragma mark - PolylineViewDelegate
200
+
201
+ - (void)polylineViewDidUpdate:(LuggPolylineView *)polylineView {
202
+ [self syncPolylineView:polylineView];
235
203
  }
236
204
 
237
205
  #pragma mark - Marker Management
238
206
 
239
- - (void)applyMarkerStyle:(LuggMarkerView *)markerView
240
- marker:(GMSAdvancedMarker *)marker {
241
- if (markerView.hasCustomView) {
242
- if (markerView.rasterize) {
243
- marker.iconView = nil;
244
- marker.icon = [markerView createScaledIconImage];
245
- marker.rotation = markerView.rotate;
246
- } else {
247
- UIView *iconView = markerView.iconView;
248
- if (marker.iconView != iconView) {
249
- [iconView removeFromSuperview];
250
- marker.iconView = iconView;
251
- }
252
- CGFloat scale = markerView.scale;
253
- CGFloat radians = markerView.rotate * M_PI / 180.0;
254
- iconView.transform =
255
- CGAffineTransformConcat(CGAffineTransformMakeScale(scale, scale),
256
- CGAffineTransformMakeRotation(radians));
257
- marker.rotation = 0;
258
- }
259
- marker.groundAnchor = markerView.anchor;
260
- } else {
207
+ - (void)addMarkerView:(LuggMarkerView *)markerView {
208
+ markerView.delegate = self;
209
+ [self syncMarkerView:markerView];
210
+ }
211
+
212
+ - (void)removeMarkerView:(LuggMarkerView *)markerView {
213
+ GMSAdvancedMarker *marker = (GMSAdvancedMarker *)markerView.marker;
214
+ if (marker) {
261
215
  marker.iconView = nil;
262
- marker.icon = nil;
263
- marker.rotation = markerView.rotate;
264
- marker.groundAnchor = CGPointMake(0.5, 1);
216
+ marker.map = nil;
217
+ markerView.marker = nil;
265
218
  }
219
+ [markerView resetIconViewTransform];
266
220
  }
267
221
 
268
- - (void)syncMarkerView:(LuggMarkerView *)markerView caller:(NSString *)caller {
222
+ - (void)syncMarkerView:(LuggMarkerView *)markerView {
269
223
  if (!_mapView) {
270
224
  if (![_pendingMarkerViews containsObject:markerView]) {
271
225
  [_pendingMarkerViews addObject:markerView];
@@ -287,9 +241,8 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
287
241
  }
288
242
 
289
243
  - (void)processPendingMarkers {
290
- if (!_mapView) {
244
+ if (!_mapView)
291
245
  return;
292
- }
293
246
 
294
247
  for (LuggMarkerView *markerView in _pendingMarkerViews) {
295
248
  [self addMarkerViewToMap:markerView];
@@ -298,10 +251,8 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
298
251
  }
299
252
 
300
253
  - (void)addMarkerViewToMap:(LuggMarkerView *)markerView {
301
- if (!_mapView) {
302
- RCTLogWarn(@"Lugg: addMarkerViewToMap called without a map");
254
+ if (!_mapView)
303
255
  return;
304
- }
305
256
 
306
257
  GMSAdvancedMarker *marker = [[GMSAdvancedMarker alloc] init];
307
258
  marker.position = markerView.coordinate;
@@ -315,8 +266,51 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
315
266
  markerView.marker = marker;
316
267
  }
317
268
 
269
+ - (void)applyMarkerStyle:(LuggMarkerView *)markerView
270
+ marker:(GMSAdvancedMarker *)marker {
271
+ if (markerView.hasCustomView) {
272
+ if (markerView.rasterize) {
273
+ marker.iconView = nil;
274
+ marker.icon = [markerView createScaledIconImage];
275
+ marker.rotation = markerView.rotate;
276
+ } else {
277
+ UIView *iconView = markerView.iconView;
278
+ if (marker.iconView != iconView) {
279
+ [iconView removeFromSuperview];
280
+ marker.iconView = iconView;
281
+ }
282
+ CGFloat scale = markerView.scale;
283
+ CGFloat radians = markerView.rotate * M_PI / 180.0;
284
+ iconView.transform =
285
+ CGAffineTransformConcat(CGAffineTransformMakeScale(scale, scale),
286
+ CGAffineTransformMakeRotation(radians));
287
+ marker.rotation = 0;
288
+ }
289
+ marker.groundAnchor = markerView.anchor;
290
+ } else {
291
+ marker.iconView = nil;
292
+ marker.icon = nil;
293
+ marker.rotation = markerView.rotate;
294
+ marker.groundAnchor = CGPointMake(0.5, 1);
295
+ }
296
+ }
297
+
318
298
  #pragma mark - Polyline Management
319
299
 
300
+ - (void)addPolylineView:(LuggPolylineView *)polylineView {
301
+ polylineView.delegate = self;
302
+ [self syncPolylineView:polylineView];
303
+ }
304
+
305
+ - (void)removePolylineView:(LuggPolylineView *)polylineView {
306
+ [_polylineAnimators removeObjectForKey:polylineView];
307
+ GMSPolyline *polyline = (GMSPolyline *)polylineView.polyline;
308
+ if (polyline) {
309
+ polyline.map = nil;
310
+ polylineView.polyline = nil;
311
+ }
312
+ }
313
+
320
314
  - (void)syncPolylineView:(LuggPolylineView *)polylineView {
321
315
  if (!_mapView) {
322
316
  if (![_pendingPolylineViews containsObject:polylineView]) {
@@ -346,9 +340,8 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
346
340
  }
347
341
 
348
342
  - (void)processPendingPolylines {
349
- if (!_mapView) {
343
+ if (!_mapView)
350
344
  return;
351
- }
352
345
 
353
346
  for (LuggPolylineView *polylineView in _pendingPolylineViews) {
354
347
  [self addPolylineViewToMap:polylineView];
@@ -357,9 +350,8 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
357
350
  }
358
351
 
359
352
  - (void)addPolylineViewToMap:(LuggPolylineView *)polylineView {
360
- if (!_mapView) {
353
+ if (!_mapView)
361
354
  return;
362
- }
363
355
 
364
356
  GMSPolyline *polyline = [GMSPolyline polylineWithPath:[GMSMutablePath path]];
365
357
  polyline.strokeWidth = polylineView.strokeWidth;
@@ -378,39 +370,18 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
378
370
  [_polylineAnimators setObject:animator forKey:polylineView];
379
371
  }
380
372
 
381
- #pragma mark - Property Setters
382
-
383
- - (void)updateProps:(Props::Shared const &)props
384
- oldProps:(Props::Shared const &)oldProps {
385
- const auto &newViewProps =
386
- *std::static_pointer_cast<LuggGoogleMapViewProps const>(props);
373
+ #pragma mark - Lifecycle
387
374
 
388
- if (_mapView == nil) {
389
- NSString *newMapId =
390
- [NSString stringWithUTF8String:newViewProps.mapId.c_str()];
391
- if (newMapId.length > 0) {
392
- _mapId = newMapId;
393
- }
375
+ - (void)pauseAnimations {
376
+ for (GMSPolylineAnimator *animator in _polylineAnimators.objectEnumerator) {
377
+ [animator pause];
394
378
  }
379
+ }
395
380
 
396
- if (_mapView) {
397
- _mapView.settings.zoomGestures = newViewProps.zoomEnabled;
398
- _mapView.settings.scrollGestures = newViewProps.scrollEnabled;
399
- _mapView.settings.rotateGestures = newViewProps.rotateEnabled;
400
- _mapView.settings.tiltGestures = newViewProps.pitchEnabled;
401
- _mapView.myLocationEnabled = newViewProps.userLocationEnabled;
402
- _mapView.padding = UIEdgeInsetsMake(
403
- newViewProps.padding.top, newViewProps.padding.left,
404
- newViewProps.padding.bottom, newViewProps.padding.right);
405
-
406
- float minZoom = newViewProps.minZoom > 0 ? (float)newViewProps.minZoom
407
- : _mapView.minZoom;
408
- float maxZoom = newViewProps.maxZoom > 0 ? (float)newViewProps.maxZoom
409
- : _mapView.maxZoom;
410
- [_mapView setMinZoom:minZoom maxZoom:maxZoom];
381
+ - (void)resumeAnimations {
382
+ for (GMSPolylineAnimator *animator in _polylineAnimators.objectEnumerator) {
383
+ [animator resume];
411
384
  }
412
-
413
- [super updateProps:props oldProps:oldProps];
414
385
  }
415
386
 
416
387
  #pragma mark - Commands
@@ -419,9 +390,8 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
419
390
  longitude:(double)longitude
420
391
  zoom:(double)zoom
421
392
  duration:(double)duration {
422
- if (!_mapView) {
393
+ if (!_mapView)
423
394
  return;
424
- }
425
395
 
426
396
  float targetZoom = zoom > 0 ? (float)zoom : _mapView.camera.zoom;
427
397
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude
@@ -445,9 +415,8 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
445
415
  paddingBottom:(double)paddingBottom
446
416
  paddingRight:(double)paddingRight
447
417
  duration:(double)duration {
448
- if (!_mapView || coordinates.count == 0) {
418
+ if (!_mapView || coordinates.count == 0)
449
419
  return;
450
- }
451
420
 
452
421
  GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] init];
453
422
  for (NSDictionary *coord in coordinates) {
@@ -473,12 +442,4 @@ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
473
442
  }
474
443
  }
475
444
 
476
- - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
477
- RCTLuggGoogleMapViewHandleCommand(self, commandName, args);
478
- }
479
-
480
- Class<RCTComponentViewProtocol> LuggGoogleMapViewCls(void) {
481
- return LuggGoogleMapView.class;
482
- }
483
-
484
445
  @end
@@ -0,0 +1,68 @@
1
+ #import <CoreLocation/CoreLocation.h>
2
+ #import <UIKit/UIKit.h>
3
+
4
+ NS_ASSUME_NONNULL_BEGIN
5
+
6
+ @class LuggMarkerView;
7
+ @class LuggPolylineView;
8
+
9
+ @protocol MapProviderDelegate <NSObject>
10
+ - (void)mapProviderDidReady;
11
+ - (void)mapProviderDidMoveCamera:(double)latitude
12
+ longitude:(double)longitude
13
+ zoom:(double)zoom
14
+ gesture:(BOOL)gesture;
15
+ - (void)mapProviderDidIdleCamera:(double)latitude
16
+ longitude:(double)longitude
17
+ zoom:(double)zoom
18
+ gesture:(BOOL)gesture;
19
+ @end
20
+
21
+ @protocol MapProvider <NSObject>
22
+
23
+ @property(nonatomic, weak, nullable) id<MapProviderDelegate> delegate;
24
+ @property(nonatomic, readonly) BOOL isMapReady;
25
+
26
+ - (void)initializeMapInView:(UIView *)wrapperView
27
+ initialCoordinate:(CLLocationCoordinate2D)coordinate
28
+ initialZoom:(double)zoom;
29
+ - (void)destroy;
30
+
31
+ // Props
32
+ - (void)setZoomEnabled:(BOOL)enabled;
33
+ - (void)setScrollEnabled:(BOOL)enabled;
34
+ - (void)setRotateEnabled:(BOOL)enabled;
35
+ - (void)setPitchEnabled:(BOOL)enabled;
36
+ - (void)setUserLocationEnabled:(BOOL)enabled;
37
+ - (void)setTheme:(NSString *)theme;
38
+ - (void)setMinZoom:(double)minZoom;
39
+ - (void)setMaxZoom:(double)maxZoom;
40
+ - (void)setPadding:(UIEdgeInsets)padding oldPadding:(UIEdgeInsets)oldPadding;
41
+
42
+ // Children
43
+ - (void)addMarkerView:(LuggMarkerView *)markerView;
44
+ - (void)removeMarkerView:(LuggMarkerView *)markerView;
45
+ - (void)syncMarkerView:(LuggMarkerView *)markerView;
46
+ - (void)addPolylineView:(LuggPolylineView *)polylineView;
47
+ - (void)removePolylineView:(LuggPolylineView *)polylineView;
48
+ - (void)syncPolylineView:(LuggPolylineView *)polylineView;
49
+
50
+ // Lifecycle
51
+ - (void)pauseAnimations;
52
+ - (void)resumeAnimations;
53
+
54
+ // Commands
55
+ - (void)moveCamera:(double)latitude
56
+ longitude:(double)longitude
57
+ zoom:(double)zoom
58
+ duration:(double)duration;
59
+ - (void)fitCoordinates:(NSArray *)coordinates
60
+ paddingTop:(double)paddingTop
61
+ paddingLeft:(double)paddingLeft
62
+ paddingBottom:(double)paddingBottom
63
+ paddingRight:(double)paddingRight
64
+ duration:(double)duration;
65
+
66
+ @end
67
+
68
+ NS_ASSUME_NONNULL_END