@lugg/maps 0.2.0-alpha.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.
Files changed (114) hide show
  1. package/LICENSE +20 -0
  2. package/LuggMaps.podspec +23 -0
  3. package/README.md +119 -0
  4. package/android/build.gradle +78 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/luggmaps/LuggMapsGoogleMapView.kt +438 -0
  8. package/android/src/main/java/com/luggmaps/LuggMapsGoogleMapViewManager.kt +144 -0
  9. package/android/src/main/java/com/luggmaps/LuggMapsMarkerView.kt +134 -0
  10. package/android/src/main/java/com/luggmaps/LuggMapsMarkerViewManager.kt +69 -0
  11. package/android/src/main/java/com/luggmaps/LuggMapsPackage.kt +13 -0
  12. package/android/src/main/java/com/luggmaps/LuggMapsPolylineView.kt +79 -0
  13. package/android/src/main/java/com/luggmaps/LuggMapsPolylineViewManager.kt +71 -0
  14. package/android/src/main/java/com/luggmaps/LuggMapsWrapperView.kt +39 -0
  15. package/android/src/main/java/com/luggmaps/LuggMapsWrapperViewManager.kt +25 -0
  16. package/android/src/main/java/com/luggmaps/core/PolylineAnimator.kt +180 -0
  17. package/android/src/main/java/com/luggmaps/events/CameraIdleEvent.kt +21 -0
  18. package/android/src/main/java/com/luggmaps/events/CameraMoveEvent.kt +28 -0
  19. package/app.plugin.js +1 -0
  20. package/ios/LuggMapsAppleMapView.h +16 -0
  21. package/ios/LuggMapsAppleMapView.mm +544 -0
  22. package/ios/LuggMapsGoogleMapView.h +13 -0
  23. package/ios/LuggMapsGoogleMapView.mm +439 -0
  24. package/ios/LuggMapsMarkerView.h +29 -0
  25. package/ios/LuggMapsMarkerView.mm +154 -0
  26. package/ios/LuggMapsPolylineView.h +27 -0
  27. package/ios/LuggMapsPolylineView.mm +116 -0
  28. package/ios/LuggMapsWrapperView.h +9 -0
  29. package/ios/LuggMapsWrapperView.mm +36 -0
  30. package/ios/core/GMSPolylineAnimator.h +11 -0
  31. package/ios/core/GMSPolylineAnimator.m +151 -0
  32. package/ios/core/MKPolylineAnimator.h +12 -0
  33. package/ios/core/MKPolylineAnimator.m +252 -0
  34. package/ios/core/PolylineAnimatorBase.h +22 -0
  35. package/ios/core/PolylineAnimatorBase.m +35 -0
  36. package/ios/events/CameraIdleEvent.h +24 -0
  37. package/ios/events/CameraMoveEvent.h +26 -0
  38. package/ios/extensions/MKMapView+Zoom.h +19 -0
  39. package/ios/extensions/MKMapView+Zoom.m +45 -0
  40. package/lib/module/MapView.js +87 -0
  41. package/lib/module/MapView.js.map +1 -0
  42. package/lib/module/MapView.types.js +4 -0
  43. package/lib/module/MapView.types.js.map +1 -0
  44. package/lib/module/Marker.js +34 -0
  45. package/lib/module/Marker.js.map +1 -0
  46. package/lib/module/Marker.types.js +4 -0
  47. package/lib/module/Marker.types.js.map +1 -0
  48. package/lib/module/Polyline.js +30 -0
  49. package/lib/module/Polyline.js.map +1 -0
  50. package/lib/module/Polyline.types.js +4 -0
  51. package/lib/module/Polyline.types.js.map +1 -0
  52. package/lib/module/fabric/LuggMapsAppleMapViewNativeComponent.ts +73 -0
  53. package/lib/module/fabric/LuggMapsGoogleMapViewNativeComponent.ts +74 -0
  54. package/lib/module/fabric/LuggMapsMarkerViewNativeComponent.ts +25 -0
  55. package/lib/module/fabric/LuggMapsPolylineViewNativeComponent.ts +19 -0
  56. package/lib/module/fabric/LuggMapsWrapperViewNativeComponent.ts +8 -0
  57. package/lib/module/index.js +6 -0
  58. package/lib/module/index.js.map +1 -0
  59. package/lib/module/package.json +1 -0
  60. package/lib/module/types.js +2 -0
  61. package/lib/module/types.js.map +1 -0
  62. package/lib/typescript/package.json +1 -0
  63. package/lib/typescript/plugin/src/index.d.ts +16 -0
  64. package/lib/typescript/plugin/src/index.d.ts.map +1 -0
  65. package/lib/typescript/plugin/src/withMapsAndroid.d.ts +6 -0
  66. package/lib/typescript/plugin/src/withMapsAndroid.d.ts.map +1 -0
  67. package/lib/typescript/plugin/src/withMapsIOS.d.ts +6 -0
  68. package/lib/typescript/plugin/src/withMapsIOS.d.ts.map +1 -0
  69. package/lib/typescript/src/MapView.d.ts +12 -0
  70. package/lib/typescript/src/MapView.d.ts.map +1 -0
  71. package/lib/typescript/src/MapView.types.d.ts +102 -0
  72. package/lib/typescript/src/MapView.types.d.ts.map +1 -0
  73. package/lib/typescript/src/Marker.d.ts +6 -0
  74. package/lib/typescript/src/Marker.d.ts.map +1 -0
  75. package/lib/typescript/src/Marker.types.d.ts +32 -0
  76. package/lib/typescript/src/Marker.types.d.ts.map +1 -0
  77. package/lib/typescript/src/Polyline.d.ts +6 -0
  78. package/lib/typescript/src/Polyline.d.ts.map +1 -0
  79. package/lib/typescript/src/Polyline.types.d.ts +24 -0
  80. package/lib/typescript/src/Polyline.types.d.ts.map +1 -0
  81. package/lib/typescript/src/fabric/LuggMapsAppleMapViewNativeComponent.d.ts +47 -0
  82. package/lib/typescript/src/fabric/LuggMapsAppleMapViewNativeComponent.d.ts.map +1 -0
  83. package/lib/typescript/src/fabric/LuggMapsGoogleMapViewNativeComponent.d.ts +48 -0
  84. package/lib/typescript/src/fabric/LuggMapsGoogleMapViewNativeComponent.d.ts.map +1 -0
  85. package/lib/typescript/src/fabric/LuggMapsMarkerViewNativeComponent.d.ts +20 -0
  86. package/lib/typescript/src/fabric/LuggMapsMarkerViewNativeComponent.d.ts.map +1 -0
  87. package/lib/typescript/src/fabric/LuggMapsPolylineViewNativeComponent.d.ts +15 -0
  88. package/lib/typescript/src/fabric/LuggMapsPolylineViewNativeComponent.d.ts.map +1 -0
  89. package/lib/typescript/src/fabric/LuggMapsWrapperViewNativeComponent.d.ts +6 -0
  90. package/lib/typescript/src/fabric/LuggMapsWrapperViewNativeComponent.d.ts.map +1 -0
  91. package/lib/typescript/src/index.d.ts +8 -0
  92. package/lib/typescript/src/index.d.ts.map +1 -0
  93. package/lib/typescript/src/types.d.ts +28 -0
  94. package/lib/typescript/src/types.d.ts.map +1 -0
  95. package/package.json +200 -0
  96. package/plugin/build/index.d.ts +15 -0
  97. package/plugin/build/index.js +13 -0
  98. package/plugin/build/withMapsAndroid.d.ts +5 -0
  99. package/plugin/build/withMapsAndroid.js +15 -0
  100. package/plugin/build/withMapsIOS.d.ts +5 -0
  101. package/plugin/build/withMapsIOS.js +27 -0
  102. package/src/MapView.tsx +111 -0
  103. package/src/MapView.types.ts +110 -0
  104. package/src/Marker.tsx +31 -0
  105. package/src/Marker.types.ts +32 -0
  106. package/src/Polyline.tsx +32 -0
  107. package/src/Polyline.types.ts +24 -0
  108. package/src/fabric/LuggMapsAppleMapViewNativeComponent.ts +73 -0
  109. package/src/fabric/LuggMapsGoogleMapViewNativeComponent.ts +74 -0
  110. package/src/fabric/LuggMapsMarkerViewNativeComponent.ts +25 -0
  111. package/src/fabric/LuggMapsPolylineViewNativeComponent.ts +19 -0
  112. package/src/fabric/LuggMapsWrapperViewNativeComponent.ts +8 -0
  113. package/src/index.ts +13 -0
  114. package/src/types.ts +30 -0
