react-native-google-maps-plus 1.8.8-dev.1 → 1.10.0-dev.2

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 (57) hide show
  1. package/README.md +0 -2
  2. package/android/build.gradle +0 -21
  3. package/android/gradle.properties +1 -1
  4. package/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt +64 -80
  5. package/android/src/main/java/com/rngooglemapsplus/MapLifecycleEventObserver.kt +78 -0
  6. package/android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt +6 -13
  7. package/android/src/main/java/com/rngooglemapsplus/extensions/RNLatLngBoundsExtension.kt +0 -1
  8. package/android/src/main/java/com/rngooglemapsplus/extensions/ThrowableExtension.kt +2 -0
  9. package/expoConfig/build/index.js +2 -2
  10. package/ios/GoogleMapViewImpl.swift +27 -14
  11. package/ios/LocationHandler.swift +32 -20
  12. package/ios/RNGoogleMapsPlusView.swift +8 -16
  13. package/ios/extensions/CLLocation+Extension.swift +1 -1
  14. package/ios/extensions/RNIOSLocationActivityType+Extensions.swift +18 -0
  15. package/ios/extensions/RNLineCapType+Extension.swift +0 -1
  16. package/ios/extensions/RNLineJoinType+Extension.swift +0 -2
  17. package/ios/extensions/String+Extensions.swift +6 -6
  18. package/lib/module/GoogleMapsPlus.js.map +1 -1
  19. package/lib/module/index.js.map +1 -1
  20. package/lib/module/types.js +8 -0
  21. package/lib/module/types.js.map +1 -1
  22. package/lib/typescript/src/GoogleMapsPlus.d.ts +1 -1
  23. package/lib/typescript/src/GoogleMapsPlus.d.ts.map +1 -1
  24. package/lib/typescript/src/RNGoogleMapsPlusModule.nitro.d.ts.map +1 -1
  25. package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts +1 -1
  26. package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts.map +1 -1
  27. package/lib/typescript/src/index.d.ts +1 -1
  28. package/lib/typescript/src/index.d.ts.map +1 -1
  29. package/lib/typescript/src/types.d.ts +10 -2
  30. package/lib/typescript/src/types.d.ts.map +1 -1
  31. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.cpp +20 -8
  32. package/nitrogen/generated/android/c++/JRNHeatmap.hpp +2 -1
  33. package/nitrogen/generated/android/c++/JRNHeatmapGradient.hpp +2 -1
  34. package/nitrogen/generated/android/c++/JRNIOSLocationActivityType.hpp +68 -0
  35. package/nitrogen/generated/android/c++/JRNIOSLocationConfig.hpp +9 -3
  36. package/nitrogen/generated/android/c++/JRNIndoorBuilding.hpp +2 -1
  37. package/nitrogen/generated/android/c++/JRNLocationConfig.hpp +2 -0
  38. package/nitrogen/generated/android/c++/JRNPolygon.hpp +4 -2
  39. package/nitrogen/generated/android/c++/JRNPolygonHole.hpp +2 -1
  40. package/nitrogen/generated/android/c++/JRNPolyline.hpp +2 -1
  41. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNIOSLocationActivityType.kt +24 -0
  42. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNIOSLocationConfig.kt +6 -3
  43. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Bridge.hpp +18 -0
  44. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Umbrella.hpp +3 -0
  45. package/nitrogen/generated/ios/c++/HybridRNGoogleMapsPlusViewSpecSwift.hpp +3 -0
  46. package/nitrogen/generated/ios/swift/RNIOSLocationActivityType.swift +52 -0
  47. package/nitrogen/generated/ios/swift/RNIOSLocationConfig.swift +24 -1
  48. package/nitrogen/generated/shared/c++/RNIOSLocationActivityType.hpp +65 -0
  49. package/nitrogen/generated/shared/c++/RNIOSLocationConfig.hpp +9 -2
  50. package/package.json +19 -69
  51. package/src/GoogleMapsPlus.tsx +1 -2
  52. package/src/RNGoogleMapsPlusModule.nitro.ts +1 -0
  53. package/src/RNGoogleMapsPlusView.nitro.ts +5 -5
  54. package/src/index.tsx +2 -1
  55. package/src/types.ts +11 -2
  56. package/scripts/create-dev-tag.sh +0 -8
  57. package/scripts/nitrogen-patch.js +0 -191
