react-native-maps 1.21.0-alpha.6 → 1.21.0-alpha.8

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 (38) hide show
  1. package/ios/AirGoogleMaps/AIRGoogleMap.h +6 -1
  2. package/ios/AirGoogleMaps/AIRGoogleMap.m +90 -7
  3. package/ios/AirGoogleMaps/AIRGoogleMapCircle.h +0 -1
  4. package/ios/AirGoogleMaps/AIRGoogleMapCoordinate.h +13 -0
  5. package/ios/AirGoogleMaps/AIRGoogleMapCoordinate.m +10 -0
  6. package/ios/AirGoogleMaps/AIRGoogleMapManager.h +7 -0
  7. package/ios/AirGoogleMaps/AIRGoogleMapManager.m +13 -91
  8. package/ios/AirGoogleMaps/AIRGoogleMapMarkerManager.m +0 -1
  9. package/ios/AirGoogleMaps/AIRGoogleMapOverlay.h +0 -1
  10. package/ios/AirGoogleMaps/AIRGoogleMapPolygon.h +3 -3
  11. package/ios/AirGoogleMaps/AIRGoogleMapPolygon.m +2 -2
  12. package/ios/AirGoogleMaps/AIRGoogleMapPolygonManager.m +3 -3
  13. package/ios/AirGoogleMaps/AIRGoogleMapPolyline.h +3 -2
  14. package/ios/AirGoogleMaps/AIRGoogleMapPolyline.m +2 -3
  15. package/ios/AirGoogleMaps/AIRGoogleMapPolylineManager.m +2 -2
  16. package/ios/AirGoogleMaps/RCTConvert+GMSMapViewType.h +3 -0
  17. package/ios/AirGoogleMaps/RCTConvert+GMSMapViewType.m +16 -0
  18. package/ios/AirGoogleMaps/RNMapsGoogleMapView.h +26 -0
  19. package/ios/AirGoogleMaps/RNMapsGoogleMapView.mm +531 -0
  20. package/ios/AirGoogleMaps/RNMapsGoogleMapViewManager.mm +25 -0
  21. package/ios/AirMaps/AIRMap.h +4 -4
  22. package/ios/AirMaps/AIRMap.m +14 -2
  23. package/ios/AirMaps/AIRMapManager.m +6 -21
  24. package/ios/AirMaps/RCTConvert+AirMap.h +4 -0
  25. package/ios/AirMaps/RCTConvert+AirMap.m +2 -0
  26. package/ios/AirMaps/RNMapsAirModule.h +3 -0
  27. package/ios/AirMaps/RNMapsMapView.h +3 -0
  28. package/ios/AirMaps/RNMapsMapView.mm +12 -25
  29. package/lib/MapOverlay.d.ts +1 -1
  30. package/lib/MapView.d.ts +2 -2
  31. package/lib/MapView.js +20 -18
  32. package/lib/{FabricMapView.d.ts → createFabricMap.d.ts} +7 -6
  33. package/lib/createFabricMap.js +175 -0
  34. package/lib/specs/NativeComponentGoogleMapView.d.ts +713 -0
  35. package/lib/specs/NativeComponentGoogleMapView.js +21 -0
  36. package/lib/specs/NativeComponentMapView.d.ts +4 -11
  37. package/package.json +7 -7
  38. package/lib/FabricMapView.js +0 -175