@@ -0,0 +1,439 @@
1
+ #import "LuggMapsGoogleMapView.h"
2
+ #import "LuggMapsMarkerView.h"
3
+ #import "LuggMapsPolylineView.h"
4
+ #import "core/GMSPolylineAnimator.h"
5
+ #import "core/PolylineAnimatorBase.h"
6
+ #import "events/CameraIdleEvent.h"
7
+ #import "events/CameraMoveEvent.h"
8
+
9
+ #import <react/renderer/components/RNMapsSpec/ComponentDescriptors.h>
10
+ #import <react/renderer/components/RNMapsSpec/EventEmitters.h>
11
+ #import <react/renderer/components/RNMapsSpec/Props.h>
12
+ #import <react/renderer/components/RNMapsSpec/RCTComponentViewHelpers.h>
13
+
14
+ #import "RCTFabricComponentsPlugins.h"
15
+
16
+ using namespace facebook::react;
17
+ using namespace luggmaps::events;
18
+
19
+ #import "LuggMapsWrapperView.h"
20
+
21
+ static NSString *const kDemoMapId = @"DEMO_MAP_ID";
22
+
23
+ @interface LuggMapsGoogleMapView () <
24
+ RCTLuggMapsGoogleMapViewViewProtocol, GMSMapViewDelegate,
25
+ LuggMapsMarkerViewDelegate, LuggMapsPolylineViewDelegate>
26
+ @end
27
+
28
+ @implementation LuggMapsGoogleMapView {
29
+ GMSMapView *_mapView;
30
+ LuggMapsWrapperView *_mapWrapperView;
31
+ BOOL _isMapReady;
32
+ BOOL _isDragging;
33
+ NSString *_mapId;
34
+ NSMutableArray<LuggMapsMarkerView *> *_pendingMarkerViews;
35
+ NSMutableArray<LuggMapsPolylineView *> *_pendingPolylineViews;
36
+ NSMapTable<LuggMapsPolylineView *, GMSPolylineAnimator *> *_polylineAnimators;
37
+ }
38
+
39
+ + (ComponentDescriptorProvider)componentDescriptorProvider {
40
+ return concreteComponentDescriptorProvider<
41
+ LuggMapsGoogleMapViewComponentDescriptor>();
42
+ }
43
+
44
+ - (instancetype)initWithFrame:(CGRect)frame {
45
+ if (self = [super initWithFrame:frame]) {
46
+ static const auto defaultProps =
47
+ std::make_shared<const LuggMapsGoogleMapViewProps>();
48
+ _props = defaultProps;
49
+
50
+ _isMapReady = NO;
51
+ _mapId = kDemoMapId;
52
+ _pendingMarkerViews = [NSMutableArray array];
53
+ _pendingPolylineViews = [NSMutableArray array];
54
+ _polylineAnimators = [NSMapTable weakToStrongObjectsMapTable];
55
+ }
56
+
57
+ return self;
58
+ }
59
+
60
+ #pragma mark - View Lifecycle
61
+
62
+ - (void)mountChildComponentView:
63
+ (UIView<RCTComponentViewProtocol> *)childComponentView
64
+ index:(NSInteger)index {
65
+ [super mountChildComponentView:childComponentView index:index];
66
+
67
+ if ([childComponentView isKindOfClass:[LuggMapsWrapperView class]]) {
68
+ _mapWrapperView = (LuggMapsWrapperView *)childComponentView;
69
+ } else if ([childComponentView isKindOfClass:[LuggMapsMarkerView class]]) {
70
+ LuggMapsMarkerView *markerView = (LuggMapsMarkerView *)childComponentView;
71
+ markerView.delegate = self;
72
+ [self syncMarkerView:markerView caller:@"mountChildComponentView"];
73
+ } else if ([childComponentView isKindOfClass:[LuggMapsPolylineView class]]) {
74
+ LuggMapsPolylineView *polylineView =
75
+ (LuggMapsPolylineView *)childComponentView;
76
+ polylineView.delegate = self;
77
+ [self syncPolylineView:polylineView];
78
+ }
79
+ }
80
+
81
+ - (void)unmountChildComponentView:
82
+ (UIView<RCTComponentViewProtocol> *)childComponentView
83
+ index:(NSInteger)index {
84
+ if ([childComponentView isKindOfClass:[LuggMapsMarkerView class]]) {
85
+ LuggMapsMarkerView *markerView = (LuggMapsMarkerView *)childComponentView;
86
+ GMSAdvancedMarker *marker = (GMSAdvancedMarker *)markerView.marker;
87
+ if (marker) {
88
+ marker.iconView = nil;
89
+ marker.map = nil;
90
+ markerView.marker = nil;
91
+ }
92
+ } else if ([childComponentView isKindOfClass:[LuggMapsPolylineView class]]) {
93
+ LuggMapsPolylineView *polylineView =
94
+ (LuggMapsPolylineView *)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;
124
+ }
125
+
126
+ #pragma mark - Map Initialization
127
+
128
+ - (void)initializeMap {
129
+ if (_mapView || !_mapWrapperView) {
130
+ return;
131
+ }
132
+
133
+ const auto &viewProps =
134
+ *std::static_pointer_cast<LuggMapsGoogleMapViewProps const>(_props);
135
+
136
+ GMSMapID *gmsMapId;
137
+ if ([_mapId isEqualToString:kDemoMapId] || _mapId.length == 0) {
138
+ gmsMapId = [GMSMapID demoMapID];
139
+ } else {
140
+ gmsMapId = [GMSMapID mapIDWithIdentifier:_mapId];
141
+ }
142
+
143
+ GMSCameraPosition *camera = [GMSCameraPosition
144
+ cameraWithLatitude:viewProps.initialCoordinate.latitude
145
+ longitude:viewProps.initialCoordinate.longitude
146
+ zoom:viewProps.initialZoom];
147
+
148
+ GMSMapViewOptions *options = [[GMSMapViewOptions alloc] init];
149
+ options.frame = _mapWrapperView.bounds;
150
+ options.camera = camera;
151
+ options.mapID = gmsMapId;
152
+
153
+ _mapView = [[GMSMapView alloc] initWithOptions:options];
154
+ _mapView.autoresizingMask =
155
+ UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
156
+ _mapView.delegate = self;
157
+ _mapView.paddingAdjustmentBehavior =
158
+ 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
+
164
+ [_mapWrapperView addSubview:_mapView];
165
+
166
+ _isMapReady = YES;
167
+ [self processPendingMarkers];
168
+ [self processPendingPolylines];
169
+ }
170
+
171
+ - (GMSMapView *)mapView {
172
+ return _mapView;
173
+ }
174
+
175
+ #pragma mark - GMSMapViewDelegate
176
+
177
+ - (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture {
178
+ _isDragging = gesture;
179
+ }
180
+
181
+ - (void)mapView:(GMSMapView *)mapView
182
+ didChangeCameraPosition:(GMSCameraPosition *)position {
183
+ if (_eventEmitter) {
184
+ auto emitter =
185
+ std::static_pointer_cast<LuggMapsGoogleMapViewEventEmitter const>(
186
+ _eventEmitter);
187
+ CameraMoveEvent{position.target.latitude, position.target.longitude,
188
+ position.zoom, _isDragging}
189
+ .emit(emitter);
190
+ }
191
+ }
192
+
193
+ - (void)mapView:(GMSMapView *)mapView
194
+ idleAtCameraPosition:(GMSCameraPosition *)position {
195
+ _isDragging = NO;
196
+ if (_eventEmitter) {
197
+ auto emitter =
198
+ std::static_pointer_cast<LuggMapsGoogleMapViewEventEmitter const>(
199
+ _eventEmitter);
200
+ CameraIdleEvent{position.target.latitude, position.target.longitude,
201
+ position.zoom}
202
+ .emit(emitter);
203
+ }
204
+ }
205
+
206
+ #pragma mark - PolylineViewDelegate
207
+
208
+ - (void)polylineViewDidUpdate:(LuggMapsPolylineView *)polylineView {
209
+ [self syncPolylineView:polylineView];
210
+ }
211
+
212
+ #pragma mark - MarkerViewDelegate
213
+
214
+ - (void)markerViewDidLayout:(LuggMapsMarkerView *)markerView {
215
+ [self syncMarkerView:markerView caller:@"markerViewDidLayout"];
216
+ }
217
+
218
+ - (void)markerViewDidUpdate:(LuggMapsMarkerView *)markerView {
219
+ [self syncMarkerView:markerView caller:@"markerViewDidUpdate"];
220
+ }
221
+
222
+ #pragma mark - Marker Management
223
+
224
+ - (void)syncMarkerView:(LuggMapsMarkerView *)markerView
225
+ caller:(NSString *)caller {
226
+ if (!_mapView) {
227
+ if (![_pendingMarkerViews containsObject:markerView]) {
228
+ [_pendingMarkerViews addObject:markerView];
229
+ }
230
+ return;
231
+ }
232
+
233
+ if (!markerView.marker) {
234
+ [self addMarkerViewToMap:markerView];
235
+ return;
236
+ }
237
+
238
+ GMSAdvancedMarker *marker = (GMSAdvancedMarker *)markerView.marker;
239
+ marker.position = markerView.coordinate;
240
+ marker.title = markerView.title;
241
+ marker.snippet = markerView.markerDescription;
242
+ marker.groundAnchor = markerView.anchor;
243
+
244
+ if (markerView.hasCustomView) {
245
+ UIView *iconView = markerView.iconView;
246
+ [iconView removeFromSuperview];
247
+ marker.iconView = iconView;
248
+ } else {
249
+ marker.iconView = nil;
250
+ }
251
+ }
252
+
253
+ - (void)processPendingMarkers {
254
+ if (!_mapView) {
255
+ return;
256
+ }
257
+
258
+ for (LuggMapsMarkerView *markerView in _pendingMarkerViews) {
259
+ [self addMarkerViewToMap:markerView];
260
+ }
261
+ [_pendingMarkerViews removeAllObjects];
262
+ }
263
+
264
+ - (void)addMarkerViewToMap:(LuggMapsMarkerView *)markerView {
265
+ if (!_mapView) {
266
+ RCTLogWarn(@"LuggMaps: addMarkerViewToMap called without a map");
267
+ return;
268
+ }
269
+
270
+ UIView *iconView = markerView.iconView;
271
+ [iconView removeFromSuperview];
272
+
273
+ GMSAdvancedMarker *marker = [[GMSAdvancedMarker alloc] init];
274
+ marker.position = markerView.coordinate;
275
+ marker.title = markerView.title;
276
+ marker.snippet = markerView.markerDescription;
277
+ marker.collisionBehavior = GMSCollisionBehaviorRequired;
278
+
279
+ if (markerView.hasCustomView) {
280
+ marker.iconView = iconView;
281
+ }
282
+
283
+ marker.groundAnchor = markerView.anchor;
284
+ marker.map = _mapView;
285
+
286
+ markerView.marker = marker;
287
+ }
288
+
289
+ #pragma mark - Polyline Management
290
+
291
+ - (void)syncPolylineView:(LuggMapsPolylineView *)polylineView {
292
+ if (!_mapView) {
293
+ if (![_pendingPolylineViews containsObject:polylineView]) {
294
+ [_pendingPolylineViews addObject:polylineView];
295
+ }
296
+ return;
297
+ }
298
+
299
+ if (!polylineView.polyline) {
300
+ [self addPolylineViewToMap:polylineView];
301
+ return;
302
+ }
303
+
304
+ GMSPolyline *polyline = (GMSPolyline *)polylineView.polyline;
305
+ polyline.strokeWidth = polylineView.strokeWidth;
306
+
307
+ GMSPolylineAnimator *animator =
308
+ [_polylineAnimators objectForKey:polylineView];
309
+ if (animator) {
310
+ animator.coordinates = polylineView.coordinates;
311
+ animator.strokeColors = polylineView.strokeColors;
312
+ animator.animated = polylineView.animated;
313
+ [animator update];
314
+ }
315
+ }
316
+
317
+ - (void)processPendingPolylines {
318
+ if (!_mapView) {
319
+ return;
320
+ }
321
+
322
+ for (LuggMapsPolylineView *polylineView in _pendingPolylineViews) {
323
+ [self addPolylineViewToMap:polylineView];
324
+ }
325
+ [_pendingPolylineViews removeAllObjects];
326
+ }
327
+
328
+ - (void)addPolylineViewToMap:(LuggMapsPolylineView *)polylineView {
329
+ if (!_mapView) {
330
+ return;
331
+ }
332
+
333
+ GMSPolyline *polyline = [GMSPolyline polylineWithPath:[GMSMutablePath path]];
334
+ polyline.strokeWidth = polylineView.strokeWidth;
335
+ polyline.map = _mapView;
336
+ polylineView.polyline = polyline;
337
+
338
+ GMSPolylineAnimator *animator = [[GMSPolylineAnimator alloc] init];
339
+ animator.polyline = polyline;
340
+ animator.coordinates = polylineView.coordinates;
341
+ animator.strokeColors = polylineView.strokeColors;
342
+ animator.animated = polylineView.animated;
343
+ [animator update];
344
+
345
+ [_polylineAnimators setObject:animator forKey:polylineView];
346
+ }
347
+
348
+ #pragma mark - Property Setters
349
+
350
+ - (void)updateProps:(Props::Shared const &)props
351
+ oldProps:(Props::Shared const &)oldProps {
352
+ const auto &newViewProps =
353
+ *std::static_pointer_cast<LuggMapsGoogleMapViewProps const>(props);
354
+
355
+ if (_mapView == nil) {
356
+ NSString *newMapId =
357
+ [NSString stringWithUTF8String:newViewProps.mapId.c_str()];
358
+ if (newMapId.length > 0) {
359
+ _mapId = newMapId;
360
+ }
361
+ }
362
+
363
+ if (_mapView) {
364
+ _mapView.settings.zoomGestures = newViewProps.zoomEnabled;
365
+ _mapView.settings.scrollGestures = newViewProps.scrollEnabled;
366
+ _mapView.settings.rotateGestures = newViewProps.rotateEnabled;
367
+ _mapView.settings.tiltGestures = newViewProps.pitchEnabled;
368
+ _mapView.padding = UIEdgeInsetsMake(
369
+ newViewProps.padding.top, newViewProps.padding.left,
370
+ newViewProps.padding.bottom, newViewProps.padding.right);
371
+ }
372
+
373
+ [super updateProps:props oldProps:oldProps];
374
+ }
375
+
376
+ #pragma mark - Commands
377
+
378
+ - (void)moveCamera:(double)latitude
379
+ longitude:(double)longitude
380
+ zoom:(double)zoom
381
+ duration:(double)duration {
382
+ if (!_mapView) {
383
+ return;
384
+ }
385
+
386
+ GMSCameraPosition *camera =
387
+ [GMSCameraPosition cameraWithLatitude:latitude
388
+ longitude:longitude
389
+ zoom:(float)zoom];
390
+ if (duration < 0) {
391
+ [_mapView animateToCameraPosition:camera];
392
+ } else if (duration > 0) {
393
+ [CATransaction begin];
394
+ [CATransaction setAnimationDuration:duration / 1000.0];
395
+ [_mapView animateToCameraPosition:camera];
396
+ [CATransaction commit];
397
+ } else {
398
+ [_mapView setCamera:camera];
399
+ }
400
+ }
401
+
402
+ - (void)fitCoordinates:(NSArray *)coordinates
403
+ padding:(double)padding
404
+ duration:(double)duration {
405
+ if (!_mapView || coordinates.count == 0) {
406
+ return;
407
+ }
408
+
409
+ GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] init];
410
+ for (NSDictionary *coord in coordinates) {
411
+ double lat = [coord[@"latitude"] doubleValue];
412
+ double lng = [coord[@"longitude"] doubleValue];
413
+ bounds = [bounds includingCoordinate:CLLocationCoordinate2DMake(lat, lng)];
414
+ }
415
+
416
+ GMSCameraUpdate *cameraUpdate = [GMSCameraUpdate fitBounds:bounds
417
+ withPadding:padding];
418
+
419
+ if (duration < 0) {
420
+ [_mapView animateWithCameraUpdate:cameraUpdate];
421
+ } else if (duration > 0) {
422
+ [CATransaction begin];
423
+ [CATransaction setAnimationDuration:duration / 1000.0];
424
+ [_mapView animateWithCameraUpdate:cameraUpdate];
425
+ [CATransaction commit];
426
+ } else {
427
+ [_mapView moveCamera:cameraUpdate];
428
+ }
429
+ }
430
+
431
+ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
432
+ RCTLuggMapsGoogleMapViewHandleCommand(self, commandName, args);
433
+ }
434
+
435
+ Class<RCTComponentViewProtocol> LuggMapsGoogleMapViewCls(void) {
436
+ return LuggMapsGoogleMapView.class;
437
+ }
438
+
439
+ @end
@@ -0,0 +1,29 @@
1
+ #import <CoreLocation/CoreLocation.h>
2
+ #import <React/RCTViewComponentView.h>
3
+ #import <UIKit/UIKit.h>
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ @class LuggMapsMarkerView;
8
+
9
+ @protocol LuggMapsMarkerViewDelegate <NSObject>
10
+ @optional
11
+ - (void)markerViewDidLayout:(LuggMapsMarkerView *)markerView;
12
+ - (void)markerViewDidUpdate:(LuggMapsMarkerView *)markerView;
13
+ @end
14
+
15
+ @interface LuggMapsMarkerView : RCTViewComponentView
16
+
17
+ @property(nonatomic, readonly) CLLocationCoordinate2D coordinate;
18
+ @property(nonatomic, readonly, nullable) NSString *title;
19
+ @property(nonatomic, readonly, nullable) NSString *markerDescription;
20
+ @property(nonatomic, readonly) CGPoint anchor;
21
+ @property(nonatomic, readonly) BOOL hasCustomView;
22
+ @property(nonatomic, readonly) BOOL didLayout;
23
+ @property(nonatomic, readonly) UIView *iconView;
24
+ @property(nonatomic, weak, nullable) id<LuggMapsMarkerViewDelegate> delegate;
25
+ @property(nonatomic, strong, nullable) NSObject *marker;
26
+
27
+ @end
28
+
29
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,154 @@
1
+ #import "LuggMapsMarkerView.h"
2
+
3
+ #import <react/renderer/components/RNMapsSpec/ComponentDescriptors.h>
4
+ #import <react/renderer/components/RNMapsSpec/EventEmitters.h>
5
+ #import <react/renderer/components/RNMapsSpec/Props.h>
6
+ #import <react/renderer/components/RNMapsSpec/RCTComponentViewHelpers.h>
7
+
8
+ #import "RCTFabricComponentsPlugins.h"
9
+
10
+ using namespace facebook::react;
11
+
12
+ @interface LuggMapsMarkerView () <RCTLuggMapsMarkerViewViewProtocol>
13
+ @end
14
+
15
+ @implementation LuggMapsMarkerView {
16
+ CLLocationCoordinate2D _coordinate;
17
+ NSString *_title;
18
+ NSString *_markerDescription;
19
+ CGPoint _anchor;
20
+ BOOL _didLayout;
21
+ UIView *_iconView;
22
+ }
23
+
24
+ + (ComponentDescriptorProvider)componentDescriptorProvider {
25
+ return concreteComponentDescriptorProvider<
26
+ LuggMapsMarkerViewComponentDescriptor>();
27
+ }
28
+
29
+ - (instancetype)initWithFrame:(CGRect)frame {
30
+ if (self = [super initWithFrame:frame]) {
31
+ static const auto defaultProps =
32
+ std::make_shared<const LuggMapsMarkerViewProps>();
33
+ _props = defaultProps;
34
+
35
+ _coordinate = CLLocationCoordinate2DMake(0, 0);
36
+ _anchor = CGPointMake(0.5, 1.0);
37
+ _didLayout = NO;
38
+
39
+ _iconView = [[UIView alloc] init];
40
+ _iconView.backgroundColor = [UIColor clearColor];
41
+
42
+ self.backgroundColor = [UIColor clearColor];
43
+ self.hidden = YES;
44
+ }
45
+
46
+ return self;
47
+ }
48
+
49
+ - (void)updateProps:(Props::Shared const &)props
50
+ oldProps:(Props::Shared const &)oldProps {
51
+ [super updateProps:props oldProps:oldProps];
52
+ const auto &newViewProps =
53
+ *std::static_pointer_cast<LuggMapsMarkerViewProps const>(props);
54
+
55
+ _coordinate = CLLocationCoordinate2DMake(newViewProps.coordinate.latitude,
56
+ newViewProps.coordinate.longitude);
57
+ _title = [NSString stringWithUTF8String:newViewProps.title.c_str()];
58
+ _markerDescription =
59
+ [NSString stringWithUTF8String:newViewProps.description.c_str()];
60
+ _anchor = CGPointMake(newViewProps.anchor.x, newViewProps.anchor.y);
61
+ }
62
+
63
+ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask {
64
+ [super finalizeUpdates:updateMask];
65
+
66
+ if (updateMask & RNComponentViewUpdateMaskProps) {
67
+ if ([self.delegate respondsToSelector:@selector(markerViewDidUpdate:)]) {
68
+ [self.delegate markerViewDidUpdate:self];
69
+ }
70
+ }
71
+ }
72
+
73
+ - (void)mountChildComponentView:
74
+ (UIView<RCTComponentViewProtocol> *)childComponentView
75
+ index:(NSInteger)index {
76
+ [_iconView insertSubview:childComponentView atIndex:index];
77
+ _didLayout = NO;
78
+ }
79
+
80
+ - (void)unmountChildComponentView:
81
+ (UIView<RCTComponentViewProtocol> *)childComponentView
82
+ index:(NSInteger)index {
83
+ [childComponentView removeFromSuperview];
84
+ _didLayout = NO;
85
+ }
86
+
87
+ - (void)layoutSubviews {
88
+ [super layoutSubviews];
89
+
90
+ if (self.hasCustomView) {
91
+ CGFloat width = 0;
92
+ CGFloat height = 0;
93
+
94
+ for (UIView *subview in _iconView.subviews) {
95
+ CGFloat fw = subview.frame.origin.x + subview.frame.size.width;
96
+ CGFloat fh = subview.frame.origin.y + subview.frame.size.height;
97
+ width = MAX(fw, width);
98
+ height = MAX(fh, height);
99
+ }
100
+
101
+ if (width > 0 && height > 0) {
102
+ _iconView.frame = CGRectMake(0, 0, width, height);
103
+ }
104
+ }
105
+
106
+ if (!_didLayout) {
107
+ _didLayout = YES;
108
+ [self.delegate markerViewDidLayout:self];
109
+ }
110
+ }
111
+
112
+ - (CLLocationCoordinate2D)coordinate {
113
+ return _coordinate;
114
+ }
115
+
116
+ - (NSString *)title {
117
+ return _title;
118
+ }
119
+
120
+ - (NSString *)markerDescription {
121
+ return _markerDescription;
122
+ }
123
+
124
+ - (CGPoint)anchor {
125
+ return _anchor;
126
+ }
127
+
128
+ - (BOOL)hasCustomView {
129
+ return _iconView.subviews.count > 0;
130
+ }
131
+
132
+ - (BOOL)didLayout {
133
+ return _didLayout;
134
+ }
135
+
136
+ - (UIView *)iconView {
137
+ return _iconView;
138
+ }
139
+
140
+ - (void)prepareForRecycle {
141
+ [super prepareForRecycle];
142
+ _didLayout = NO;
143
+ self.marker = nil;
144
+ self.delegate = nil;
145
+ for (UIView *subview in _iconView.subviews) {
146
+ [subview removeFromSuperview];
147
+ }
148
+ }
149
+
150
+ Class<RCTComponentViewProtocol> LuggMapsMarkerViewCls(void) {
151
+ return LuggMapsMarkerView.class;
152
+ }
153
+
154
+ @end
@@ -0,0 +1,27 @@
1
+ #import <CoreLocation/CoreLocation.h>
2
+ #import <React/RCTViewComponentView.h>
3
+ #import <UIKit/UIKit.h>
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ @class LuggMapsPolylineView;
8
+
9
+ @protocol LuggMapsPolylineViewDelegate <NSObject>
10
+ @optional
11
+ - (void)polylineViewDidUpdate:(LuggMapsPolylineView *)polylineView;
12
+ @end
13
+
14
+ @interface LuggMapsPolylineView : RCTViewComponentView
15
+
16
+ @property(nonatomic, readonly) NSArray<CLLocation *> *coordinates;
17
+ @property(nonatomic, readonly) NSArray<UIColor *> *strokeColors;
18
+ @property(nonatomic, readonly) BOOL animated;
19
+ @property(nonatomic, readonly) CGFloat strokeWidth;
20
+ @property(nonatomic, weak, nullable) id<LuggMapsPolylineViewDelegate> delegate;
21
+ @property(nonatomic, strong, nullable) NSObject *polyline;
22
+ @property(nonatomic, weak, nullable) NSObject *renderer;
23
+ @property(nonatomic, strong, nullable) NSArray *cachedSpans;
24
+
25
+ @end
26
+
27
+ NS_ASSUME_NONNULL_END