react-native-google-maps-plus 1.3.0-dev.2 → 1.3.0-dev.4

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 (52) hide show
  1. package/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt +92 -8
  2. package/android/src/main/java/com/rngooglemapsplus/LocationHandler.kt +0 -1
  3. package/android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt +52 -9
  4. package/android/src/main/java/com/rngooglemapsplus/extensions/RNLatLngBoundsExtension.kt +17 -0
  5. package/android/src/main/java/com/rngooglemapsplus/extensions/RNSize.kt +7 -0
  6. package/android/src/main/java/com/rngooglemapsplus/extensions/RNSnapshotFormat.kt +16 -0
  7. package/android/src/main/java/com/rngooglemapsplus/extensions/RNSnapshotResultType.kt +9 -0
  8. package/ios/GoogleMapViewImpl.swift +285 -145
  9. package/ios/RNGoogleMapsPlusView.swift +86 -38
  10. package/ios/extensions/RNLatLngBounds+Extension.swift +16 -0
  11. package/ios/extensions/RNSize+Extension.swift +7 -0
  12. package/ios/extensions/RNSnapshotFormat+Extension.swift +28 -0
  13. package/ios/extensions/RNSnapshotResultType+Extension.swift +12 -0
  14. package/lib/module/types.js.map +1 -1
  15. package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts +6 -3
  16. package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts.map +1 -1
  17. package/lib/typescript/src/types.d.ts +13 -1
  18. package/lib/typescript/src/types.d.ts.map +1 -1
  19. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.cpp +51 -7
  20. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.hpp +5 -2
  21. package/nitrogen/generated/android/c++/JRNLatLngBounds.hpp +58 -0
  22. package/nitrogen/generated/android/c++/JRNSize.hpp +57 -0
  23. package/nitrogen/generated/android/c++/JRNSnapshotFormat.hpp +62 -0
  24. package/nitrogen/generated/android/c++/JRNSnapshotOptions.hpp +71 -0
  25. package/nitrogen/generated/android/c++/JRNSnapshotResultType.hpp +59 -0
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/HybridRNGoogleMapsPlusViewSpec.kt +14 -2
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNLatLngBounds.kt +32 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNSize.kt +32 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNSnapshotFormat.kt +22 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNSnapshotOptions.kt +38 -0
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNSnapshotResultType.kt +21 -0
  32. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Bridge.hpp +57 -0
  33. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Umbrella.hpp +15 -0
  34. package/nitrogen/generated/ios/c++/HybridRNGoogleMapsPlusViewSpecSwift.hpp +40 -5
  35. package/nitrogen/generated/ios/c++/views/HybridRNGoogleMapsPlusViewComponent.mm +7 -0
  36. package/nitrogen/generated/ios/swift/HybridRNGoogleMapsPlusViewSpec.swift +5 -2
  37. package/nitrogen/generated/ios/swift/HybridRNGoogleMapsPlusViewSpec_cxx.swift +58 -4
  38. package/nitrogen/generated/ios/swift/RNLatLngBounds.swift +46 -0
  39. package/nitrogen/generated/ios/swift/RNSize.swift +46 -0
  40. package/nitrogen/generated/ios/swift/RNSnapshotFormat.swift +44 -0
  41. package/nitrogen/generated/ios/swift/RNSnapshotOptions.swift +87 -0
  42. package/nitrogen/generated/ios/swift/RNSnapshotResultType.swift +40 -0
  43. package/nitrogen/generated/shared/c++/HybridRNGoogleMapsPlusViewSpec.cpp +3 -0
  44. package/nitrogen/generated/shared/c++/HybridRNGoogleMapsPlusViewSpec.hpp +12 -3
  45. package/nitrogen/generated/shared/c++/RNLatLngBounds.hpp +72 -0
  46. package/nitrogen/generated/shared/c++/RNSize.hpp +71 -0
  47. package/nitrogen/generated/shared/c++/RNSnapshotFormat.hpp +80 -0
  48. package/nitrogen/generated/shared/c++/RNSnapshotOptions.hpp +87 -0
  49. package/nitrogen/generated/shared/c++/RNSnapshotResultType.hpp +76 -0
  50. package/package.json +1 -1
  51. package/src/RNGoogleMapsPlusView.nitro.ts +15 -2
  52. package/src/types.ts +24 -2