package/README.md CHANGED
@@ -4,8 +4,6 @@
4
4
  [![Dev Release](https://img.shields.io/npm/v/react-native-google-maps-plus/dev.svg?label=dev%20release&color=orange)](https://www.npmjs.com/package/react-native-google-maps-plus)
5
5
  [![Build](https://github.com/pinpong/react-native-google-maps-plus/actions/workflows/release.yml/badge.svg)](https://github.com/pinpong/react-native-google-maps-plus/actions/workflows/release.yml)
6
6
  ![React Native](https://img.shields.io/badge/react--native-%3E%3D0.81.0-61dafb.svg?logo=react)
7
- ![Platform: Android](https://img.shields.io/badge/android-supported-brightgreen.svg?logo=android&logoColor=white)
8
- ![Platform: iOS](https://img.shields.io/badge/ios-supported-lightgrey.svg?logo=apple&logoColor=black)
9
7
 
10
8
  React Native wrapper for Android & iOS Google Maps SDK.
11
9
 
@@ -70,27 +70,6 @@ android {
70
70
  }
71
71
  }
72
72
 
73
- packagingOptions {
74
- excludes = [
75
- "META-INF",
76
- "META-INF/**",
77
- "**/libc++_shared.so",
78
- "**/libfbjni.so",
79
- "**/libjsi.so",
80
- "**/libfolly_json.so",
81
- "**/libfolly_runtime.so",
82
- "**/libglog.so",
83
- "**/libhermes.so",
84
- "**/libhermes-executor-debug.so",
85
- "**/libhermes_executor.so",
86
- "**/libreactnative.so",
87
- "**/libreactnativejni.so",
88
- "**/libturbomodulejsijni.so",
89
- "**/libreact_nativemodule_core.so",
90
- "**/libjscexecutor.so"
91
- ]
92
- }
93
-
94
73
  buildFeatures {
95
74
  buildConfig true
96
75
  prefab true
@@ -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,10 @@ 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
848
+ mapViewInitialized = false
853
849
  }
854
850
 
855
851
  override fun requestLayout() {
@@ -864,32 +860,20 @@ class GoogleMapsViewImpl(
864
860
  }
865
861
  }
866
862
 
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()
863
+ override fun onAttachedToWindow() {
864
+ super.onAttachedToWindow()
865
+ initMapView()
866
+ lifecycle = mapView?.findViewTreeLifecycleOwner()?.lifecycle
867
+ lifecycleObserver?.let { observer ->
868
+ lifecycle?.addObserver(observer)
889
869
  }
870
+ }
890
871
 
891
- override fun onHostDestroy() {
892
- destroyInternal()
872
+ override fun onDetachedFromWindow() {
873
+ super.onDetachedFromWindow()
874
+ lifecycleObserver?.let { lifecycle?.removeObserver(it) }
875
+ lifecycle = null
876
+ lifecycleObserver?.toCreatedState()
893
877
  }
894
878
 
895
879
  override fun onMarkerClick(marker: Marker): Boolean {
@@ -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);
@@ -1,8 +1,8 @@
1
1
  import CoreLocation
2
2
  import GoogleMaps
3
3
  import GoogleMapsUtils
4
- import UIKit
5
4
  import NitroModules
5
+ import UIKit
6
6
 
7
7
  final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate,
8
8
  GMSIndoorDisplayDelegate {
@@ -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,12 +83,20 @@ 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) {
99
+ func initMapView() {
88
100
  if initialized { return }
89
101
  initialized = true
90
102
  googleMapOptions.frame = bounds
@@ -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? {
@@ -273,10 +282,12 @@ GMSIndoorDisplayDelegate {
273
282
  @MainActor
274
283
  var locationConfig: RNLocationConfig? {
275
284
  didSet {
276
- locationHandler.desiredAccuracy =
277
- locationConfig?.ios?.desiredAccuracy?.toCLLocationAccuracy
278
- locationHandler.distanceFilterMeters =
279
- locationConfig?.ios?.distanceFilterMeters
285
+ locationHandler.updateConfig(
286
+ desiredAccuracy: locationConfig?.ios?.desiredAccuracy?
287
+ .toCLLocationAccuracy,
288
+ distanceFilterMeters: locationConfig?.ios?.distanceFilterMeters,
289
+ activityType: locationConfig?.ios?.activityType?.toCLActivityType,
290
+ )
280
291
  }
281
292
  }
282
293
 
@@ -691,6 +702,7 @@ GMSIndoorDisplayDelegate {
691
702
  func deinitInternal() {
692
703
  guard !deInitialized else { return }
693
704
  deInitialized = true
705
+ detachLifecycleObservers()
694
706
  onMain {
695
707
  self.locationHandler.stop()
696
708
  self.markerBuilder.cancelAllIconTasks()
@@ -726,16 +738,17 @@ GMSIndoorDisplayDelegate {
726
738
  override func didMoveToWindow() {
727
739
  super.didMoveToWindow()
728
740
  if window != nil {
741
+ attachLifecycleObservers()
729
742
  locationHandler.start()
743
+ initMapView()
730
744
  } else {
731
745
  locationHandler.stop()
746
+ detachLifecycleObservers()
732
747
  }
733
748
  }
734
749
 
735
750
  deinit {
736
751
  deinitInternal()
737
- lifecycleTasks.forEach { $0.cancel() }
738
- lifecycleTasks.removeAll()
739
752
  }
740
753
 
741
754
  func mapViewDidFinishTileRendering(_ mapView: GMSMapView) {
@@ -6,22 +6,19 @@ private let kCLLocationAccuracyDefault: CLLocationAccuracy =
6
6
  kCLLocationAccuracyBest
7
7
  private let kCLDistanceFilterNoneDefault: CLLocationDistance =
8
8
  kCLDistanceFilterNone
9
+ private let kCLActivityTypeDefault: CLActivityType = .other
9
10
 
10
11
  final class LocationHandler: NSObject, CLLocationManagerDelegate {
11
12
 
12
13
  private let manager = CLLocationManager()
13
14
 
14
- var desiredAccuracy: CLLocationAccuracy? = kCLLocationAccuracyDefault {
15
- didSet {
16
- manager.desiredAccuracy = desiredAccuracy ?? kCLLocationAccuracyBest
17
- }
18
- }
15
+ private var isActive = false
19
16
 
20
- var distanceFilterMeters: CLLocationDistance? = kCLDistanceFilterNoneDefault {
21
- didSet {
22
- manager.distanceFilter = distanceFilterMeters ?? kCLDistanceFilterNone
23
- }
24
- }
17
+ private var currentDesiredAccuracy: CLLocationAccuracy =
18
+ kCLLocationAccuracyDefault
19
+ private var currentDistanceFilter: CLLocationDistance =
20
+ kCLDistanceFilterNoneDefault
21
+ private var currentActivityType: CLActivityType = kCLActivityTypeDefault
25
22
 
26
23
  var onUpdate: ((CLLocation) -> Void)?
27
24
  var onError: ((_ error: RNLocationErrorCode) -> Void)?
@@ -30,7 +27,21 @@ final class LocationHandler: NSObject, CLLocationManagerDelegate {
30
27
  super.init()
31
28
  manager.delegate = self
32
29
  manager.pausesLocationUpdatesAutomatically = true
33
- manager.activityType = .other
30
+ }
31
+
32
+ func updateConfig(
33
+ desiredAccuracy: CLLocationAccuracy?,
34
+ distanceFilterMeters: CLLocationDistance?,
35
+ activityType: CLActivityType?
36
+ ) {
37
+ currentDesiredAccuracy = desiredAccuracy ?? kCLLocationAccuracyDefault
38
+ manager.desiredAccuracy = currentDesiredAccuracy
39
+
40
+ currentDistanceFilter = distanceFilterMeters ?? kCLDistanceFilterNoneDefault
41
+ manager.distanceFilter = currentDistanceFilter
42
+
43
+ currentActivityType = activityType ?? kCLActivityTypeDefault
44
+ manager.activityType = currentActivityType
34
45
  }
35
46
 
36
47
  func showLocationDialog() {
@@ -71,11 +82,19 @@ final class LocationHandler: NSObject, CLLocationManagerDelegate {
71
82
  }
72
83
 
73
84
  func start() {
74
- stop()
75
- startUpdates()
85
+ guard !isActive else { return }
86
+ isActive = true
87
+
88
+ manager.location.map {
89
+ onUpdate?($0)
90
+ }
91
+
92
+ manager.startUpdatingLocation()
76
93
  }
77
94
 
78
95
  func stop() {
96
+ guard isActive else { return }
97
+ isActive = false
79
98
  manager.stopUpdatingLocation()
80
99
  }
81
100
 
@@ -104,13 +123,6 @@ final class LocationHandler: NSObject, CLLocationManagerDelegate {
104
123
  }
105
124
  }
106
125
 
107
- private func startUpdates() {
108
- manager.desiredAccuracy = desiredAccuracy ?? kCLLocationAccuracyDefault
109
- manager.distanceFilter =
110
- distanceFilterMeters ?? kCLDistanceFilterNoneDefault
111
- manager.startUpdatingLocation()
112
- }
113
-
114
126
  func locationManager(
115
127
  _ manager: CLLocationManager,
116
128
  didFailWithError error: Error
@@ -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