@@ -0,0 +1,531 @@
1
+ //
2
+ // RNMapsGoogleMapView.mm
3
+ //
4
+ //
5
+ // Created by Salah Ghanim on 23.11.24.
6
+ // Copyright © 2024 react-native-maps. All rights reserved.
7
+ //
8
+ #ifdef HAVE_GOOGLE_MAPS
9
+
10
+ #import "RNMapsGoogleMapView.h"
11
+ #import "AirGoogleMap.h"
12
+ #import "AIRMapMarker.h"
13
+ #import "AirGoogleMapManager.h"
14
+
15
+ #import <react/renderer/components/RNMapsSpecs/ComponentDescriptors.h>
16
+ #import <react/renderer/components/RNMapsSpecs/EventEmitters.h>
17
+ #import <react/renderer/components/RNMapsSpecs/Props.h>
18
+ #import <react/renderer/components/RNMapsSpecs/RCTComponentViewHelpers.h>
19
+
20
+ #import "RCTFabricComponentsPlugins.h"
21
+ #import <React/RCTConversions.h>
22
+ #import "RCTConvert+GMSMapViewType.h"
23
+ #import "RCTConvert+AirMap.h"
24
+
25
+
26
+ using namespace facebook::react;
27
+
28
+ @interface RNMapsGoogleMapView () <RCTRNMapsGoogleMapViewViewProtocol>
29
+ @end
30
+
31
+ @implementation RNMapsGoogleMapView {
32
+ AIRGoogleMap *_view;
33
+ AIRGoogleMapManager* _legacyMapManager;
34
+ }
35
+
36
+
37
+ - (AIRGoogleMap *) mapView {
38
+ return _view;
39
+ }
40
+
41
+ #pragma mark - JS Commands
42
+ - (void)animateToRegion:(NSString *)regionJSON duration:(NSInteger)duration{
43
+ NSDictionary* regionDic = [RCTConvert dictonaryFromString:regionJSON];
44
+ MKCoordinateRegion region = [RCTConvert MKCoordinateRegion:regionDic];
45
+ [CATransaction begin];
46
+ [CATransaction setAnimationDuration:duration/1000];
47
+ GMSCameraPosition *camera = [AIRGoogleMap makeGMSCameraPositionFromMap:_view andMKCoordinateRegion:region];
48
+ [self->_view animateToCameraPosition:camera];
49
+ [CATransaction commit];
50
+ }
51
+ - (void)setCamera:(NSString *)cameraJSON{
52
+ NSDictionary* cameraDic = [RCTConvert dictonaryFromString:cameraJSON];
53
+ GMSCameraPosition* camera = [RCTConvert GMSCameraPositionWithDefaults:cameraDic existingCamera:[_view camera]];
54
+ [_view setCamera:camera];
55
+ }
56
+
57
+ - (void)animateCamera:(NSString *)cameraJSON duration:(NSInteger)duration{
58
+ NSDictionary* cameraDic = [RCTConvert dictonaryFromString:cameraJSON];
59
+ GMSCameraPosition* camera = [RCTConvert GMSCameraPositionWithDefaults:cameraDic existingCamera:[_view camera]];
60
+ [_view animateToCameraPosition:camera];
61
+ }
62
+
63
+ - (void)fitToElements:(NSString *)edgePaddingJSON animated:(BOOL)animated {
64
+ NSDictionary* edgePadding = [RCTConvert dictonaryFromString:edgePaddingJSON];
65
+ [_view fitToElementsWithEdgePadding:edgePadding animated:animated];
66
+ }
67
+
68
+ - (void)fitToSuppliedMarkers:(NSString *)markersJSON edgePaddingJSON:(NSString *)edgePaddingJSON animated:(BOOL)animated {
69
+ NSArray* markers = [RCTConvert arrayFromString:markersJSON];
70
+ NSDictionary* edgePadding = [RCTConvert dictonaryFromString:edgePaddingJSON];
71
+ [_view fitToSuppliedMarkers:markers withEdgePadding:edgePadding animated:animated];
72
+
73
+ }
74
+ - (void)fitToCoordinates:(NSString *)coordinatesJSON edgePaddingJSON:(NSString *)edgePaddingJSON animated:(BOOL)animated {
75
+ NSArray* coordinatesArr = [RCTConvert arrayFromString:coordinatesJSON];
76
+ NSMutableArray<AIRGoogleMapCoordinate*>* coordinatesArray = [NSMutableArray new];
77
+ for (id json : coordinatesArr){
78
+ [coordinatesArray addObject:[RCTConvert AIRGoogleMapCoordinate:json]];
79
+ }
80
+
81
+ NSDictionary* edgePadding = [RCTConvert dictonaryFromString:edgePaddingJSON];
82
+
83
+ [_view fitToCoordinates:coordinatesArray withEdgePadding:edgePadding animated:animated];
84
+ }
85
+
86
+ #pragma mark - Native commands
87
+
88
+ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
89
+ {
90
+ RCTRNMapsGoogleMapViewHandleCommand(self, commandName, args);
91
+ }
92
+
93
+
94
+ + (ComponentDescriptorProvider)componentDescriptorProvider
95
+ {
96
+ return concreteComponentDescriptorProvider<RNMapsGoogleMapViewComponentDescriptor>();
97
+ }
98
+
99
+ - (void) prepareContentView {
100
+
101
+ _view = (AIRGoogleMap *)[_legacyMapManager view];
102
+
103
+ self.contentView = _view;
104
+
105
+ _view.onPress = [self](NSDictionary* dictionary) {
106
+ if (_eventEmitter) {
107
+ // Extract values from the NSDictionary
108
+ NSDictionary* coordinateDict = dictionary[@"coordinate"];
109
+ NSDictionary* positionDict = dictionary[@"position"];
110
+
111
+ // Populate the OnMapPressCoordinate struct
112
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnPressCoordinate coordinate = {
113
+ .latitude = [coordinateDict[@"latitude"] doubleValue],
114
+ .longitude = [coordinateDict[@"longitude"] doubleValue],
115
+ };
116
+
117
+ // Populate the OnMapPressPosition struct
118
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnPressPosition position = {
119
+ .x = [positionDict[@"x"] doubleValue],
120
+ .y = [positionDict[@"y"] doubleValue],
121
+ };
122
+
123
+ auto mapViewEventEmitter = std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter);
124
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnPress data = {
125
+ .action = std::string([@"press" UTF8String]),
126
+ .position = position,
127
+ .coordinate = coordinate
128
+ };
129
+ mapViewEventEmitter->onPress(data);
130
+ }
131
+ };
132
+
133
+ _view.onMapReady = [self](NSDictionary* dictionary) {
134
+ if (_eventEmitter) {
135
+ auto mapViewEventEmitter = std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter);
136
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnMapReady data = {};
137
+ mapViewEventEmitter->onMapReady(data);
138
+ }
139
+ };
140
+
141
+ _view.onMapLoaded = [self](NSDictionary* dictionary) {
142
+ if (_eventEmitter) {
143
+ auto mapViewEventEmitter = std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter);
144
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnMapLoaded data = {};
145
+ mapViewEventEmitter->onMapLoaded(data);
146
+ }
147
+ };
148
+
149
+ _view.onKmlReady = [self](NSDictionary* dictionary) {
150
+ if (_eventEmitter) {
151
+
152
+ auto mapViewEventEmitter = std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter);
153
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnKmlReady data = {};
154
+ mapViewEventEmitter->onKmlReady(data);
155
+ }
156
+ };
157
+ _view.onChange = [self](NSDictionary* dictionary) {
158
+ if (_eventEmitter) {
159
+
160
+ NSDictionary* regionDict = dictionary[@"region"];
161
+ auto mapViewEventEmitter = std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter);
162
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnRegionChange data = {
163
+ .region.latitude = [regionDict[@"latitude"] doubleValue],
164
+ .region.longitude = [regionDict[@"longitude"] doubleValue],
165
+ .region.latitudeDelta = [regionDict[@"latitudeDelta"] doubleValue],
166
+ .region.longitudeDelta = [regionDict[@"longitudeDelta"] doubleValue],
167
+ .continuous = [dictionary[@"continuous"] boolValue],
168
+ };
169
+ mapViewEventEmitter->onRegionChange(data);
170
+ }
171
+ };
172
+
173
+ _view.onPanDrag = [self](NSDictionary* dictionary) {
174
+ if (_eventEmitter) {
175
+
176
+ NSDictionary* coordinateDict = dictionary[@"coordinate"];
177
+ NSDictionary* positionDict = dictionary[@"position"];
178
+
179
+ // Populate the OnMapPressCoordinate struct
180
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnPanDragCoordinate coordinate = {
181
+ .latitude = [coordinateDict[@"latitude"] doubleValue],
182
+ .longitude = [coordinateDict[@"longitude"] doubleValue],
183
+ };
184
+
185
+ // Populate the OnMapDouplePressPosition struct
186
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnPanDragPosition position = {
187
+ .x = [positionDict[@"x"] doubleValue],
188
+ .y = [positionDict[@"y"] doubleValue],
189
+ };
190
+
191
+ auto mapViewEventEmitter = std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter);
192
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnPanDrag data = {
193
+ .position = position,
194
+ .coordinate = coordinate,
195
+ };
196
+ mapViewEventEmitter->onPanDrag(data);
197
+ }
198
+ };
199
+
200
+ _view.onUserLocationChange = [self](NSDictionary* dictionary) {
201
+ if (_eventEmitter) {
202
+
203
+ NSDictionary* coordinateDict = dictionary[@"coordinate"];
204
+ NSDictionary* errorDict = dictionary[@"error"];
205
+
206
+
207
+ // Populate the OnMapPressCoordinate struct
208
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnUserLocationChangeCoordinate coordinate = {
209
+ .latitude = [coordinateDict[@"latitude"] doubleValue],
210
+ .longitude = [coordinateDict[@"longitude"] doubleValue],
211
+ };
212
+ NSString* str = @"";
213
+ if (errorDict){
214
+ str = errorDict[@"message"];
215
+ }
216
+
217
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnUserLocationChangeError error = {
218
+ .message = std::string([str UTF8String]),
219
+ };
220
+
221
+
222
+ auto mapViewEventEmitter = std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter);
223
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnUserLocationChange data = {
224
+ .coordinate = coordinate,
225
+ .error = error,
226
+ };
227
+ mapViewEventEmitter->onUserLocationChange(data);
228
+ }
229
+ };
230
+
231
+
232
+
233
+ _view.onRegionChangeStart = [self](NSDictionary* dictionary) {
234
+ if (_eventEmitter) {
235
+
236
+ NSDictionary* regionDict = dictionary[@"region"];
237
+ auto mapViewEventEmitter = std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter);
238
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnRegionChangeStart data = {
239
+ .region.latitude = [regionDict[@"latitude"] doubleValue],
240
+ .region.longitude = [regionDict[@"longitude"] doubleValue],
241
+ .region.latitudeDelta = [regionDict[@"latitudeDelta"] doubleValue],
242
+ .region.longitudeDelta = [regionDict[@"longitudeDelta"] doubleValue],
243
+ .continuous = [dictionary[@"continuous"] boolValue],
244
+ };
245
+ mapViewEventEmitter->onRegionChangeStart(data);
246
+ }
247
+ };
248
+
249
+ _view.onRegionChange = [self](NSDictionary* dictionary) {
250
+ if (_eventEmitter) {
251
+
252
+ NSDictionary* regionDict = dictionary[@"region"];
253
+ auto mapViewEventEmitter = std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter);
254
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnRegionChange data = {
255
+ .region.latitude = [regionDict[@"latitude"] doubleValue],
256
+ .region.longitude = [regionDict[@"longitude"] doubleValue],
257
+ .region.latitudeDelta = [regionDict[@"latitudeDelta"] doubleValue],
258
+ .region.longitudeDelta = [regionDict[@"longitudeDelta"] doubleValue],
259
+ .continuous = [dictionary[@"continuous"] boolValue],
260
+ };
261
+ mapViewEventEmitter->onRegionChange(data);
262
+ }
263
+ };
264
+
265
+ _view.onRegionChangeComplete = [self](NSDictionary* dictionary) {
266
+ if (_eventEmitter) {
267
+
268
+ NSDictionary* regionDict = dictionary[@"region"];
269
+ auto mapViewEventEmitter = std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter);
270
+ facebook::react::RNMapsGoogleMapViewEventEmitter::OnRegionChangeComplete data = {
271
+ .region.latitude = [regionDict[@"latitude"] doubleValue],
272
+ .region.longitude = [regionDict[@"longitude"] doubleValue],
273
+ .region.latitudeDelta = [regionDict[@"latitudeDelta"] doubleValue],
274
+ .region.longitudeDelta = [regionDict[@"longitudeDelta"] doubleValue],
275
+ .continuous = [dictionary[@"continuous"] boolValue],
276
+ };
277
+ mapViewEventEmitter->onRegionChangeComplete(data);
278
+ }
279
+ };
280
+
281
+
282
+ #define HANDLE_MARKER_DRAG_EVENT(eventName, emitterFunction) \
283
+ if (_eventEmitter) { \
284
+ NSDictionary* coordinateDict = dictionary[@"coordinate"]; \
285
+ auto mapViewEventEmitter = \
286
+ std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter); \
287
+ facebook::react::RNMapsGoogleMapViewEventEmitter::eventName data = { \
288
+ .coordinate.latitude = [coordinateDict[@"latitude"] doubleValue], \
289
+ .coordinate.longitude = [coordinateDict[@"longitude"] doubleValue], \
290
+ .id = std::string([[dictionary valueForKey:@"id"] UTF8String]), \
291
+ }; \
292
+ mapViewEventEmitter->emitterFunction(data); \
293
+ }
294
+
295
+
296
+
297
+ #define HANDLE_MARKER_EVENT(eventName, emitterFunction, actionName) \
298
+ if (_eventEmitter) { \
299
+ NSDictionary* coordinateDict = dictionary[@"coordinate"]; \
300
+ facebook::react::RNMapsGoogleMapViewEventEmitter::eventName##Coordinate coordinate = { \
301
+ .latitude = [coordinateDict[@"latitude"] doubleValue], \
302
+ .longitude = [coordinateDict[@"longitude"] doubleValue], \
303
+ }; \
304
+ \
305
+ auto mapViewEventEmitter = \
306
+ std::static_pointer_cast<RNMapsGoogleMapViewEventEmitter const>(_eventEmitter); \
307
+ facebook::react::RNMapsGoogleMapViewEventEmitter::eventName data = { \
308
+ .action = std::string([@actionName UTF8String]), \
309
+ .id = std::string([[dictionary valueForKey:@"id"] UTF8String]), \
310
+ .coordinate = coordinate \
311
+ }; \
312
+ mapViewEventEmitter->emitterFunction(data); \
313
+ }
314
+
315
+ _view.onMarkerSelect = [self](NSDictionary* dictionary) {
316
+ HANDLE_MARKER_EVENT(OnMarkerSelect, onMarkerSelect, "marker-select");
317
+ };
318
+
319
+ _view.onMarkerDeselect = [self](NSDictionary* dictionary) {
320
+ HANDLE_MARKER_EVENT(OnMarkerDeselect, onMarkerDeselect, "marker-deselect");
321
+ };
322
+
323
+ _view.onMarkerPress = [self](NSDictionary* dictionary) {
324
+ HANDLE_MARKER_EVENT(OnMarkerPress, onMarkerPress, "marker-press");
325
+ };
326
+ }
327
+
328
+ - (instancetype)initWithFrame:(CGRect)frame
329
+ {
330
+ if (self = [super initWithFrame:frame]) {
331
+ static const auto defaultProps = std::make_shared<const RNMapsGoogleMapViewProps>();
332
+ _props = defaultProps;
333
+ _legacyMapManager = [[AIRGoogleMapManager alloc] init];
334
+ }
335
+
336
+ return self;
337
+ }
338
+
339
+ - (id)getPaperViewFromChildComponentView:(UIView *)childComponentView {
340
+ // Check if the childComponentView responds to the "adapter" selector
341
+ if ([childComponentView respondsToSelector:@selector(paperView)]) {
342
+ // Safely return the paperView
343
+ return [childComponentView valueForKey:@"paperView"];
344
+ }
345
+ // Return nil if paperView is not accessible
346
+ return nil;
347
+ }
348
+
349
+ - (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index{
350
+ id<RCTComponent> paperView = [self getPaperViewFromChildComponentView:childComponentView];
351
+ if (paperView){
352
+ [_view insertReactSubview:paperView atIndex:index];
353
+ }
354
+ }
355
+ - (void) unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
356
+ {
357
+ id<RCTComponent> paperView = [self getPaperViewFromChildComponentView:childComponentView];
358
+ if (paperView){
359
+ [_view removeReactSubview:paperView];
360
+ }
361
+ }
362
+
363
+
364
+ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
365
+ {
366
+ const auto &oldViewProps = *std::static_pointer_cast<RNMapsGoogleMapViewProps const>(_props);
367
+ const auto &newViewProps = *std::static_pointer_cast<RNMapsGoogleMapViewProps const>(props);
368
+
369
+
370
+ if (oldViewProps.googleMapId != newViewProps.googleMapId) {
371
+ NSString* mapID = RCTNSStringFromString(newViewProps.googleMapId);
372
+ if (mapID && [mapID length]){
373
+ _legacyMapManager.googleMapId = mapID;
374
+ }
375
+ }
376
+ if (!newViewProps.zoomTapEnabled) {
377
+ _legacyMapManager.zoomTapEnabled = newViewProps.zoomTapEnabled;
378
+ } else {
379
+ _legacyMapManager.zoomTapEnabled = true;
380
+ }
381
+ if (oldViewProps.loadingBackgroundColor != newViewProps.loadingBackgroundColor){
382
+ _legacyMapManager.backgroundColor = RCTUIColorFromSharedColor(newViewProps.backgroundColor);
383
+ }
384
+
385
+ NSLog(@"initialCamera lat:%f lng:%f pitch:%f zoom:%f heading: %f", newViewProps.initialCamera.center.latitude, newViewProps.initialCamera.center.longitude, newViewProps.initialCamera.pitch, newViewProps.initialCamera.zoom, newViewProps.initialCamera.heading);
386
+
387
+ // bug with zoom / pitch / heading where value is not 0 even though
388
+ // nothing is passed from JS so we depend on lat / lng comparison for now
389
+ if (newViewProps.initialCamera.center.latitude != oldViewProps.initialCamera.center.latitude ||
390
+ newViewProps.initialCamera.center.longitude != oldViewProps.initialCamera.center.longitude ||
391
+ newViewProps.initialCamera.pitch != oldViewProps.initialCamera.pitch ||
392
+ newViewProps.initialCamera.zoom != oldViewProps.initialCamera.zoom
393
+ || newViewProps.initialCamera.heading != oldViewProps.initialCamera.heading) {
394
+ GMSCameraPosition* camera = [GMSCameraPosition cameraWithLatitude:newViewProps.initialCamera.center.latitude
395
+ longitude:newViewProps.initialCamera.center.longitude
396
+ zoom:newViewProps.initialCamera.zoom
397
+ bearing:newViewProps.initialCamera.heading
398
+ viewingAngle:newViewProps.initialCamera.pitch];
399
+ _legacyMapManager.camera = camera;
400
+ }
401
+
402
+
403
+
404
+ if (!_view){
405
+ [self prepareContentView];
406
+ }
407
+
408
+ #define REMAP_MAPVIEW_PROP(name) \
409
+ if (oldViewProps.name != newViewProps.name) { \
410
+ _view.name = newViewProps.name; \
411
+ }
412
+
413
+ #define REMAP_MAPVIEW_STRING_PROP(name) \
414
+ if (oldViewProps.name != newViewProps.name) { \
415
+ _view.name = RCTNSStringFromString(newViewProps.name); \
416
+ }
417
+
418
+ #define REMAP_MAPVIEW_POINT_PROP(name) \
419
+ if (newViewProps.name.x != oldViewProps.name.x || \
420
+ newViewProps.name.y != oldViewProps.name.y) { \
421
+ _view.name = CGPointMake(newViewProps.name.x, newViewProps.name.y); \
422
+ }
423
+
424
+ #define REMAP_MAPVIEW_REGION_PROP(name) \
425
+ if (newViewProps.name.latitude != oldViewProps.name.latitude || \
426
+ newViewProps.name.longitude != oldViewProps.name.longitude || \
427
+ newViewProps.name.latitudeDelta != oldViewProps.name.latitudeDelta ||\
428
+ newViewProps.name.longitudeDelta != oldViewProps.name.longitudeDelta) { \
429
+ MKCoordinateSpan span = MKCoordinateSpanMake(newViewProps.name.latitudeDelta, \
430
+ newViewProps.name.longitudeDelta); \
431
+ MKCoordinateRegion region = MKCoordinateRegionMake(CLLocationCoordinate2DMake( \
432
+ newViewProps.name.latitude, newViewProps.name.longitude), span); \
433
+ _view.name = region; \
434
+ }
435
+
436
+ #define REMAP_GOOGLEMAPVIEW_CAMERA_PROP(name) \
437
+ if (newViewProps.name.center.latitude != oldViewProps.name.center.latitude || \
438
+ newViewProps.name.center.longitude != oldViewProps.name.center.longitude || \
439
+ newViewProps.name.heading != oldViewProps.name.heading || \
440
+ newViewProps.name.pitch != oldViewProps.name.pitch || \
441
+ newViewProps.name.zoom != oldViewProps.name.zoom) { \
442
+ GMSCameraPosition* camera = [GMSCameraPosition cameraWithLatitude:newViewProps.name.center.latitude \
443
+ longitude:newViewProps.name.center.longitude \
444
+ zoom:newViewProps.name.zoom \
445
+ bearing:newViewProps.name.heading \
446
+ viewingAngle:newViewProps.name.pitch]; \
447
+ _view.name = camera; \
448
+ }
449
+
450
+
451
+ #define REMAP_MAPVIEW_EDGEINSETS_PROP(name) \
452
+ if (newViewProps.name.top != oldViewProps.name.top || \
453
+ newViewProps.name.right != oldViewProps.name.right || \
454
+ newViewProps.name.bottom != oldViewProps.name.bottom || \
455
+ newViewProps.name.left != oldViewProps.name.left) { \
456
+ _view.name = UIEdgeInsetsMake(newViewProps.name.top, \
457
+ newViewProps.name.left, \
458
+ newViewProps.name.bottom, \
459
+ newViewProps.name.right); \
460
+ }
461
+
462
+
463
+ REMAP_MAPVIEW_PROP(pitchEnabled)
464
+
465
+ REMAP_MAPVIEW_PROP(zoomTapEnabled)
466
+
467
+ REMAP_MAPVIEW_PROP(scrollEnabled)
468
+
469
+ if (newViewProps.minZoom != oldViewProps.minZoom || newViewProps.maxZoom != oldViewProps.maxZoom){
470
+ [_view setMinZoom:newViewProps.minZoom maxZoom:newViewProps.maxZoom];
471
+ }
472
+
473
+ REMAP_MAPVIEW_PROP(showsCompass)
474
+ REMAP_MAPVIEW_PROP(showsTraffic)
475
+ REMAP_MAPVIEW_PROP(showsUserLocation)
476
+ REMAP_MAPVIEW_PROP(zoomEnabled)
477
+
478
+
479
+ REMAP_MAPVIEW_REGION_PROP(region)
480
+ REMAP_MAPVIEW_REGION_PROP(initialRegion)
481
+
482
+ REMAP_GOOGLEMAPVIEW_CAMERA_PROP(camera)
483
+
484
+
485
+ REMAP_MAPVIEW_EDGEINSETS_PROP(mapPadding)
486
+
487
+
488
+ if (oldViewProps.mapType != newViewProps.mapType){
489
+ switch (newViewProps.mapType) {
490
+ case RNMapsGoogleMapViewMapType::Standard:
491
+ _view.mapType = kGMSTypeNormal;
492
+ break;
493
+ case RNMapsGoogleMapViewMapType::Satellite:
494
+ _view.mapType = kGMSTypeSatellite;
495
+ break;
496
+ case RNMapsGoogleMapViewMapType::Terrain:
497
+ _view.mapType = kGMSTypeTerrain;
498
+ case RNMapsGoogleMapViewMapType::Hybrid:
499
+ _view.mapType = kGMSTypeHybrid;
500
+ default:
501
+ _view.mapType = kGMSTypeNormal;
502
+ break;
503
+ }
504
+ }
505
+
506
+ if (oldViewProps.userInterfaceStyle != newViewProps.userInterfaceStyle){
507
+ switch (newViewProps.userInterfaceStyle) {
508
+ case RNMapsGoogleMapViewUserInterfaceStyle::Light:
509
+ _view.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
510
+ break;
511
+ case RNMapsGoogleMapViewUserInterfaceStyle::Dark:
512
+ _view.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;
513
+ break;
514
+ case RNMapsGoogleMapViewUserInterfaceStyle::System:
515
+ _view.overrideUserInterfaceStyle = UIUserInterfaceStyleUnspecified;
516
+ break;
517
+ }
518
+ }
519
+
520
+
521
+ [super updateProps:props oldProps:oldProps];
522
+ }
523
+
524
+ @end
525
+
526
+ Class<RCTComponentViewProtocol> RNMapsGoogleMapViewCls(void)
527
+ {
528
+ return RNMapsGoogleMapView.class;
529
+ }
530
+
531
+ #endif
@@ -0,0 +1,25 @@
1
+ //
2
+ // RNMapsMapViewManager.mm
3
+ // AirMaps
4
+ //
5
+ // Created by Salah Ghanim on 23.11.24.
6
+ // Copyright © 2024 react-native-maps. All rights reserved.
7
+ //
8
+ #ifdef HAVE_GOOGLE_MAPS
9
+
10
+ #import <React/RCTLog.h>
11
+ #import <React/RCTUIManager.h>
12
+ #import <React/RCTViewManager.h>
13
+
14
+ @interface RNMapsGoogleMapViewManager : RCTViewManager
15
+ @end
16
+
17
+ @implementation RNMapsGoogleMapViewManager
18
+
19
+ RCT_EXPORT_MODULE(RNMapsGoogleMapViewManager)
20
+
21
+
22
+
23
+ @end
24
+
25
+ #endif
@@ -14,7 +14,7 @@
14
14
  #import "SMCalloutView.h"
15
15
  #import "RCTConvert+AirMap.h"
16
16
  #import "AIRMapCalloutSubview.h"
17
-
17
+ @class AIRMapCoordinate;
18
18
  @class AIRMapMarker;
19
19
 
20
20
  extern const NSTimeInterval AIRMapRegionChangeObserveInterval;
@@ -42,8 +42,8 @@ extern const NSInteger AIRMapMaxZoomLevel;
42
42
  @property (nonatomic, assign) UIEdgeInsets legalLabelInsets;
43
43
  @property (nonatomic, assign) MKCoordinateRegion initialRegion;
44
44
  @property (nonatomic, assign) MKMapCamera *initialCamera;
45
- @property (nonatomic, assign) CGFloat minZoomLevel;
46
- @property (nonatomic, assign) CGFloat maxZoomLevel;
45
+ @property (nonatomic, assign) CGFloat minZoom;
46
+ @property (nonatomic, assign) CGFloat maxZoom;
47
47
  @property (nonatomic, assign) CGPoint compassOffset;
48
48
  @property (nonatomic, assign) UIEdgeInsets mapPadding;
49
49
 
@@ -80,5 +80,5 @@ extern const NSInteger AIRMapMaxZoomLevel;
80
80
  - (AIRMapMarker*) markerAtPoint:(CGPoint)point;
81
81
  - (NSDictionary*) getMarkersFramesWithOnlyVisible:(BOOL)onlyVisible;
82
82
  - (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex;
83
-
83
+ -(void) fitToCoordinates:(NSArray<AIRMapCoordinate*>*) coordinates edgePadding:(UIEdgeInsets) edgeInsets animated:(Boolean) animated;
84
84
  @end
@@ -85,8 +85,8 @@ const NSInteger AIRMapMaxZoomLevel = 20;
85
85
  self.calloutView = [SMCalloutView platformCalloutView];
86
86
  self.calloutView.delegate = self;
87
87
 
88
- self.minZoomLevel = 0;
89
- self.maxZoomLevel = AIRMapMaxZoomLevel;
88
+ self.minZoom = 0;
89
+ self.maxZoom = AIRMapMaxZoomLevel;
90
90
  self.compassOffset = CGPointMake(0, 0);
91
91
  self.legacyZoomConstraintsEnabled = YES;
92
92
  }
@@ -199,7 +199,19 @@ const NSInteger AIRMapMaxZoomLevel = 20;
199
199
  }
