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

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 (51) hide show
  1. package/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt +86 -5
  2. package/android/src/main/java/com/rngooglemapsplus/LocationHandler.kt +0 -1
  3. package/android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt +38 -4
  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 +261 -131
  9. package/ios/RNGoogleMapsPlusView.swift +72 -27
  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/swift/HybridRNGoogleMapsPlusViewSpec.swift +5 -2
  36. package/nitrogen/generated/ios/swift/HybridRNGoogleMapsPlusViewSpec_cxx.swift +58 -4
  37. package/nitrogen/generated/ios/swift/RNLatLngBounds.swift +46 -0
  38. package/nitrogen/generated/ios/swift/RNSize.swift +46 -0
  39. package/nitrogen/generated/ios/swift/RNSnapshotFormat.swift +44 -0
  40. package/nitrogen/generated/ios/swift/RNSnapshotOptions.swift +87 -0
  41. package/nitrogen/generated/ios/swift/RNSnapshotResultType.swift +40 -0
  42. package/nitrogen/generated/shared/c++/HybridRNGoogleMapsPlusViewSpec.cpp +3 -0
  43. package/nitrogen/generated/shared/c++/HybridRNGoogleMapsPlusViewSpec.hpp +12 -3
  44. package/nitrogen/generated/shared/c++/RNLatLngBounds.hpp +72 -0
  45. package/nitrogen/generated/shared/c++/RNSize.hpp +71 -0
  46. package/nitrogen/generated/shared/c++/RNSnapshotFormat.hpp +80 -0
  47. package/nitrogen/generated/shared/c++/RNSnapshotOptions.hpp +87 -0
  48. package/nitrogen/generated/shared/c++/RNSnapshotResultType.hpp +76 -0
  49. package/package.json +1 -1
  50. package/src/RNGoogleMapsPlusView.nitro.ts +15 -2
  51. 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,6 +193,7 @@ GMSIndoorDisplayDelegate {
191
193
  }
192
194
  }
193
195
 
196
+ @MainActor
194
197
  var currentCamera: GMSCameraPosition? {
195
198
  mapView?.camera
196
199
  }
@@ -268,7 +271,8 @@ GMSIndoorDisplayDelegate {
268
271
  }
269
272
  }
270
273
 
