react-native-google-maps-plus 1.9.0-dev.1 → 1.10.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 (40) hide show
  1. package/android/gradle.properties +1 -1
  2. package/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt +63 -80
  3. package/android/src/main/java/com/rngooglemapsplus/LocationHandler.kt +3 -3
  4. package/android/src/main/java/com/rngooglemapsplus/MapLifecycleEventObserver.kt +78 -0
  5. package/android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt +6 -13
  6. package/android/src/main/java/com/rngooglemapsplus/extensions/RNLatLngBoundsExtension.kt +0 -1
  7. package/android/src/main/java/com/rngooglemapsplus/extensions/ThrowableExtension.kt +2 -0
  8. package/expoConfig/build/index.js +2 -2
  9. package/ios/GoogleMapViewImpl.swift +30 -20
  10. package/ios/RNGoogleMapsPlusView.swift +8 -16
  11. package/ios/extensions/CLLocation+Extension.swift +1 -1
  12. package/ios/extensions/RNLineCapType+Extension.swift +0 -1
  13. package/ios/extensions/RNLineJoinType+Extension.swift +0 -2
  14. package/ios/extensions/String+Extensions.swift +6 -6
  15. package/lib/module/GoogleMapsPlus.js.map +1 -1
  16. package/lib/module/index.js.map +1 -1
  17. package/lib/typescript/src/GoogleMapsPlus.d.ts +1 -1
  18. package/lib/typescript/src/GoogleMapsPlus.d.ts.map +1 -1
  19. package/lib/typescript/src/RNGoogleMapsPlusModule.nitro.d.ts.map +1 -1
  20. package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts +1 -1
  21. package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts.map +1 -1
  22. package/lib/typescript/src/index.d.ts +1 -1
  23. package/lib/typescript/src/index.d.ts.map +1 -1
  24. package/lib/typescript/src/types.d.ts +2 -2
  25. package/lib/typescript/src/types.d.ts.map +1 -1
  26. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.cpp +16 -8
  27. package/nitrogen/generated/android/c++/JRNHeatmap.hpp +2 -1
  28. package/nitrogen/generated/android/c++/JRNHeatmapGradient.hpp +2 -1
  29. package/nitrogen/generated/android/c++/JRNIndoorBuilding.hpp +2 -1
  30. package/nitrogen/generated/android/c++/JRNPolygon.hpp +4 -2
  31. package/nitrogen/generated/android/c++/JRNPolygonHole.hpp +2 -1
  32. package/nitrogen/generated/android/c++/JRNPolyline.hpp +2 -1
  33. package/package.json +19 -69
  34. package/src/GoogleMapsPlus.tsx +1 -2
  35. package/src/RNGoogleMapsPlusModule.nitro.ts +1 -0
  36. package/src/RNGoogleMapsPlusView.nitro.ts +5 -5
  37. package/src/index.tsx +2 -1
  38. package/src/types.ts +2 -2
  39. package/scripts/create-dev-tag.sh +0 -8
  40. package/scripts/nitrogen-patch.js +0 -191
@@ -6,4 +6,4 @@ RNGoogleMapsPlus_ndkVersion=27.1.12297006
6
6
  RNGoogleMapsPlus_googlePlayServicesBaseVersion=18.9.0
7
7
  RNGoogleMapsPlus_googlePlayServicesMapsVersion=19.2.0
8
8
  RNGoogleMapsPlus_googlePlayServicesLocationVersion=21.3.0
9
- RNGoogleMapsPlus_mapsUtilsVersion=3.19.0
9
+ RNGoogleMapsPlus_mapsUtilsVersion=3.19.1
@@ -12,7 +12,8 @@ import android.location.Location
12
12
  import android.util.Size
13
13
  import android.view.View
14
14
  import android.widget.FrameLayout
15
- import com.facebook.react.bridge.LifecycleEventListener
15
+ import androidx.lifecycle.Lifecycle
16
+ import androidx.lifecycle.findViewTreeLifecycleOwner
16
17
  import com.facebook.react.uimanager.PixelUtil.dpToPx
17
18
  import com.facebook.react.uimanager.ThemedReactContext
18
19
  import com.google.android.gms.maps.CameraUpdateFactory