200
200
  return marker;
201
201
  }
202
+ // Create Polyline with coordinates
203
+ -(void) fitToCoordinates:(NSArray<AIRMapCoordinate*>*) coordinates edgePadding:(UIEdgeInsets) edgeInsets animated:(Boolean) animated {
204
+ CLLocationCoordinate2D coords[coordinates.count];
205
+ for(int i = 0; i < coordinates.count; i++)
206
+ {
207
+ coords[i] = coordinates[i].coordinate;
208
+ }
209
+ MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordinates.count];
202
210
 
211
+ // Set Map viewport
212
+
213
+ [self setVisibleMapRect:[polyline boundingMapRect] edgePadding:edgeInsets animated:animated];
214
+ }
203
215
  - (CGRect) frameForMarker:(AIRMapMarker*) mrkAnn {
204
216
  MKAnnotationView* mrkView = [self viewForAnnotation: mrkAnn];
205
217
  CGRect mrkFrame = mrkView.frame;
@@ -350,23 +350,8 @@ RCT_EXPORT_METHOD(fitToCoordinates:(nonnull NSNumber *)reactTag
350
350
  RCTLogError(@"Invalid view returned from registry, expecting AIRMap, got: %@", view);
351
351
  } else {
352
352
  AIRMap *mapView = (AIRMap *)view;
353
-
354
- // Create Polyline with coordinates
355
- CLLocationCoordinate2D coords[coordinates.count];
356
- for(int i = 0; i < coordinates.count; i++)
357
- {
358
- coords[i] = coordinates[i].coordinate;
359
- }
360
- MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coords count:coordinates.count];
361
-
362
- // Set Map viewport
363
- CGFloat top = [RCTConvert CGFloat:edgePadding[@"top"]];
364
- CGFloat right = [RCTConvert CGFloat:edgePadding[@"right"]];
365
- CGFloat bottom = [RCTConvert CGFloat:edgePadding[@"bottom"]];
366
- CGFloat left = [RCTConvert CGFloat:edgePadding[@"left"]];
367
-
368
- [mapView setVisibleMapRect:[polyline boundingMapRect] edgePadding:UIEdgeInsetsMake(top, left, bottom, right) animated:animated];
369
-
353
+ UIEdgeInsets edgeInsets = [RCTConvert UIEdgeInsets:edgePadding];
354
+ [mapView fitToCoordinates: coordinates edgePadding:edgeInsets animated:animated];
370
355
  }