271
- @MainActor var mapPadding: RNMapPadding? {
274
+ @MainActor
275
+ var mapPadding: RNMapPadding? {
272
276
  didSet {
273
277
  mapView?.padding =
274
278
  mapPadding.map {
@@ -282,13 +286,15 @@ GMSIndoorDisplayDelegate {
282
286
  }
283
287
  }
284
288
 
285
- @MainActor var mapType: GMSMapViewType? {
289
+ @MainActor
290
+ var mapType: GMSMapViewType? {
286
291
  didSet {
287
292
  mapView?.mapType = mapType ?? .normal
288
293
  }
289
294
  }
290
295
 
291
- @MainActor var locationConfig: RNLocationConfig? {
296
+ @MainActor
297
+ var locationConfig: RNLocationConfig? {
292
298
  didSet {
293
299
  locationHandler.desiredAccuracy =
294
300
  locationConfig?.ios?.desiredAccuracy?.toCLLocationAccuracy
@@ -315,11 +321,12 @@ GMSIndoorDisplayDelegate {
315
321
  var onCameraChange: ((RNRegion, RNCamera, Bool) -> Void)?
316
322
  var onCameraChangeComplete: ((RNRegion, RNCamera, Bool) -> Void)?
317
323
 
318
- func setCamera(camera: GMSCameraPosition, animated: Bool, durationMS: Double) {
324
+ @MainActor
325
+ func setCamera(camera: GMSCameraPosition, animated: Bool, durationMs: Double) {
319
326
  if animated {
320
327
  withCATransaction(
321
328
  disableActions: false,
322
- duration: durationMS / 1000.0
329
+ duration: durationMs / 1000.0
323
330
  ) {
324
331
  mapView?.animate(to: camera)
325
332
  }
@@ -329,11 +336,12 @@ GMSIndoorDisplayDelegate {
329
336
  }
330
337
  }
331
338
 
339
+ @MainActor
332
340
  func setCameraToCoordinates(
333
341
  coordinates: [RNLatLng],
334
342
  padding: RNMapPadding,
335
343
  animated: Bool,
336
- durationMS: Double
344
+ durationMs: Double
337
345
  ) {
338
346
  if coordinates.isEmpty {
339
347
  return
@@ -369,7 +377,7 @@ GMSIndoorDisplayDelegate {
369
377
  if animated {
370
378
  withCATransaction(
371
379
  disableActions: false,
372
- duration: durationMS / 1000.0
380
+ duration: durationMs / 1000.0
373
381
  ) {
374
382
  mapView?.animate(with: update)
375
383
  }
@@ -378,6 +386,90 @@ GMSIndoorDisplayDelegate {
378
386
  }
379
387
  }
380
388
 
389
+ @MainActor
390
+ func setCameraBounds(_ bounds: GMSCoordinateBounds?) {
391
+ mapView?.cameraTargetBounds = bounds
392
+ }
393
+
394
+ @MainActor
395
+ func animateToBounds(
396
+ _ bounds: GMSCoordinateBounds,
397
+ padding: Double,
398
+ durationMs: Double,
399
+ lockBounds: Bool
400
+ ) {
401
+ if lockBounds {
402
+ mapView?.cameraTargetBounds = bounds
403
+ }
404
+
405
+ let update = GMSCameraUpdate.fit(bounds, withPadding: CGFloat(padding))
406
+ mapView?.animate(with: update)
407
+ }
408
+
409
+ @MainActor
410
+ func snapshot(
411
+ size: CGSize?,
412
+ format: String,
413
+ imageFormat: ImageFormat,
414
+ quality: CGFloat,
415
+ resultIsFile: Bool
416
+ ) -> NitroModules.Promise<String?> {
417
+ let promise = Promise<String?>()
418
+
419
+ DispatchQueue.main.async {
420
+ guard let mapView = self.mapView else {
421
+ promise.resolve(withResult: nil)
422
+ return
423
+ }
424
+
425
+ let renderer = UIGraphicsImageRenderer(bounds: mapView.bounds)
426
+ let image = renderer.image { ctx in
427
+ mapView.layer.render(in: ctx.cgContext)
428
+ }
429
+
430
+ var finalImage = image
431
+
432
+ size.map {
433
+ UIGraphicsBeginImageContextWithOptions($0, false, 0.0)
434
+ image.draw(in: CGRect(origin: .zero, size: $0))
435
+ finalImage = UIGraphicsGetImageFromCurrentImageContext() ?? image
436
+ UIGraphicsEndImageContext()
437
+ }
438
+
439
+ let data: Data?
440
+ switch imageFormat {
441
+ case .jpeg:
442
+ data = finalImage.jpegData(compressionQuality: quality)
443
+ case .png:
444
+ data = finalImage.pngData()
445
+ }
446
+
447
+ guard let imageData = data else {
448
+ promise.resolve(withResult: nil)
449
+ return
450
+ }
451
+
452
+ // Rückgabe
453
+ if resultIsFile {
454
+ let filename =
455
+ "map_snapshot_\(Int(Date().timeIntervalSince1970)).\(format)"
456
+ let fileURL = URL(fileURLWithPath: NSTemporaryDirectory())
457
+ .appendingPathComponent(filename)
458
+ do {
459
+ try imageData.write(to: fileURL)
460
+ promise.resolve(withResult: fileURL.path)
461
+ } catch {
462
+ promise.resolve(withResult: nil)
463
+ }
464
+ } else {
465
+ let base64 = imageData.base64EncodedString()
466
+ promise.resolve(withResult: "data:image/\(format);base64,\(base64)")
467
+ }
468
+ }
469
+
470
+ return promise
471
+ }
472
+
381
473
  @MainActor
382
474
  func addMarker(id: String, marker: GMSMarker) {
383
475
  if mapView == nil {
@@ -619,177 +711,215 @@ GMSIndoorDisplayDelegate {
619
711
  }
620
712
 
621
713
  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
- )
714
+ onMain {
715
+ let visibleRegion = mapView.projection.visibleRegion()
716
+ let bounds = GMSCoordinateBounds(region: visibleRegion)
717
+
718
+ let center = CLLocationCoordinate2D(
719
+ latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
720
+ longitude: (bounds.northEast.longitude + bounds.southWest.longitude)
721
+ / 2.0
722
+ )
629
723
 
630
- let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
631
- let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
724
+ let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
725
+ let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
632
726
 
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
727
+ let cp = mapView.camera
728
+ let region = RNRegion(
729
+ center: RNLatLng(center.latitude, center.longitude),
730
+ latitudeDelta: latDelta,
731
+ longitudeDelta: lngDelta
732
+ )
733
+ let cam = RNCamera(
734
+ center: RNLatLng(
735
+ latitude: cp.target.latitude,
736
+ longitude: cp.target.longitude
737
+ ),
738
+ zoom: Double(cp.zoom),
739
+ bearing: cp.bearing,
740
+ tilt: cp.viewingAngle
741
+ )
742
+ self.cameraMoveReasonIsGesture = gesture
649
743
 
650
- onCameraChangeStart?(region, cam, gesture)
744
+ self.onCameraChangeStart?(region, cam, gesture)
745
+ }
651
746
  }
652
747
 
653
748
  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)
749
+ onMain {
750
+ if let last = self.lastSubmittedCameraPosition,
751
+ last.target.latitude == position.target.latitude,
752
+ last.target.longitude == position.target.longitude,
753
+ last.zoom == position.zoom,
754
+ last.bearing == position.bearing,
755
+ last.viewingAngle == position.viewingAngle {
756
+ return
757
+ }
664
758
 
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
- )
759
+ self.lastSubmittedCameraPosition = position
760
+ let visibleRegion = mapView.projection.visibleRegion()
761
+ let bounds = GMSCoordinateBounds(region: visibleRegion)
669
762
 
670
- let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
671
- let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
763
+ let center = CLLocationCoordinate2D(
764
+ latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
765
+ longitude: (bounds.northEast.longitude + bounds.southWest.longitude)
766
+ / 2.0
767
+ )
672
768
 
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
769
+ let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
770
+ let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
771
+
772
+ let cp = mapView.camera
773
+ let region = RNRegion(
774
+ center: RNLatLng(center.latitude, center.longitude),
775
+ latitudeDelta: latDelta,
776
+ longitudeDelta: lngDelta
777
+ )
778
+ let cam = RNCamera(
779
+ center: RNLatLng(
780
+ latitude: cp.target.latitude,
781
+ longitude: cp.target.longitude
782
+ ),
783
+ zoom: Double(cp.zoom),
784
+ bearing: cp.bearing,
785
+ tilt: cp.viewingAngle
786
+ )
787
+ self.onCameraChange?(region, cam, self.cameraMoveReasonIsGesture)
788
+ }
690
789
  }
691
790
 
692
791
  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
- )
792
+ onMain {
793
+ let visibleRegion = mapView.projection.visibleRegion()
794
+ let bounds = GMSCoordinateBounds(region: visibleRegion)
795
+
796
+ let center = CLLocationCoordinate2D(
797
+ latitude: (bounds.northEast.latitude + bounds.southWest.latitude) / 2.0,
798
+ longitude: (bounds.northEast.longitude + bounds.southWest.longitude)
799
+ / 2.0
800
+ )
700
801
 
701
- let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
702
- let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
802
+ let latDelta = bounds.northEast.latitude - bounds.southWest.latitude
803
+ let lngDelta = bounds.northEast.longitude - bounds.southWest.longitude
703
804
 
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)
805
+ let cp = mapView.camera
806
+ let region = RNRegion(
807
+ center: RNLatLng(center.latitude, center.longitude),
808
+ latitudeDelta: latDelta,
809
+ longitudeDelta: lngDelta
810
+ )
811
+ let cam = RNCamera(
812
+ center: RNLatLng(
813
+ latitude: cp.target.latitude,
814
+ longitude: cp.target.longitude
815
+ ),
816
+ zoom: Double(cp.zoom),
817
+ bearing: cp.bearing,
818
+ tilt: cp.viewingAngle
819
+ )
820
+ self.onCameraChangeComplete?(region, cam, self.cameraMoveReasonIsGesture)
821
+ }
720
822
  }
721
823
 
722
824
  func mapView(
723
825
  _ mapView: GMSMapView,
724
826
  didTapAt coordinate: CLLocationCoordinate2D
725
827
  ) {
726
- onMapPress?(
727
- RNLatLng(
728
- latitude: coordinate.latitude,
729
- longitude: coordinate.longitude
828
+ onMain {
829
+ self.onMapPress?(
830
+ RNLatLng(
831
+ latitude: coordinate.latitude,
832
+ longitude: coordinate.longitude
833
+ )
730
834
  )
731
- )
835
+ }
732
836
  }
733
837
 
734
838
  func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
735
- mapView.selectedMarker = marker
736
- onMarkerPress?(marker.userData as? String, )
839
+ onMain {
840
+ mapView.selectedMarker = marker
841
+ self.onMarkerPress?(marker.userData as? String, )
842
+ }
737
843
  return true
738
844
  }
739
845
 
740
846
  func mapView(_ mapView: GMSMapView, didTap overlay: GMSOverlay) {
741
- switch overlay {
742
- case let circle as GMSCircle:
743
- onCirclePress?(circle.userData as? String, )
847
+ onMain {
848
+ switch overlay {
849
+ case let circle as GMSCircle:
850
+ self.onCirclePress?(circle.userData as? String, )
744
851
 
745
- case let polygon as GMSPolygon:
746
- onPolygonPress?(polygon.userData as? String, )
852
+ case let polygon as GMSPolygon:
853
+ self.onPolygonPress?(polygon.userData as? String, )
747
854
 
748
- case let polyline as GMSPolyline:
749
- onPolylinePress?(polyline.userData as? String, )
855
+ case let polyline as GMSPolyline:
856
+ self.onPolylinePress?(polyline.userData as? String, )
750
857
 
751
- default:
752
- break
858
+ default:
859
+ break
860
+ }
753
861
  }
754
862
  }
755
863
 
756
864
  func mapView(_ mapView: GMSMapView, didBeginDragging marker: GMSMarker) {
757
- onMarkerDragStart?(
758
- marker.userData as? String,
759
- RNLatLng(marker.position.latitude, marker.position.longitude)
760
- )
865
+ onMain {
866
+ self.onMarkerDragStart?(
867
+ marker.userData as? String,
868
+ RNLatLng(marker.position.latitude, marker.position.longitude)
869
+ )
870
+ }
761
871
  }
762
872
 
763
873
  func mapView(_ mapView: GMSMapView, didDrag marker: GMSMarker) {
764
- onMarkerDrag?(
765
- marker.userData as? String,
766
- RNLatLng(marker.position.latitude, marker.position.longitude)
767
- )
874
+ onMain {
875
+ self.onMarkerDrag?(
876
+ marker.userData as? String,
877
+ RNLatLng(marker.position.latitude, marker.position.longitude)
878
+ )
879
+ }
768
880
  }
769
881
 
770
882
  func mapView(_ mapView: GMSMapView, didEndDragging marker: GMSMarker) {
771
- onMarkerDragEnd?(
772
- marker.userData as? String,
773
- RNLatLng(marker.position.latitude, marker.position.longitude)
774
- )
883
+ onMain {
884
+ self.onMarkerDragEnd?(
885
+ marker.userData as? String,
886
+ RNLatLng(marker.position.latitude, marker.position.longitude)
887
+ )
888
+ }
775
889
  }
776
890
 
777
891
  func didChangeActiveBuilding(_ building: GMSIndoorBuilding?) {
778
- guard let display = mapView?.indoorDisplay, let building else { return }
779
- onIndoorBuildingFocused?(building.toRNIndoorBuilding(from: display))
892
+ onMain {
893
+ guard let display = self.mapView?.indoorDisplay, let building else {
894
+ return
895
+ }
896
+ self.onIndoorBuildingFocused?(building.toRNIndoorBuilding(from: display))
897
+ }
780
898
  }
781
899
 
782
900
  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))
901
+ onMain {
902
+ guard
903
+ let display = self.mapView?.indoorDisplay,
904
+ let building = display.activeBuilding,
905
+ let level,
906
+ let index = building.levels.firstIndex(where: {
907
+ $0.name == level.name && $0.shortName == level.shortName
908
+ })
909
+ else { return }
910
+
911
+ self.onIndoorLevelActivated?(
912
+ level.toRNIndoorLevel(index: index, active: true)
913
+ )
914
+ }
793
915
  }
916
+ }
794
917
 
918
+ @inline(__always)
919
+ func onMain(_ block: @escaping () -> Void) {
920
+ if Thread.isMainThread {
921
+ block()
922
+ } else {
923
+ DispatchQueue.main.async { block() }
924
+ }
795
925
  }