@@ -81,10 +82,12 @@ class GoogleMapsViewImpl(
81
82
  GoogleMap.OnInfoWindowLongClickListener,
82
83
  GoogleMap.OnMyLocationClickListener,
83
84
  GoogleMap.OnMyLocationButtonClickListener,
84
- GoogleMap.InfoWindowAdapter,
85
- LifecycleEventListener {
86
- private var initialized = false
87
- private var loaded = false
85
+ GoogleMap.InfoWindowAdapter {
86
+ private var lifecycleObserver: MapLifecycleEventObserver? = null
87
+ private var lifecycle: Lifecycle? = null
88
+
89
+ private var mapViewInitialized = false
90
+ private var mapViewLoaded = false
88
91
  private var destroyed = false
89
92
  private var googleMap: GoogleMap? = null
90
93
  private var mapView: MapView? = null
@@ -125,13 +128,12 @@ class GoogleMapsViewImpl(
125
128
  init {
126
129
  MapsInitializer.initialize(reactContext)
127
130
  reactContext.registerComponentCallbacks(componentCallbacks)
128
- reactContext.addLifecycleEventListener(this)
129
131
  }
130
132
 
131
- fun initMapView(googleMapsOptions: GoogleMapOptions) =
133
+ fun initMapView() =
132
134
  onUi {
133
- if (initialized) return@onUi
134
- initialized = true
135
+ if (mapViewInitialized) return@onUi
136
+ mapViewInitialized = true
135
137
 
136
138
  val result = playServiceHandler.playServicesAvailability()
137
139
  val errorCode = result.toRNMapErrorCodeOrNull()
@@ -144,45 +146,46 @@ class GoogleMapsViewImpl(
144
146
  }
145
147
  }
146
148
 
147
- mapView = MapView(reactContext, googleMapsOptions)
148
- super.addView(mapView)
149
-
150
- mapView?.onCreate(null)
151
- mapView?.getMapAsync { map ->
152
- googleMap = map
153
- googleMap?.setOnMapLoadedCallback {
154
- googleMap?.setOnCameraMoveStartedListener(this@GoogleMapsViewImpl)
155
- googleMap?.setOnCameraMoveListener(this@GoogleMapsViewImpl)
156
- googleMap?.setOnCameraIdleListener(this@GoogleMapsViewImpl)
157
- googleMap?.setOnMarkerClickListener(this@GoogleMapsViewImpl)
158
- googleMap?.setOnPolylineClickListener(this@GoogleMapsViewImpl)
159
- googleMap?.setOnPolygonClickListener(this@GoogleMapsViewImpl)
160
- googleMap?.setOnCircleClickListener(this@GoogleMapsViewImpl)
161
- googleMap?.setOnMapClickListener(this@GoogleMapsViewImpl)
162
- googleMap?.setOnMapLongClickListener(this@GoogleMapsViewImpl)
163
- googleMap?.setOnPoiClickListener(this@GoogleMapsViewImpl)
164
- googleMap?.setOnMarkerDragListener(this@GoogleMapsViewImpl)
165
- googleMap?.setOnInfoWindowClickListener(this@GoogleMapsViewImpl)
166
- googleMap?.setOnInfoWindowCloseListener(this@GoogleMapsViewImpl)
167
- googleMap?.setOnInfoWindowLongClickListener(this@GoogleMapsViewImpl)
168
- googleMap?.setOnMyLocationClickListener(this@GoogleMapsViewImpl)
169
- googleMap?.setOnMyLocationButtonClickListener(this@GoogleMapsViewImpl)
170
- googleMap?.setInfoWindowAdapter(this@GoogleMapsViewImpl)
171
- loaded = true
172
- onMapLoaded?.invoke(
173
- map.projection.visibleRegion.toRnRegion(),
174
- map.cameraPosition.toRnCamera(),
175
- )
149
+ mapView =
150
+ MapView(reactContext, googleMapsOptions).also {
151
+ lifecycleObserver = MapLifecycleEventObserver(it, locationHandler)
152
+ super.addView(it)
153
+ it.getMapAsync { map ->
154
+ googleMap = map
155
+ googleMap?.setOnMapLoadedCallback {
156
+ googleMap?.setOnCameraMoveStartedListener(this@GoogleMapsViewImpl)
157
+ googleMap?.setOnCameraMoveListener(this@GoogleMapsViewImpl)
158
+ googleMap?.setOnCameraIdleListener(this@GoogleMapsViewImpl)
159
+ googleMap?.setOnMarkerClickListener(this@GoogleMapsViewImpl)
160
+ googleMap?.setOnPolylineClickListener(this@GoogleMapsViewImpl)
161
+ googleMap?.setOnPolygonClickListener(this@GoogleMapsViewImpl)
162
+ googleMap?.setOnCircleClickListener(this@GoogleMapsViewImpl)
163
+ googleMap?.setOnMapClickListener(this@GoogleMapsViewImpl)
164
+ googleMap?.setOnMapLongClickListener(this@GoogleMapsViewImpl)
165
+ googleMap?.setOnPoiClickListener(this@GoogleMapsViewImpl)
166
+ googleMap?.setOnMarkerDragListener(this@GoogleMapsViewImpl)
167
+ googleMap?.setOnInfoWindowClickListener(this@GoogleMapsViewImpl)
168
+ googleMap?.setOnInfoWindowCloseListener(this@GoogleMapsViewImpl)
169
+ googleMap?.setOnInfoWindowLongClickListener(this@GoogleMapsViewImpl)
170
+ googleMap?.setOnMyLocationClickListener(this@GoogleMapsViewImpl)
171
+ googleMap?.setOnMyLocationButtonClickListener(this@GoogleMapsViewImpl)
172
+ googleMap?.setInfoWindowAdapter(this@GoogleMapsViewImpl)
173
+ mapViewLoaded = true
174
+ onMapLoaded?.invoke(
175
+ map.projection.visibleRegion.toRnRegion(),
176
+ map.cameraPosition.toRnCamera(),
177
+ )
178
+ }
179
+ applyProps()
180
+ initLocationCallbacks()
181
+ onMapReady?.invoke(true)
182
+ }
176
183
  }
177
- applyProps()
178
- initLocationCallbacks()
179
- onMapReady?.invoke(true)
180
- }
181
184
  }
182
185
 
183
186
  override fun onCameraMoveStarted(reason: Int) =
184
187
  onUi {
185
- if (!loaded) return@onUi
188
+ if (!mapViewLoaded) return@onUi
186
189
  cameraMoveReason = reason
187
190
  val visibleRegion = googleMap?.projection?.visibleRegion ?: return@onUi
188
191
  val cameraPosition = googleMap?.cameraPosition ?: return@onUi
@@ -195,7 +198,7 @@ class GoogleMapsViewImpl(
195
198
 
196
199
  override fun onCameraMove() =
197
200
  onUi {
198
- if (!loaded) return@onUi
201
+ if (!mapViewLoaded) return@onUi
199
202
  val visibleRegion = googleMap?.projection?.visibleRegion ?: return@onUi
200
203
  val cameraPosition = googleMap?.cameraPosition ?: return@onUi
201
204
  val gesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason
@@ -208,7 +211,7 @@ class GoogleMapsViewImpl(
208
211
 
209
212
  override fun onCameraIdle() =
210
213
  onUi {
211
- if (!loaded) return@onUi
214
+ if (!mapViewLoaded) return@onUi
212
215
  val visibleRegion = googleMap?.projection?.visibleRegion ?: return@onUi
213
216
  val cameraPosition = googleMap?.cameraPosition ?: return@onUi
214
217
  val gesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason
@@ -226,7 +229,6 @@ class GoogleMapsViewImpl(
226
229
  locationHandler.onError = { error ->
227
230
  onUi { onLocationError?.invoke(error) }
228
231
  }
229
- locationHandler.start()
230
232
  }
231
233
 
232
234
  fun applyProps() {
@@ -275,7 +277,7 @@ class GoogleMapsViewImpl(
275
277
  val currentCamera: CameraPosition?
276
278
  get() = onUiSync { googleMap?.cameraPosition }
277
279
 
278
- var initialProps: RNInitialProps? = null
280
+ var googleMapsOptions: GoogleMapOptions = GoogleMapOptions()
279
281
 
280
282
  var uiSettings: RNMapUiSettings? = null
281
283
  set(value) {
@@ -811,7 +813,7 @@ class GoogleMapsViewImpl(
811
813
  onUi {
812
814
  if (destroyed) return@onUi
813
815
  destroyed = true
814
- locationHandler.stop()
816
+ lifecycleObserver?.toDestroyedState()
815
817
  markerBuilder.cancelAllJobs()
816
818
  clearMarkers()
817
819
  clearPolylines()
@@ -840,16 +842,9 @@ class GoogleMapsViewImpl(
840
842
  setInfoWindowAdapter(null)
841
843
  }
842
844
  googleMap = null
843
- mapView?.apply {
844
- onPause()
845
- onStop()
846
- onDestroy()
847
- removeAllViews()
848
- }
845
+ mapView?.removeAllViews()
849
846
  super.removeAllViews()
850
847
  reactContext.unregisterComponentCallbacks(componentCallbacks)
851
- reactContext.removeLifecycleEventListener(this)
852
- initialized = false
853
848
  }
854
849
 
855
850
  override fun requestLayout() {
@@ -864,32 +859,20 @@ class GoogleMapsViewImpl(
864
859
  }
865
860
  }
866
861
 
867
- override fun onAttachedToWindow() =
868
- onUi {
869
- super.onAttachedToWindow()
870
- locationHandler.start()
871
- }
872
-
873
- override fun onDetachedFromWindow() =
874
- onUi {
875
- super.onDetachedFromWindow()
876
- locationHandler.stop()
877
- }
878
-
879
- override fun onHostResume() =
880
- onUi {
881
- locationHandler.start()
882
- mapView?.onResume()
883
- }
884
-
885
- override fun onHostPause() =
886
- onUi {
887
- locationHandler.stop()
888
- mapView?.onPause()
862
+ override fun onAttachedToWindow() {
863
+ super.onAttachedToWindow()
864
+ initMapView()
865
+ lifecycle = mapView?.findViewTreeLifecycleOwner()?.lifecycle
866
+ lifecycleObserver?.let { observer ->
867
+ lifecycle?.addObserver(observer)
889
868
  }
869
+ }
890
870
 
891
- override fun onHostDestroy() {
892
- destroyInternal()
871
+ override fun onDetachedFromWindow() {
872
+ super.onDetachedFromWindow()
873
+ lifecycleObserver?.let { lifecycle?.removeObserver(it) }
874
+ lifecycle = null
875
+ lifecycleObserver?.toCreatedState()
893
876
  }
894
877
 
895
878
  override fun onMarkerClick(marker: Marker): Boolean {
@@ -56,6 +56,8 @@ class LocationHandler(
56
56
  this.interval = interval ?: INTERVAL_DEFAULT
57
57
  this.minUpdateInterval = minUpdateInterval ?: MIN_UPDATE_INTERVAL
58
58
  buildLocationRequest(this.priority, this.interval, this.minUpdateInterval)
59
+
60
+ if (!isActive) return
59
61
  stop()
60
62
  start()
61
63
  }
@@ -173,7 +175,7 @@ class LocationHandler(
173
175
  val error = e.toLocationErrorCode(context)
174
176
  onError?.invoke(error)
175
177
  }
176
- } catch (se: SecurityException) {
178
+ } catch (_: SecurityException) {
177
179
  onError?.invoke(RNLocationErrorCode.PERMISSION_DENIED)
178
180
  } catch (ex: Exception) {
179
181
  val error = ex.toLocationErrorCode(context)
@@ -193,11 +195,9 @@ class LocationHandler(
193
195
 
194
196
  override fun activate(listener: LocationSource.OnLocationChangedListener) {
195
197
  this.listener = listener
196
- start()
197
198
  }
198
199
 
199
200
  override fun deactivate() {
200
201
  listener = null
201
- stop()
202
202
  }
203
203
  }
@@ -0,0 +1,78 @@
1
+ package com.rngooglemapsplus
2
+
3
+ import android.os.Bundle
4
+ import androidx.lifecycle.Lifecycle
5
+ import androidx.lifecycle.LifecycleEventObserver
6
+ import androidx.lifecycle.LifecycleOwner
7
+ import com.google.android.gms.maps.MapView
8
+
9
+ class MapLifecycleEventObserver(
10
+ private val mapView: MapView?,
11
+ private val locationHandler: LocationHandler,
12
+ ) : LifecycleEventObserver {
13
+ private var currentState: Lifecycle.State = Lifecycle.State.INITIALIZED
14
+
15
+ override fun onStateChanged(
16
+ source: LifecycleOwner,
17
+ event: Lifecycle.Event,
18
+ ) {
19
+ when (event) {
20
+ Lifecycle.Event.ON_DESTROY -> toCreatedState()
21
+ else -> toState(event.targetState)
22
+ }
23
+ }
24
+
25
+ fun toCreatedState() {
26
+ if (currentState > Lifecycle.State.CREATED) {
27
+ toState(Lifecycle.State.CREATED)
28
+ }
29
+ }
30
+
31
+ fun toDestroyedState() {
32
+ if (currentState > Lifecycle.State.INITIALIZED) {
33
+ toState(Lifecycle.State.DESTROYED)
34
+ }
35
+ }
36
+
37
+ private fun toState(state: Lifecycle.State) {
38
+ while (currentState != state) {
39
+ when {
40
+ currentState < state -> upFromCurrentState()
41
+ currentState > state -> downFromCurrentState()
42
+ }
43
+ }
44
+ }
45
+
46
+ private fun downFromCurrentState() {
47
+ Lifecycle.Event.downFrom(currentState)?.also {
48
+ invokeEvent(it)
49
+ }
50
+ }
51
+
52
+ private fun upFromCurrentState() {
53
+ Lifecycle.Event.upFrom(currentState)?.also {
54
+ invokeEvent(it)
55
+ }
56
+ }
57
+
58
+ private fun invokeEvent(event: Lifecycle.Event) {
59
+ when (event) {
60
+ Lifecycle.Event.ON_CREATE -> mapView?.onCreate(Bundle())
61
+ Lifecycle.Event.ON_START -> mapView?.onStart()
62
+ Lifecycle.Event.ON_RESUME -> {
63
+ locationHandler.start()
64
+ mapView?.onResume()
65
+ }
66
+
67
+ Lifecycle.Event.ON_PAUSE -> {
68
+ mapView?.onPause()
69
+ locationHandler.stop()
70
+ }
71
+
72
+ Lifecycle.Event.ON_STOP -> mapView?.onStop()
73
+ Lifecycle.Event.ON_DESTROY -> mapView?.onDestroy()
74
+ Lifecycle.Event.ON_ANY -> {}
75
+ }
76
+ currentState = event.targetState
77
+ }
78
+ }
@@ -24,7 +24,6 @@ import com.rngooglemapsplus.extensions.toSize
24
24
  class RNGoogleMapsPlusView(
25
25
  val context: ThemedReactContext,
26
26
  ) : HybridRNGoogleMapsPlusViewSpec() {
27
- private var propsInitialized = false
28
27
  private var currentCustomMapStyle: String? = null
29
28
  private var permissionHandler = PermissionHandler(context)
30
29
  private var locationHandler = LocationHandler(context)
@@ -40,10 +39,11 @@ class RNGoogleMapsPlusView(
40
39
  override val view =
41
40
  GoogleMapsViewImpl(context, locationHandler, playServiceHandler, markerBuilder)
42
41
 
43
- override fun afterUpdate() {
44
- super.afterUpdate()
45
- if (!propsInitialized) {
46
- propsInitialized = true
42
+ override var initialProps: RNInitialProps? = null
43
+ set(value) {
44
+ if (field == value) return
45
+ field = value
46
+
47
47
  val options =
48
48
  GoogleMapOptions().apply {
49
49
  initialProps?.mapId?.let { mapId(it) }
@@ -51,15 +51,8 @@ class RNGoogleMapsPlusView(
51
51
  initialProps?.camera?.let { camera(it.toCameraPosition(current = null)) }
52
52
  initialProps?.backgroundColor?.let { backgroundColor(it.toColor()) }
53
53
  }
54
- view.initMapView(options)
55
- }
56
- }
57
54
 
58
- override var initialProps: RNInitialProps? = null
59
- set(value) {
60
- if (field == value) return
61
- field = value
62
- view.initialProps = value
55
+ view.googleMapsOptions = options
63
56
  }
64
57
 
65
58
  override var uiSettings: RNMapUiSettings? = null
@@ -1,6 +1,5 @@
1
1
  package com.rngooglemapsplus.extensions
2
2
 
3
- import com.google.android.gms.maps.model.LatLng
4
3
  import com.google.android.gms.maps.model.LatLngBounds
5
4
  import com.rngooglemapsplus.RNLatLngBounds
6
5
 
@@ -16,10 +16,12 @@ fun Throwable.toLocationErrorCode(context: Context): RNLocationErrorCode {
16
16
  when (statusCode) {
17
17
  CommonStatusCodes.NETWORK_ERROR ->
18
18
  RNLocationErrorCode.POSITION_UNAVAILABLE
19
+
19
20
  LocationSettingsStatusCodes.RESOLUTION_REQUIRED,
20
21
  LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE,
21
22
  ->
22
23
  RNLocationErrorCode.SETTINGS_NOT_SATISFIED
24
+
23
25
  else ->
24
26
  RNLocationErrorCode.INTERNAL_ERROR
25
27
  }
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var fs_1 = __importDefault(require("fs"));
7
7
  var path_1 = __importDefault(require("path"));
8
- var pkg = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../../package.json'), 'utf8'));
9
8
  var config_plugins_1 = require("@expo/config-plugins");
10
- var withIosGoogleMapsPlus_1 = __importDefault(require("./ios/withIosGoogleMapsPlus"));
11
9
  var withAndroidGoogleMapsPlus_1 = __importDefault(require("./android/withAndroidGoogleMapsPlus"));
10
+ var withIosGoogleMapsPlus_1 = __importDefault(require("./ios/withIosGoogleMapsPlus"));
11
+ var pkg = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../../package.json'), 'utf8'));
12
12
  var withGoogleMapsPlus = function (config, props) {
13
13
  config = (0, withAndroidGoogleMapsPlus_1.default)(config, props);
14
14
  config = (0, withIosGoogleMapsPlus_1.default)(config, props);
@@ -10,8 +10,8 @@ GMSIndoorDisplayDelegate {
10
10
  private let locationHandler: LocationHandler
11
11
  private let markerBuilder: MapMarkerBuilder
12
12
  private var mapView: GMSMapView?
13
- private var initialized = false
14
- private var loaded = false
13
+ private var mapViewInitialized = false
14
+ private var mapViewLoaded = false
15
15
  private var deInitialized = false
16
16
 
17
17
  private var pendingMarkers: [(id: String, marker: GMSMarker)] = []
@@ -40,14 +40,18 @@ GMSIndoorDisplayDelegate {
40
40
  self.locationHandler = locationHandler
41
41
  self.markerBuilder = markerBuilder
42
42
  super.init(frame: frame)
43
- setupAppLifecycleObservers()
44
43
  }
45
44
 
45
+ @MainActor
46
+ private var lifecycleAttached = false
47
+
46
48
  @MainActor
47
49
  private var lifecycleTasks = [Task<Void, Never>]()
48
50
 
49
51
  @MainActor
50
- private func setupAppLifecycleObservers() {
52
+ private func attachLifecycleObservers() {
53
+ if lifecycleAttached { return }
54
+ lifecycleAttached = true
51
55
  lifecycleTasks.append(
52
56
  Task { @MainActor in
53
57
  for await _ in NotificationCenter.default.notifications(
@@ -79,14 +83,22 @@ GMSIndoorDisplayDelegate {
79
83
  )
80
84
  }
81
85
 
86
+ @MainActor
87
+ private func detachLifecycleObservers() {
88
+ if !lifecycleAttached { return }
89
+ lifecycleAttached = false
90
+ lifecycleTasks.forEach { $0.cancel() }
91
+ lifecycleTasks.removeAll()
92
+ }
93
+
82
94
  required init?(coder: NSCoder) {
83
95
  fatalError("init(coder:) has not been implemented")
84
96
  }
85
97
 
86
98
  @MainActor
87
- func initMapView(googleMapOptions: GMSMapViewOptions) {
88
- if initialized { return }
89
- initialized = true
99
+ func initMapView() {
100
+ if mapViewInitialized { return }
101
+ mapViewInitialized = true
90
102
  googleMapOptions.frame = bounds
91
103
 
92
104
  mapView = GMSMapView.init(options: googleMapOptions)
@@ -108,7 +120,6 @@ GMSIndoorDisplayDelegate {
108
120
  locationHandler.onError = { [weak self] error in
109
121
  self?.onLocationError?(error)
110
122
  }
111
- locationHandler.start()
112
123
  }
113
124
 
114
125
  @MainActor
@@ -171,9 +182,7 @@ GMSIndoorDisplayDelegate {
171
182
  }
172
183
 
173
184
  @MainActor
174
- var initialProps: RNInitialProps? {
175
- didSet {}
176
- }
185
+ var googleMapOptions: GMSMapViewOptions = GMSMapViewOptions()
177
186
 
178
187
  @MainActor
179
188
  var uiSettings: RNMapUiSettings? {
@@ -212,7 +221,7 @@ GMSIndoorDisplayDelegate {
212
221
  @MainActor
213
222
  var trafficEnabled: Bool? {
214
223
  didSet {
215
- mapView?.isTrafficEnabled = false
224
+ mapView?.isTrafficEnabled = trafficEnabled ?? false
216
225
  }
217
226
  }
218
227
 
@@ -693,6 +702,7 @@ GMSIndoorDisplayDelegate {
693
702
  func deinitInternal() {
694
703
  guard !deInitialized else { return }
695
704
  deInitialized = true
705
+ detachLifecycleObservers()
696
706
  onMain {
697
707
  self.locationHandler.stop()
698
708
  self.markerBuilder.cancelAllIconTasks()
@@ -707,7 +717,6 @@ GMSIndoorDisplayDelegate {
707
717
  self.mapView?.indoorDisplay.delegate = nil
708
718
  self.mapView?.delegate = nil
709
719
  self.mapView = nil
710
- self.initialized = false
711
720
  }
712
721
  }
713
722
 
@@ -728,21 +737,22 @@ GMSIndoorDisplayDelegate {
728
737
  override func didMoveToWindow() {
729
738
  super.didMoveToWindow()
730
739
  if window != nil {
740
+ attachLifecycleObservers()
731
741
  locationHandler.start()
742
+ initMapView()
732
743
  } else {
733
744
  locationHandler.stop()
745
+ detachLifecycleObservers()
734
746
  }
735
747
  }
736
748
 
737
749
  deinit {
738
750
  deinitInternal()
739
- lifecycleTasks.forEach { $0.cancel() }
740
- lifecycleTasks.removeAll()
741
751
  }
742
752
 
743
753
  func mapViewDidFinishTileRendering(_ mapView: GMSMapView) {
744
- guard !loaded else { return }
745
- loaded = true
754
+ guard !mapViewLoaded else { return }
755
+ mapViewLoaded = true
746
756
  let visibleRegion = mapView.projection.visibleRegion().toRNRegion()
747
757
  let camera = mapView.camera.toRNCamera()
748
758
 
@@ -750,7 +760,7 @@ GMSIndoorDisplayDelegate {
750
760
  }
751
761
 
752
762
  func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {
753
- if !loaded { return }
763
+ if !mapViewLoaded { return }
754
764
  onMain {
755
765
  self.cameraMoveReasonIsGesture = gesture
756
766
 
@@ -762,7 +772,7 @@ GMSIndoorDisplayDelegate {
762
772
  }
763
773
 
764
774
  func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
765
- if !loaded { return }
775
+ if !mapViewLoaded { return }
766
776
  onMain {
767
777
  let visibleRegion = mapView.projection.visibleRegion().toRNRegion()
768
778
  let camera = mapView.camera.toRNCamera()
@@ -773,7 +783,7 @@ GMSIndoorDisplayDelegate {
773
783
  }
774
784
 
775
785
  func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
776
- if !loaded { return }
786
+ if !mapViewLoaded { return }
777
787
  onMain {
778
788
  let visibleRegion = mapView.projection.visibleRegion().toRNRegion()
779
789
  let camera = mapView.camera.toRNCamera()
@@ -8,7 +8,6 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
8
8
  private let permissionHandler: PermissionHandler
9
9
  private let locationHandler: LocationHandler
10
10
 
11
- private var propsInitialized = false
12
11
  private let markerBuilder = MapMarkerBuilder()
13
12
  private let polylineBuilder = MapPolylineBuilder()
14
13
  private let polygonBuilder = MapPolygonBuilder()
@@ -32,9 +31,13 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
32
31
  }
33
32
 
34
33
  @MainActor
35
- func afterUpdate() {
36
- if !propsInitialized {
37
- propsInitialized = true
34
+ func dispose() {
35
+ impl.deinitInternal()
36
+ }
37
+
38
+ @MainActor
39
+ var initialProps: RNInitialProps? {
40
+ didSet {
38
41
  let options = GMSMapViewOptions()
39
42
  initialProps?.mapId.map { options.mapID = GMSMapID(identifier: $0) }
40
43
  initialProps?.liteMode.map { _ in /* not supported */ }
@@ -44,19 +47,8 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
44
47
  initialProps?.backgroundColor.map {
45
48
  options.backgroundColor = $0.toUIColor()
46
49
  }
47
- impl.initMapView(googleMapOptions: options)
48
- }
49
- }
50
50
 
51
- @MainActor
52
- func dispose() {
53
- impl.deinitInternal()
54
- }
55
-
56
- @MainActor
57
- var initialProps: RNInitialProps? {
58
- didSet {
59
- impl.initialProps = initialProps
51
+ impl.googleMapOptions = options
60
52
  }
61
53
  }
62
54
 
@@ -18,7 +18,7 @@ extension CLLocation {
18
18
  verticalAccuracy: verticalAccuracy,
19
19
  speedAccuracy: speedAccuracy,
20
20
  courseAccuracy: courseAccuracy,
21
- floor: floor.map { Double($0.level)},
21
+ floor: floor.map { Double($0.level) },
22
22
  isFromMockProvider: false,
23
23
  timestamp: timestamp.timeIntervalSince1970 * 1000
24
24
  )
@@ -7,4 +7,3 @@ extension RNLineCapType {
7
7
  }
8
8
  }
9
9
  }
10
-
@@ -6,6 +6,4 @@ extension RNLineJoinType {
6
6
  default: return .miter
7
7
  }
8
8
  }
9
-
10
9
  }
11
-
@@ -90,12 +90,12 @@ extension UIColor {
90
90
  // swiftlint:disable:next large_tuple
91
91
  let (r1, g1, b1): (Double, Double, Double)
92
92
  switch h {
93
- case 0..<60: (r1, g1, b1) = (c, x, 0)
94
- case 60..<120: (r1, g1, b1) = (x, c, 0)
95
- case 120..<180: (r1, g1, b1) = (0, c, x)
96
- case 180..<240: (r1, g1, b1) = (0, x, c)
97
- case 240..<300: (r1, g1, b1) = (x, 0, c)
98
- case 300..<360: (r1, g1, b1) = (c, 0, x)
93
+ case 0 ..< 60: (r1, g1, b1) = (c, x, 0)
94
+ case 60 ..< 120: (r1, g1, b1) = (x, c, 0)
95
+ case 120 ..< 180: (r1, g1, b1) = (0, c, x)
96
+ case 180 ..< 240: (r1, g1, b1) = (0, x, c)
97
+ case 240 ..< 300: (r1, g1, b1) = (x, 0, c)
98
+ case 300 ..< 360: (r1, g1, b1) = (c, 0, x)
99
99
  default: (r1, g1, b1) = (0, 0, 0)
100
100
  }
101
101
  return UIColor(
@@ -1 +1 @@
1
- {"version":3,"names":["getHostComponent","NitroModules","ViewConfig","type","GoogleMapsView","GoogleMapsModule","createHybridObject"],"sourceRoot":"../../src","sources":["GoogleMapsPlus.tsx"],"mappings":";;AAAA,SAASA,gBAAgB,EAAEC,YAAY,QAAQ,4BAA4B;AAE3E,OAAOC,UAAU,MAAM,mEAAmE,QAAQC,IAAI,EAAE,MAAM;AAS9G,OAAO,MAAMC,cAAc,GAAGJ,gBAAgB,CAG5C,sBAAsB,EAAE,MAAME,UAAU,CAAC;AAE3C,OAAO,MAAMG,gBAAgB,GAC3BJ,YAAY,CAACK,kBAAkB,CAC7B,wBACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["getHostComponent","NitroModules","ViewConfig","type","GoogleMapsView","GoogleMapsModule","createHybridObject"],"sourceRoot":"../../src","sources":["GoogleMapsPlus.tsx"],"mappings":";;AAAA,SAASA,gBAAgB,EAAEC,YAAY,QAAQ,4BAA4B;AAE3E,OAAOC,UAAU,MAAM,mEAAmE,QAAQC,IAAI,EAAE,MAAM;AAQ9G,OAAO,MAAMC,cAAc,GAAGJ,gBAAgB,CAG5C,sBAAsB,EAAE,MAAME,UAAU,CAAC;AAE3C,OAAO,MAAMG,gBAAgB,GAC3BJ,YAAY,CAACK,kBAAkB,CAC7B,wBACF,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["GoogleMapsView","GoogleMapsModule"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,cAAc,EAAEC,gBAAgB,QAAQ,kBAAkB;AAOnE,cAAc,SAAS;AAQvB,SAASD,cAAc,EAAEC,gBAAgB","ignoreList":[]}
1
+ {"version":3,"names":["GoogleMapsView","GoogleMapsModule"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,cAAc,EAAEC,gBAAgB,QAAQ,kBAAkB;AAQnE,cAAc,SAAS;AAQvB,SAASD,cAAc,EAAEC,gBAAgB","ignoreList":[]}