371
356
  }];
372
357
  }
@@ -1175,11 +1160,11 @@ static int kDragCenterContext;
1175
1160
 
1176
1161
  CGFloat zoomLevel = [mapView getZoomLevel];
1177
1162
 
1178
- if (zoomLevel < mapView.minZoomLevel) {
1179
- [self setCenterCoordinate:[mapView centerCoordinate] zoomLevel:mapView.minZoomLevel animated:TRUE mapView:mapView];
1163
+ if (zoomLevel < mapView.minZoom) {
1164
+ [self setCenterCoordinate:[mapView centerCoordinate] zoomLevel:mapView.minZoom animated:TRUE mapView:mapView];
1180
1165
  }
1181
- else if (zoomLevel > mapView.maxZoomLevel) {
1182
- [self setCenterCoordinate:[mapView centerCoordinate] zoomLevel:mapView.maxZoomLevel animated:TRUE mapView:mapView];
1166
+ else if (zoomLevel > mapView.maxZoom) {
1167
+ [self setCenterCoordinate:[mapView centerCoordinate] zoomLevel:mapView.maxZoom animated:TRUE mapView:mapView];
1183
1168
  }
1184
1169
  }
1185
1170
 
@@ -7,6 +7,8 @@
7
7
  #import <MapKit/MapKit.h>
8
8
  #import <React/RCTConvert.h>
9
9
 
10
+ @class AIRMapCoordinate;
11
+
10
12
  @interface RCTConvert (AirMap)
11
13
 
12
14
  + (MKCoordinateSpan)MKCoordinateSpan:(id)json;
@@ -16,4 +18,6 @@
16
18
  + (MKMapType)MKMapType:(id)json;
17
19
  + (NSDictionary*) dictonaryFromString:(NSString *) str;
18
20
  + (NSArray*) arrayFromString:(NSString *) str;
21
+ + (NSArray<NSArray<AIRMapCoordinate *> *> *)AIRMapCoordinateArrayArray:(id)json;
22
+ + (AIRMapCoordinate*) AIRMapCoordinate:(id)json;
19
23
  @end