@@ -41,6 +41,7 @@ GMSIndoorDisplayDelegate {
41
41
  setupAppLifecycleObservers()
42
42
  }
43
43
 
44
+ @MainActor
44
45
  private func setupAppLifecycleObservers() {
45
46
  NotificationCenter.default.addObserver(
46
47
  self,
@@ -82,6 +83,7 @@ GMSIndoorDisplayDelegate {
82
83
  mapReady = true
83
84
  }
84
85
 
86
+ @MainActor
85
87
  private func initLocationCallbacks() {
86
88
  locationHandler.onUpdate = { [weak self] loc in
87
89
  guard let self = self else { return }
@@ -191,10 +193,16 @@ GMSIndoorDisplayDelegate {
191
193
  }
192
194
  }
193
195
 
196
+ @MainActor
194
197
  var currentCamera: GMSCameraPosition? {
195
198
  mapView?.camera
196
199
  }
197
200
 
201
+ @MainActor
202
+ var initialProps: RNInitialProps? {
203
+ didSet {}
204
+ }
205
+
198
206
  @MainActor
199
207
  var uiSettings: RNMapUiSettings? {
200
208
  didSet {
@@ -268,7 +276,8 @@ GMSIndoorDisplayDelegate {
268
276
  }
269
277
  }
270
278
 
271
- @MainActor var mapPadding: RNMapPadding? {
279
+ @MainActor
280
+ var mapPadding: RNMapPadding? {
272
281
  didSet {
273
282
  mapView?.padding =
274
283
  mapPadding.map {
@@ -282,13 +291,15 @@ GMSIndoorDisplayDelegate {
282
291
  }
283
292
  }
284
293
 
285
- @MainActor var mapType: GMSMapViewType? {
294
+ @MainActor
295
+ var mapType: GMSMapViewType? {
286
296
  didSet {
287
297
  mapView?.mapType = mapType ?? .normal
288
298
  }
289
299
  }
290
300
 
291
- @MainActor var locationConfig: RNLocationConfig? {
301
+ @MainActor
302
+ var locationConfig: RNLocationConfig? {
292
303
  didSet {
293
304
  locationHandler.desiredAccuracy =
294
305
  locationConfig?.ios?.desiredAccuracy?.toCLLocationAccuracy
@@ -315,11 +326,12 @@ GMSIndoorDisplayDelegate {
315
326
  var onCameraChange: ((RNRegion, RNCamera, Bool) -> Void)?
316
327
  var onCameraChangeComplete: ((RNRegion, RNCamera, Bool) -> Void)?
317
328
 
318
- func setCamera(camera: GMSCameraPosition, animated: Bool, durationMS: Double) {
329
+ @MainActor
330
+ func setCamera(camera: GMSCameraPosition, animated: Bool, durationMs: Double) {
319
331
  if animated {
320
332
  withCATransaction(
321
333
  disableActions: false,
322
- duration: durationMS / 1000.0
334
+ duration: durationMs / 1000.0
323
335
  ) {
324
336
  mapView?.animate(to: camera)
325
337
  }
@@ -329,11 +341,12 @@ GMSIndoorDisplayDelegate {
329
341
  }
330
342
  }
331
343
 
344
+ @MainActor
332
345
  func setCameraToCoordinates(
333
346
  coordinates: [RNLatLng],
334
347
  padding: RNMapPadding,
335
348
  animated: Bool,
336
- durationMS: Double
349
+ durationMs: Double
337
350
  ) {
338
351
  if coordinates.isEmpty {
339
352
  return
@@ -369,7 +382,7 @@ GMSIndoorDisplayDelegate {
369
382
  if animated {
370
383
  withCATransaction(
371
384
  disableActions: false,
372
- duration: durationMS / 1000.0
385
+ duration: durationMs / 1000.0
373
386
  ) {
374
387
  mapView?.animate(with: update)
375
388
  }
@@ -378,6 +391,90 @@ GMSIndoorDisplayDelegate {
378
391
  }
379
392
  }
380
393
 
394
+ @MainActor
395
+ func setCameraBounds(_ bounds: GMSCoordinateBounds?) {
396
+ mapView?.cameraTargetBounds = bounds
397
+ }
398
+
399
+ @MainActor
400
+ func animateToBounds(
401
+ _ bounds: GMSCoordinateBounds,
402
+ padding: Double,
403
+ durationMs: Double,
404
+ lockBounds: Bool
405
+ ) {
406
+ if lockBounds {
407
+ mapView?.cameraTargetBounds = bounds
408
+ }
409
+
410
+ let update = GMSCameraUpdate.fit(bounds, withPadding: CGFloat(padding))
411
+ mapView?.animate(with: update)
412
+ }
413
+
414
+ @MainActor
415
+ func snapshot(
416
+ size: CGSize?,
417
+ format: String,
418
+ imageFormat: ImageFormat,
419
+ quality: CGFloat,
420
+ resultIsFile: Bool
421
+ ) -> NitroModules.Promise<String?> {
422
+ let promise = Promise<String?>()
423
+
424
+ DispatchQueue.main.async {
425
+ guard let mapView = self.mapView else {
426
+ promise.resolve(withResult: nil)
427
+ return
428
+ }
429
+
430
+ let renderer = UIGraphicsImageRenderer(bounds: mapView.bounds)
431
+ let image = renderer.image { ctx in
432
+ mapView.layer.render(in: ctx.cgContext)
433
+ }
434
+
435
+ var finalImage = image
436
+
437
+ size.map {
438
+ UIGraphicsBeginImageContextWithOptions($0, false, 0.0)
439
+ image.draw(in: CGRect(origin: .zero, size: $0))
440
+ finalImage = UIGraphicsGetImageFromCurrentImageContext() ?? image
441
+ UIGraphicsEndImageContext()
442
+ }
443
+
444
+ let data: Data?
445
+ switch imageFormat {
446
+ case .jpeg:
447
+ data = finalImage.jpegData(compressionQuality: quality)
448
+ case .png:
449
+ data = finalImage.pngData()
450
+ }
451
+
452
+ guard let imageData = data else {
453
+ promise.resolve(withResult: nil)
454
+ return
455
+ }
456
+
457
+ // Rückgabe
458
+ if resultIsFile {
459
+ let filename =
460
+ "map_snapshot_\(Int(Date().timeIntervalSince1970)).\(format)"
461
+ let fileURL = URL(fileURLWithPath: NSTemporaryDirectory())
462
+ .appendingPathComponent(filename)
463
+ do {
464
+ try imageData.write(to: fileURL)
465
+ promise.resolve(withResult: fileURL.path)
466
+ } catch {
467
+ promise.resolve(withResult: nil)
468
+ }
469
+ } else {
470
+ let base64 = imageData.base64EncodedString()
471
+ promise.resolve(withResult: "data:image/\(format);base64,\(base64)")
472
+ }
473
+ }
474
+
475
+ return promise
476
+ }
477
+
381
478
  @MainActor
382
479
  func addMarker(id: String, marker: GMSMarker) {
383
480
  if mapView == nil {
@@ -537,7 +634,10 @@ GMSIndoorDisplayDelegate {
537
634
 
538
635
  @MainActor
539
636
  func clearHeatmaps() {
540
- heatmapsById.values.forEach { $0.map = nil }
637
+ heatmapsById.values.forEach {
638
+ $0.clearTileCache()
639
+ $0.map = nil
640
+ }
541
641
  heatmapsById.removeAll()
542
642
  pendingHeatmaps.removeAll()
543
643
  }
@@ -579,16 +679,21 @@ GMSIndoorDisplayDelegate {
579
679
  }
580
680
 
581
681
  func deinitInternal() {
582
- markerBuilder.cancelAllIconTasks()
583
- clearMarkers()
584
- clearPolylines()
585
- clearPolygons()
586
- clearCircles()
587
- clearHeatmaps()
588
- locationHandler.stop()
589
- mapView?.clear()
590
- mapView?.delegate = nil
591
- mapView = nil
682
+ onMain {
683
+ self.locationHandler.stop()
684
+ self.markerBuilder.cancelAllIconTasks()
685
+ self.clearMarkers()
686
+ self.clearPolylines()
687
+ self.clearPolygons()
688
+ self.clearCircles()
689
+ self.clearHeatmaps()
690
+ self.clearKmlLayers()
691
+ self.mapView?.clear()
692
+ self.mapView?.indoorDisplay.delegate = nil
693
+ self.mapView?.delegate = nil
694
+ self.mapView = nil
695
+ self.initialized = false
696
+ }
592
697
  }
593
698
 
594
699
  @objc private func appDidBecomeActive() {
@@ -604,9 +709,6 @@ GMSIndoorDisplayDelegate {
604
709
  override func didMoveToWindow() {
605
710
  super.didMoveToWindow()
606
711
  if window != nil {
607
- if mapView != nil && mapReady {
608
- onMapReady?(true)
609
- }
610
712
  locationHandler.start()
611
713
  } else {
612
714
  locationHandler.stop()
@@ -619,177 +721,215 @@ GMSIndoorDisplayDelegate {
619
721
  }
620
722
 
621
723
  func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {
622
- let visibleRegion = mapView.projection.visibleRegion()
623
- let bounds = GMSCoordinateBounds(region: visibleRegion)
624
-
625
- let center = CLLocationCoordinate2D(
626
- latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
627
- longitude: (bounds.northEast.longitude + bounds.southWest.longitude) / 2.0
628
- )
724
+ onMain {
725
+ let visibleRegion = mapView.projection.visibleRegion()
726
+ let bounds = GMSCoordinateBounds(region: visibleRegion)
727
+
728
+ let center = CLLocationCoordinate2D(
729
+ latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
730
+ longitude: (bounds.northEast.longitude + bounds.southWest.longitude)
731
+ / 2.0
732
+ )
629
733
 
630
- let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
631
- let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
734
+ let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
735
+ let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
632
736
 
633
- let cp = mapView.camera
634
- let region = RNRegion(
635
- center: RNLatLng(center.latitude, center.longitude),
636
- latitudeDelta: latDelta,
637
- longitudeDelta: lngDelta
638
- )
639
- let cam = RNCamera(
640
- center: RNLatLng(
641
- latitude: cp.target.latitude,
642
- longitude: cp.target.longitude
643
- ),
644
- zoom: Double(cp.zoom),
645
- bearing: cp.bearing,
646
- tilt: cp.viewingAngle
647
- )
648
- cameraMoveReasonIsGesture = gesture
737
+ let cp = mapView.camera
738
+ let region = RNRegion(
739
+ center: RNLatLng(center.latitude, center.longitude),
740
+ latitudeDelta: latDelta,
741
+ longitudeDelta: lngDelta
742
+ )
743
+ let cam = RNCamera(
744
+ center: RNLatLng(
745
+ latitude: cp.target.latitude,
746
+ longitude: cp.target.longitude
747
+ ),
748
+ zoom: Double(cp.zoom),
749
+ bearing: cp.bearing,
750
+ tilt: cp.viewingAngle
751
+ )
752
+ self.cameraMoveReasonIsGesture = gesture
649
753
 
650
- onCameraChangeStart?(region, cam, gesture)
754
+ self.onCameraChangeStart?(region, cam, gesture)
755
+ }
651
756
  }
652
757
 
653
758
  func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
654
- if let last = lastSubmittedCameraPosition,
655
- last.target.latitude == position.target.latitude,
656
- last.target.longitude == position.target.longitude,
657
- last.zoom == position.zoom,
658
- last.bearing == position.bearing,
659
- last.viewingAngle == position.viewingAngle {
660
- return
661
- }
662
- let visibleRegion = mapView.projection.visibleRegion()
663
- let bounds = GMSCoordinateBounds(region: visibleRegion)
759
+ onMain {
760
+ if let last = self.lastSubmittedCameraPosition,
761
+ last.target.latitude == position.target.latitude,
762
+ last.target.longitude == position.target.longitude,
763
+ last.zoom == position.zoom,
764
+ last.bearing == position.bearing,
765
+ last.viewingAngle == position.viewingAngle {
766
+ return
767
+ }
664
768
 
665
- let center = CLLocationCoordinate2D(
666
- latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
667
- longitude: (bounds.northEast.longitude + bounds.southWest.longitude) / 2.0
668
- )
769
+ self.lastSubmittedCameraPosition = position
770
+ let visibleRegion = mapView.projection.visibleRegion()
771
+ let bounds = GMSCoordinateBounds(region: visibleRegion)
669
772
 
670
- let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
671
- let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
773
+ let center = CLLocationCoordinate2D(
774
+ latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
775
+ longitude: (bounds.northEast.longitude + bounds.southWest.longitude)
776
+ / 2.0
777
+ )
672
778
 
673
- let cp = mapView.camera
674
- let region = RNRegion(
675
- center: RNLatLng(center.latitude, center.longitude),
676
- latitudeDelta: latDelta,
677
- longitudeDelta: lngDelta
678
- )
679
- let cam = RNCamera(
680
- center: RNLatLng(
681
- latitude: cp.target.latitude,
682
- longitude: cp.target.longitude
683
- ),
684
- zoom: Double(cp.zoom),
685
- bearing: cp.bearing,
686
- tilt: cp.viewingAngle
687
- )
688
- onCameraChange?(region, cam, cameraMoveReasonIsGesture)
689
- lastSubmittedCameraPosition = position
779
+ let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
780
+ let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
781
+
782
+ let cp = mapView.camera
783
+ let region = RNRegion(
784
+ center: RNLatLng(center.latitude, center.longitude),
785
+ latitudeDelta: latDelta,
786
+ longitudeDelta: lngDelta
787
+ )
788
+ let cam = RNCamera(
789
+ center: RNLatLng(
790
+ latitude: cp.target.latitude,
791
+ longitude: cp.target.longitude
792
+ ),
793
+ zoom: Double(cp.zoom),
794
+ bearing: cp.bearing,
795
+ tilt: cp.viewingAngle
796
+ )
797
+ self.onCameraChange?(region, cam, self.cameraMoveReasonIsGesture)
798
+ }
690
799
  }
691
800
 
692
801
  func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
693
- let visibleRegion = mapView.projection.visibleRegion()
694
- let bounds = GMSCoordinateBounds(region: visibleRegion)
695
-
696
- let center = CLLocationCoordinate2D(
697
- latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
698
- longitude: (bounds.northEast.longitude + bounds.southWest.longitude) / 2.0
699
- )
802
+ onMain {
803
+ let visibleRegion = mapView.projection.visibleRegion()
804
+ let bounds = GMSCoordinateBounds(region: visibleRegion)
805
+
806
+ let center = CLLocationCoordinate2D(
807
+ latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
808
+ longitude: (bounds.northEast.longitude + bounds.southWest.longitude)
809
+ / 2.0
810
+ )
700
811
 
701
- let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
702
- let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
812
+ let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
813
+ let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
703
814
 
704
- let cp = mapView.camera
705
- let region = RNRegion(
706
- center: RNLatLng(center.latitude, center.longitude),
707
- latitudeDelta: latDelta,
708
- longitudeDelta: lngDelta
709
- )
710
- let cam = RNCamera(
711
- center: RNLatLng(
712
- latitude: cp.target.latitude,
713
- longitude: cp.target.longitude
714
- ),
715
- zoom: Double(cp.zoom),
716
- bearing: cp.bearing,
717
- tilt: cp.viewingAngle
718
- )
719
- onCameraChangeComplete?(region, cam, cameraMoveReasonIsGesture)
815
+ let cp = mapView.camera
816
+ let region = RNRegion(
817
+ center: RNLatLng(center.latitude, center.longitude),
818
+ latitudeDelta: latDelta,
819
+ longitudeDelta: lngDelta
820
+ )
821
+ let cam = RNCamera(
822
+ center: RNLatLng(
823
+ latitude: cp.target.latitude,
824
+ longitude: cp.target.longitude
825
+ ),
826
+ zoom: Double(cp.zoom),
827
+ bearing: cp.bearing,
828
+ tilt: cp.viewingAngle
829
+ )
830
+ self.onCameraChangeComplete?(region, cam, self.cameraMoveReasonIsGesture)
831
+ }
720
832
  }
721
833
 
722
834
  func mapView(
723
835
  _ mapView: GMSMapView,
724
836
  didTapAt coordinate: CLLocationCoordinate2D
725
837
  ) {
726
- onMapPress?(
727
- RNLatLng(
728
- latitude: coordinate.latitude,
729
- longitude: coordinate.longitude
838
+ onMain {
839
+ self.onMapPress?(
840
+ RNLatLng(
841
+ latitude: coordinate.latitude,
842
+ longitude: coordinate.longitude
843
+ )
730
844
  )
731
- )
845
+ }
732
846
  }
733
847
 
734
848
  func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
735
- mapView.selectedMarker = marker
736
- onMarkerPress?(marker.userData as? String, )
849
+ onMain {
850
+ mapView.selectedMarker = marker
851
+ self.onMarkerPress?(marker.userData as? String, )
852
+ }
737
853
  return true
738
854
  }
739
855
 
740
856
  func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
741
- switch overlay {
742
- case let circle as GMSCircle:
743
- onCirclePress?(circle.userData as? String, )
857
+ onMain {
858
+ switch overlay {
859
+ case let circle as GMSCircle:
860
+ self.onCirclePress?(circle.userData as? String, )
744
861
 
745
- case let polygon as GMSPolygon:
746
- onPolygonPress?(polygon.userData as? String, )
862
+ case let polygon as GMSPolygon:
863
+ self.onPolygonPress?(polygon.userData as? String, )
747
864
 
748
- case let polyline as GMSPolyline:
749
- onPolylinePress?(polyline.userData as? String, )
865
+ case let polyline as GMSPolyline:
866
+ self.onPolylinePress?(polyline.userData as? String, )
750
867
 
751
- default:
752
- break
868
+ default:
869
+ break
870
+ }
753
871
  }
754
872
  }
755
873
 
756
874
  func mapView(_ mapView: GMSMapView, didBeginDragging marker: GMSMarker) {
757
- onMarkerDragStart?(
758
- marker.userData as? String,
759
- RNLatLng(marker.position.latitude, marker.position.longitude)
760
- )
875
+ onMain {
876
+ self.onMarkerDragStart?(
877
+ marker.userData as? String,
878
+ RNLatLng(marker.position.latitude, marker.position.longitude)
879
+ )
880
+ }
761
881
  }
762
882
 
763
883
  func mapView(_ mapView: GMSMapView, didDrag marker: GMSMarker) {
764
- onMarkerDrag?(
765
- marker.userData as? String,
766
- RNLatLng(marker.position.latitude, marker.position.longitude)
767
- )
884
+ onMain {
885
+ self.onMarkerDrag?(
886
+ marker.userData as? String,
887
+ RNLatLng(marker.position.latitude, marker.position.longitude)
888
+ )
889
+ }
768
890
  }
769
891
 
770
892
  func mapView(_ mapView: GMSMapView, didEndDragging marker: GMSMarker) {
771
- onMarkerDragEnd?(
772
- marker.userData as? String,
773
- RNLatLng(marker.position.latitude, marker.position.longitude)
774
- )
893
+ onMain {
894
+ self.onMarkerDragEnd?(
895
+ marker.userData as? String,
896
+ RNLatLng(marker.position.latitude, marker.position.longitude)
897
+ )
898
+ }
775
899
  }
776
900
 
777
901
  func didChangeActiveBuilding(_ building: GMSIndoorBuilding?) {
778
- guard let display = mapView?.indoorDisplay, let building else { return }
779
- onIndoorBuildingFocused?(building.toRNIndoorBuilding(from: display))
902
+ onMain {
903
+ guard let display = self.mapView?.indoorDisplay, let building else {
904
+ return
905
+ }
906
+ self.onIndoorBuildingFocused?(building.toRNIndoorBuilding(from: display))
907
+ }
780
908
  }
781
909
 
782
910
  func didChangeActiveLevel(_ level: GMSIndoorLevel?) {
783
- guard
784
- let display = mapView?.indoorDisplay,
785
- let building = display.activeBuilding,
786
- let level,
787
- let index = building.levels.firstIndex(where: {
788
- $0.name == level.name && $0.shortName == level.shortName
789
- })
790
- else { return }
791
-
792
- onIndoorLevelActivated?(level.toRNIndoorLevel(index: index, active: true))
911
+ onMain {
912
+ guard
913
+ let display = self.mapView?.indoorDisplay,
914
+ let building = display.activeBuilding,
915
+ let level,
916
+ let index = building.levels.firstIndex(where: {
917
+ $0.name == level.name && $0.shortName == level.shortName
918
+ })
919
+ else { return }
920
+
921
+ self.onIndoorLevelActivated?(
922
+ level.toRNIndoorLevel(index: index, active: true)
923
+ )
924
+ }
793
925
  }
926
+ }
794
927
 
928
+ @inline(__always)
929
+ func onMain(_ block: @escaping () -> Void) {
930
+ if Thread.isMainThread {
931
+ block()
932
+ } else {
933
+ DispatchQueue.main.async { block() }
934
+ }
795
935
  }