react-native-google-maps-plus 1.7.0-dev.5 → 1.7.0-dev.7

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/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt +336 -494
  2. package/android/src/main/java/com/rngooglemapsplus/LocationHandler.kt +3 -8
  3. package/android/src/main/java/com/rngooglemapsplus/MapCircleBuilder.kt +2 -1
  4. package/android/src/main/java/com/rngooglemapsplus/MapHelper.kt +22 -0
  5. package/android/src/main/java/com/rngooglemapsplus/MapMarkerBuilder.kt +4 -2
  6. package/android/src/main/java/com/rngooglemapsplus/MapPolygonBuilder.kt +2 -1
  7. package/android/src/main/java/com/rngooglemapsplus/MapPolylineBuilder.kt.kt +2 -1
  8. package/android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt +10 -21
  9. package/android/src/main/java/com/rngooglemapsplus/extensions/LatLngBoundsExtension.kt +10 -0
  10. package/android/src/main/java/com/rngooglemapsplus/extensions/RNLatLngBoundsExtension.kt +2 -8
  11. package/android/src/main/java/com/rngooglemapsplus/extensions/VisibleRegionExtension.kt +13 -0
  12. package/ios/GoogleMapViewImpl.swift +14 -26
  13. package/ios/MapCircleBuilder.swift +2 -0
  14. package/ios/MapHeatmapBuilder.swift +1 -0
  15. package/ios/MapMarkerBuilder.swift +4 -0
  16. package/ios/MapPolygonBuilder.swift +2 -0
  17. package/ios/MapPolylineBuilder.swift +2 -0
  18. package/ios/MapUrlTileOverlayBuilder.swift +1 -0
  19. package/ios/extensions/GMSCoordinateBounds+Extension.swift +4 -13
  20. package/ios/extensions/GMSVisibleRegion+Extension.swift +14 -0
  21. package/ios/extensions/RNLatLngBounds+Extension.swift +4 -4
  22. package/lib/module/types.js.map +1 -1
  23. package/lib/typescript/src/types.d.ts +7 -5
  24. package/lib/typescript/src/types.d.ts.map +1 -1
  25. package/nitrogen/generated/android/c++/JFunc_void_RNRegion_RNCamera_bool.hpp +2 -0
  26. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.cpp +4 -4
  27. package/nitrogen/generated/android/c++/JRNLatLngBounds.hpp +8 -8
  28. package/nitrogen/generated/android/c++/JRNRegion.hpp +23 -13
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNLatLngBounds.kt +4 -4
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNRegion.kt +11 -5
  31. package/nitrogen/generated/ios/swift/RNLatLngBounds.swift +8 -8
  32. package/nitrogen/generated/ios/swift/RNRegion.swift +33 -11
  33. package/nitrogen/generated/shared/c++/RNLatLngBounds.hpp +9 -9
  34. package/nitrogen/generated/shared/c++/RNRegion.hpp +24 -13
  35. package/package.json +1 -1
  36. package/src/types.ts +7 -5
  37. package/android/src/main/java/com/rngooglemapsplus/extensions/LatLngBounds.kt +0 -15
  38. /package/android/src/main/java/com/rngooglemapsplus/extensions/{RNSize.kt → RNSizeExtension.kt} +0 -0
  39. /package/android/src/main/java/com/rngooglemapsplus/extensions/{RNSnapshotFormat.kt → RNSnapshotFormatExtension.kt} +0 -0
  40. /package/android/src/main/java/com/rngooglemapsplus/extensions/{RNSnapshotResultType.kt → RNSnapshotResultTypeExtension.kt} +0 -0
@@ -8,7 +8,6 @@ import android.util.Size
8
8
  import android.widget.FrameLayout
9
9
  import androidx.core.graphics.scale
10
10
  import com.facebook.react.bridge.LifecycleEventListener
11
- import com.facebook.react.bridge.UiThreadUtil
12
11
  import com.facebook.react.uimanager.PixelUtil.dpToPx
13
12
  import com.facebook.react.uimanager.ThemedReactContext
14
13
  import com.google.android.gms.maps.CameraUpdateFactory
@@ -34,6 +33,8 @@ import com.google.android.gms.maps.model.TileOverlay
34
33
  import com.google.android.gms.maps.model.TileOverlayOptions
35
34
  import com.google.maps.android.data.kml.KmlLayer
36
35
  import com.margelo.nitro.core.Promise
36
+ import com.rngooglemapsplus.extensions.onUi
37
+ import com.rngooglemapsplus.extensions.onUiSync
37
38
  import com.rngooglemapsplus.extensions.toGooglePriority
38
39
  import com.rngooglemapsplus.extensions.toLatLng
39
40
  import com.rngooglemapsplus.extensions.toLocationErrorCode
@@ -96,117 +97,100 @@ class GoogleMapsViewImpl(
96
97
  private val urlTileOverlaysById = mutableMapOf<String, TileOverlay>()
97
98
 
98
99
  private var cameraMoveReason = -1
99
- private var lastSubmittedCameraPosition: CameraPosition? = null
100
100
 
101
101
  init {
102
102
  reactContext.addLifecycleEventListener(this)
103
103
  }
104
104
 
105
- fun initMapView(googleMapsOptions: GoogleMapOptions) {
106
- if (initialized) return
107
- initialized = true
108
- val result = playServiceHandler.playServicesAvailability()
109
- val errorCode = result.toRNMapErrorCodeOrNull()
105
+ fun initMapView(googleMapsOptions: GoogleMapOptions) =
106
+ onUi {
107
+ if (initialized) return@onUi
108
+ initialized = true
110
109
 
111
- if (errorCode != null) {
112
- onMapError?.invoke(errorCode)
110
+ val result = playServiceHandler.playServicesAvailability()
111
+ val errorCode = result.toRNMapErrorCodeOrNull()
112
+ if (errorCode != null) {
113
+ onMapError?.invoke(errorCode)
114
+ if (errorCode == RNMapErrorCode.PLAY_SERVICES_MISSING ||
115
+ errorCode == RNMapErrorCode.PLAY_SERVICES_INVALID
116
+ ) {
117
+ return@onUi
118
+ }
119
+ }
113
120
 
114
- if (errorCode == RNMapErrorCode.PLAY_SERVICES_MISSING ||
115
- errorCode == RNMapErrorCode.PLAY_SERVICES_INVALID
116
- ) {
117
- return
121
+ mapView = MapView(reactContext, googleMapsOptions)
122
+ super.addView(mapView)
123
+
124
+ mapView?.onCreate(null)
125
+ mapView?.getMapAsync { map ->
126
+ googleMap = map
127
+ googleMap?.setOnMapLoadedCallback {
128
+ googleMap?.setOnCameraMoveStartedListener(this@GoogleMapsViewImpl)
129
+ googleMap?.setOnCameraMoveListener(this@GoogleMapsViewImpl)
130
+ googleMap?.setOnCameraIdleListener(this@GoogleMapsViewImpl)
131
+ googleMap?.setOnMarkerClickListener(this@GoogleMapsViewImpl)
132
+ googleMap?.setOnPolylineClickListener(this@GoogleMapsViewImpl)
133
+ googleMap?.setOnPolygonClickListener(this@GoogleMapsViewImpl)
134
+ googleMap?.setOnCircleClickListener(this@GoogleMapsViewImpl)
135
+ googleMap?.setOnMapClickListener(this@GoogleMapsViewImpl)
136
+ googleMap?.setOnMapLongClickListener(this@GoogleMapsViewImpl)
137
+ googleMap?.setOnPoiClickListener(this@GoogleMapsViewImpl)
138
+ googleMap?.setOnMarkerDragListener(this@GoogleMapsViewImpl)
139
+ googleMap?.setOnInfoWindowClickListener(this@GoogleMapsViewImpl)
140
+ googleMap?.setOnInfoWindowCloseListener(this@GoogleMapsViewImpl)
141
+ googleMap?.setOnInfoWindowLongClickListener(this@GoogleMapsViewImpl)
142
+ googleMap?.setOnMyLocationClickListener(this@GoogleMapsViewImpl)
143
+ googleMap?.setOnMyLocationButtonClickListener(this@GoogleMapsViewImpl)
144
+ onMapLoaded?.invoke(true)
145
+ }
146
+ applyProps()
147
+ initLocationCallbacks()
148
+ onMapReady?.invoke(true)
118
149
  }
119
150
  }
120
151
 
121
- mapView =
122
- MapView(
123
- reactContext,
124
- googleMapsOptions,
152
+ override fun onCameraMoveStarted(reason: Int) =
153
+ onUi {
154
+ cameraMoveReason = reason
155
+ val visibleRegion = googleMap?.projection?.visibleRegion ?: return@onUi
156
+ val cameraPosition = googleMap?.cameraPosition ?: return@onUi
157
+ onCameraChangeStart?.invoke(
158
+ visibleRegion.toRnRegion(),
159
+ cameraPosition.toRnCamera(),
160
+ GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == reason,
125
161
  )
126
-
127
- super.addView(mapView)
128
-
129
- mapView?.onCreate(null)
130
- mapView?.getMapAsync { map ->
131
- googleMap = map
132
- googleMap?.setOnMapLoadedCallback {
133
- googleMap?.setOnCameraMoveStartedListener(this@GoogleMapsViewImpl)
134
- googleMap?.setOnCameraMoveListener(this@GoogleMapsViewImpl)
135
- googleMap?.setOnCameraIdleListener(this@GoogleMapsViewImpl)
136
- googleMap?.setOnMarkerClickListener(this@GoogleMapsViewImpl)
137
- googleMap?.setOnPolylineClickListener(this@GoogleMapsViewImpl)
138
- googleMap?.setOnPolygonClickListener(this@GoogleMapsViewImpl)
139
- googleMap?.setOnCircleClickListener(this@GoogleMapsViewImpl)
140
- googleMap?.setOnMapClickListener(this@GoogleMapsViewImpl)
141
- googleMap?.setOnMapLongClickListener(this@GoogleMapsViewImpl)
142
- googleMap?.setOnPoiClickListener(this@GoogleMapsViewImpl)
143
- googleMap?.setOnMarkerDragListener(this@GoogleMapsViewImpl)
144
- googleMap?.setOnInfoWindowClickListener(this@GoogleMapsViewImpl)
145
- googleMap?.setOnInfoWindowCloseListener(this@GoogleMapsViewImpl)
146
- googleMap?.setOnInfoWindowLongClickListener(this@GoogleMapsViewImpl)
147
- googleMap?.setOnMyLocationClickListener(this@GoogleMapsViewImpl)
148
- googleMap?.setOnMyLocationButtonClickListener(this@GoogleMapsViewImpl)
149
- onMapLoaded?.invoke(true)
150
- }
151
- applyProps()
152
- initLocationCallbacks()
153
- onMapReady?.invoke(true)
154
162
  }
155
- }
156
163
 
157
- override fun onCameraMoveStarted(reason: Int) {
158
- lastSubmittedCameraPosition = null
159
- cameraMoveReason = reason
160
- val bounds = googleMap?.projection?.visibleRegion?.latLngBounds ?: return
161
- val cameraPosition = googleMap?.cameraPosition ?: return
162
-
163
- val isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == reason
164
-
165
- onCameraChangeStart?.invoke(
166
- bounds.toRnRegion(),
167
- cameraPosition.toRnCamera(),
168
- isGesture,
169
- )
170
- }
171
-
172
- override fun onCameraMove() {
173
- val bounds = googleMap?.projection?.visibleRegion?.latLngBounds ?: return
174
- val cameraPosition = googleMap?.cameraPosition ?: return
175
-
176
- if (cameraPosition == lastSubmittedCameraPosition) {
177
- return
164
+ override fun onCameraMove() =
165
+ onUi {
166
+ val visibleRegion = googleMap?.projection?.visibleRegion ?: return@onUi
167
+ val cameraPosition = googleMap?.cameraPosition ?: return@onUi
168
+ val gesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason
169
+ onCameraChange?.invoke(
170
+ visibleRegion.toRnRegion(),
171
+ cameraPosition.toRnCamera(),
172
+ gesture,
173
+ )
178
174
  }
179
- lastSubmittedCameraPosition = cameraPosition
180
175
 
181
- val isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason
182
-
183
- onCameraChange?.invoke(
184
- bounds.toRnRegion(),
185
- cameraPosition.toRnCamera(),
186
- isGesture,
187
- )
188
- }
189
-
190
- override fun onCameraIdle() {
191
- val bounds = googleMap?.projection?.visibleRegion?.latLngBounds ?: return
192
- val cameraPosition = googleMap?.cameraPosition ?: return
193
-
194
- val isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason
195
-
196
- onCameraChangeComplete?.invoke(
197
- bounds.toRnRegion(),
198
- cameraPosition.toRnCamera(),
199
- isGesture,
200
- )
201
- }
176
+ override fun onCameraIdle() =
177
+ onUi {
178
+ val visibleRegion = googleMap?.projection?.visibleRegion ?: return@onUi
179
+ val cameraPosition = googleMap?.cameraPosition ?: return@onUi
180
+ val gesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason
181
+ onCameraChangeComplete?.invoke(
182
+ visibleRegion.toRnRegion(),
183
+ cameraPosition.toRnCamera(),
184
+ gesture,
185
+ )
186
+ }
202
187
 
203
188
  fun initLocationCallbacks() {
204
189
  locationHandler.onUpdate = { location ->
205
- onLocationUpdate?.invoke(location.toRnLocation())
190
+ onUi { onLocationUpdate?.invoke(location.toRnLocation()) }
206
191
  }
207
-
208
192
  locationHandler.onError = { error ->
209
- onLocationError?.invoke(error)
193
+ onUi { onLocationError?.invoke(error) }
210
194
  }
211
195
  locationHandler.start()
212
196
  }
@@ -225,57 +209,37 @@ class GoogleMapsViewImpl(
225
209
  locationConfig = locationConfig
226
210
 
227
211
  if (pendingMarkers.isNotEmpty()) {
228
- pendingMarkers.forEach { (id, opts) ->
229
- internalAddMarker(id, opts)
230
- }
212
+ pendingMarkers.forEach { (id, opts) -> internalAddMarker(id, opts) }
231
213
  pendingMarkers.clear()
232
214
  }
233
-
234
215
  if (pendingPolylines.isNotEmpty()) {
235
- pendingPolylines.forEach { (id, opts) ->
236
- internalAddPolyline(id, opts)
237
- }
216
+ pendingPolylines.forEach { (id, opts) -> internalAddPolyline(id, opts) }
238
217
  pendingPolylines.clear()
239
218
  }
240
-
241
219
  if (pendingPolygons.isNotEmpty()) {
242
- pendingPolygons.forEach { (id, opts) ->
243
- internalAddPolygon(id, opts)
244
- }
220
+ pendingPolygons.forEach { (id, opts) -> internalAddPolygon(id, opts) }
245
221
  pendingPolygons.clear()
246
222
  }
247
-
248
223
  if (pendingCircles.isNotEmpty()) {
249
- pendingCircles.forEach { (id, opts) ->
250
- internalAddCircle(id, opts)
251
- }
224
+ pendingCircles.forEach { (id, opts) -> internalAddCircle(id, opts) }
252
225
  pendingCircles.clear()
253
226
  }
254
-
255
227
  if (pendingHeatmaps.isNotEmpty()) {
256
- pendingHeatmaps.forEach { (id, opts) ->
257
- internalAddHeatmap(id, opts)
258
- }
228
+ pendingHeatmaps.forEach { (id, opts) -> internalAddHeatmap(id, opts) }
259
229
  pendingHeatmaps.clear()
260
230
  }
261
-
262
231
  if (pendingKmlLayers.isNotEmpty()) {
263
- pendingKmlLayers.forEach { (id, string) ->
264
- internalAddKmlLayer(id, string)
265
- }
232
+ pendingKmlLayers.forEach { (id, str) -> internalAddKmlLayer(id, str) }
266
233
  pendingKmlLayers.clear()
267
234
  }
268
-
269
235
  if (pendingUrlTilesOverlays.isNotEmpty()) {
270
- pendingUrlTilesOverlays.forEach { (id, string) ->
271
- internalAddUrlTileOverlay(id, string)
272
- }
236
+ pendingUrlTilesOverlays.forEach { (id, opts) -> internalAddUrlTileOverlay(id, opts) }
273
237
  pendingUrlTilesOverlays.clear()
274
238
  }
275
239
  }
276
240
 
277
241
  val currentCamera: CameraPosition?
278
- get() = googleMap?.cameraPosition
242
+ get() = onUiSync { googleMap?.cameraPosition }
279
243
 
280
244
  var initialProps: RNInitialProps? = null
281
245
 
@@ -311,8 +275,8 @@ class GoogleMapsViewImpl(
311
275
  onUi {
312
276
  try {
313
277
  googleMap?.isMyLocationEnabled = value ?: false
314
- } catch (se: SecurityException) {
315
- onLocationError?.invoke(RNLocationErrorCode.PERMISSION_DENIED)
278
+ } catch (_: SecurityException) {
279
+ onLocationError?.let { cb -> cb(RNLocationErrorCode.PERMISSION_DENIED) }
316
280
  } catch (ex: Exception) {
317
281
  val error = ex.toLocationErrorCode(context)
318
282
  onLocationError?.invoke(error)
@@ -323,41 +287,31 @@ class GoogleMapsViewImpl(
323
287
  var buildingEnabled: Boolean? = null
324
288
  set(value) {
325
289
  field = value
326
- onUi {
327
- googleMap?.isBuildingsEnabled = value ?: false
328
- }
290
+ onUi { googleMap?.isBuildingsEnabled = value ?: false }
329
291
  }
330
292
 
331
293
  var trafficEnabled: Boolean? = null
332
294
  set(value) {
333
295
  field = value
334
- onUi {
335
- googleMap?.isTrafficEnabled = value ?: false
336
- }
296
+ onUi { googleMap?.isTrafficEnabled = value ?: false }
337
297
  }
338
298
 
339
299
  var indoorEnabled: Boolean? = null
340
300
  set(value) {
341
301
  field = value
342
- onUi {
343
- googleMap?.isIndoorEnabled = value ?: false
344
- }
302
+ onUi { googleMap?.isIndoorEnabled = value ?: false }
345
303
  }
346
304
 
347
305
  var customMapStyle: MapStyleOptions? = null
348
306
  set(value) {
349
307
  field = value
350
- onUi {
351
- googleMap?.setMapStyle(value)
352
- }
308
+ onUi { googleMap?.setMapStyle(value) }
353
309
  }
354
310
 
355
311
  var userInterfaceStyle: Int? = null
356
312
  set(value) {
357
313
  field = value
358
- onUi {
359
- googleMap?.mapColorScheme = value ?: MapColorScheme.FOLLOW_SYSTEM
360
- }
314
+ onUi { googleMap?.mapColorScheme = value ?: MapColorScheme.FOLLOW_SYSTEM }
361
315
  }
362
316
 
363
317
  var mapZoomConfig: RNMapZoomConfig? = null
@@ -385,9 +339,7 @@ class GoogleMapsViewImpl(
385
339
  var mapType: Int? = null
386
340
  set(value) {
387
341
  field = value
388
- onUi {
389
- googleMap?.mapType = value ?: 1
390
- }
342
+ onUi { googleMap?.mapType = value ?: 1 }
391
343
  }
392
344
 
393
345
  var locationConfig: RNLocationConfig? = null
@@ -430,15 +382,12 @@ class GoogleMapsViewImpl(
430
382
  cameraPosition: CameraPosition,
431
383
  animated: Boolean,
432
384
  durationMs: Int,
433
- ) {
434
- onUi {
435
- val update = CameraUpdateFactory.newCameraPosition(cameraPosition)
436
-
437
- if (animated) {
438
- googleMap?.animateCamera(update, durationMs, null)
439
- } else {
440
- googleMap?.moveCamera(update)
441
- }
385
+ ) = onUi {
386
+ val update = CameraUpdateFactory.newCameraPosition(cameraPosition)
387
+ if (animated) {
388
+ googleMap?.animateCamera(update, durationMs, null)
389
+ } else {
390
+ googleMap?.moveCamera(update)
442
391
  }
443
392
  }
444
393
 
@@ -447,93 +396,81 @@ class GoogleMapsViewImpl(
447
396
  padding: RNMapPadding,
448
397
  animated: Boolean,
449
398
  durationMs: Int,
450
- ) {
451
- if (coordinates.isEmpty()) {
452
- return
453
- }
454
- onUi {
455
- val builder = LatLngBounds.Builder()
456
- coordinates.forEach { coord ->
457
- builder.include(coord.toLatLng())
458
- }
459
- val bounds = builder.build()
460
-
461
- val latSpan = bounds.northeast.latitude - bounds.southwest.latitude
462
- val lngSpan = bounds.northeast.longitude - bounds.southwest.longitude
463
-
464
- val latPerPixel = latSpan / (mapView?.height ?: 0)
465
- val lngPerPixel = lngSpan / (mapView?.width ?: 0)
399
+ ) = onUi {
400
+ if (coordinates.isEmpty()) return@onUi
401
+ val builder = LatLngBounds.Builder()
402
+ coordinates.forEach { coord -> builder.include(coord.toLatLng()) }
403
+ val bounds = builder.build()
404
+
405
+ val latSpan = bounds.northeast.latitude - bounds.southwest.latitude
406
+ val lngSpan = bounds.northeast.longitude - bounds.southwest.longitude
407
+
408
+ val h = (mapView?.height ?: 0)
409
+ val w = (mapView?.width ?: 0)
410
+ val latPerPixel = if (h != 0) latSpan / h else 0.0
411
+ val lngPerPixel = if (w != 0) lngSpan / w else 0.0
412
+
413
+ builder.include(
414
+ LatLng(
415
+ bounds.northeast.latitude + (padding.top.dpToPx() * latPerPixel),
416
+ bounds.northeast.longitude,
417
+ ),
418
+ )
419
+ builder.include(
420
+ LatLng(
421
+ bounds.southwest.latitude - (padding.bottom.dpToPx() * latPerPixel),
422
+ bounds.southwest.longitude,
423
+ ),
424
+ )
425
+ builder.include(
426
+ LatLng(
427
+ bounds.northeast.latitude,
428
+ bounds.northeast.longitude + (padding.right.dpToPx() * lngPerPixel),
429
+ ),
430
+ )
431
+ builder.include(
432
+ LatLng(
433
+ bounds.southwest.latitude,
434
+ bounds.southwest.longitude - (padding.left.dpToPx() * lngPerPixel),
435
+ ),
436
+ )
466
437
 
467
- builder.include(
468
- LatLng(
469
- bounds.northeast.latitude + (padding.top.dpToPx() * latPerPixel),
470
- bounds.northeast.longitude,
471
- ),
472
- )
473
- builder.include(
474
- LatLng(
475
- bounds.southwest.latitude - (padding.bottom.dpToPx() * latPerPixel),
476
- bounds.southwest.longitude,
477
- ),
478
- )
479
- builder.include(
480
- LatLng(
481
- bounds.northeast.latitude,
482
- bounds.northeast.longitude + (padding.right.dpToPx() * lngPerPixel),
483
- ),
484
- )
485
- builder.include(
486
- LatLng(
487
- bounds.southwest.latitude,
488
- bounds.southwest.longitude - (padding.left.dpToPx() * lngPerPixel),
489
- ),
438
+ val paddedBounds = builder.build()
439
+ val adjustedWidth =
440
+ (w - padding.left.dpToPx() - padding.right.dpToPx()).toInt().coerceAtLeast(0)
441
+ val adjustedHeight =
442
+ (h - padding.top.dpToPx() - padding.bottom.dpToPx()).toInt().coerceAtLeast(0)
443
+
444
+ val update =
445
+ CameraUpdateFactory.newLatLngBounds(
446
+ paddedBounds,
447
+ adjustedWidth,
448
+ adjustedHeight,
449
+ 0,
490
450
  )
491
-
492
- val paddedBounds = builder.build()
493
-
494
- val adjustedWidth =
495
- ((mapView?.width ?: 0) - padding.left.dpToPx() - padding.right.dpToPx()).toInt()
496
- val adjustedHeight =
497
- ((mapView?.height ?: 0) - padding.top.dpToPx() - padding.bottom.dpToPx()).toInt()
498
-
499
- val update =
500
- CameraUpdateFactory.newLatLngBounds(
501
- paddedBounds,
502
- adjustedWidth,
503
- adjustedHeight,
504
- 0,
505
- )
506
- if (animated) {
507
- googleMap?.animateCamera(update, durationMs, null)
508
- } else {
509
- googleMap?.moveCamera(update)
510
- }
451
+ if (animated) {
452
+ googleMap?.animateCamera(update, durationMs, null)
453
+ } else {
454
+ googleMap?.moveCamera(update)
511
455
  }
512
456
  }
513
457
 
514
- fun setCameraBounds(bounds: LatLngBounds?) {
458
+ fun setCameraBounds(bounds: LatLngBounds?) =
515
459
  onUi {
516
460
  googleMap?.setLatLngBoundsForCameraTarget(bounds)
517
461
  }
518
- }
519
462
 
520
463
  fun animateToBounds(
521
464
  bounds: LatLngBounds,
522
465
  padding: Int,
523
466
  durationMs: Int,
524
467
  lockBounds: Boolean,
525
- ) {
526
- onUi {
527
- if (lockBounds) {
528
- googleMap?.setLatLngBoundsForCameraTarget(bounds)
529
- }
530
- val update =
531
- CameraUpdateFactory.newLatLngBounds(
532
- bounds,
533
- padding,
534
- )
535
- googleMap?.animateCamera(update, durationMs, null)
468
+ ) = onUi {
469
+ if (lockBounds) {
470
+ googleMap?.setLatLngBoundsForCameraTarget(bounds)
536
471
  }
472
+ val update = CameraUpdateFactory.newLatLngBounds(bounds, padding)
473
+ googleMap?.animateCamera(update, durationMs, null)
537
474
  }
538
475
 
539
476
  fun snapshot(
@@ -551,12 +488,7 @@ class GoogleMapsViewImpl(
551
488
  promise.resolve(null)
552
489
  return@snapshot
553
490
  }
554
-
555
- val scaledBitmap =
556
- size?.let {
557
- bitmap.scale(it.width, it.height)
558
- } ?: bitmap
559
-
491
+ val scaledBitmap = size?.let { bitmap.scale(it.width, it.height) } ?: bitmap
560
492
  val output = ByteArrayOutputStream()
561
493
  scaledBitmap.compress(compressFormat, (quality * 100).toInt().coerceIn(0, 100), output)
562
494
  val bytes = output.toByteArray()
@@ -570,367 +502,282 @@ class GoogleMapsViewImpl(
570
502
  promise.resolve("data:image/$format;base64,$base64")
571
503
  }
572
504
 
573
- if (scaledBitmap != bitmap) {
574
- scaledBitmap.recycle()
575
- }
505
+ if (scaledBitmap !== bitmap) scaledBitmap.recycle()
576
506
  bitmap.recycle()
577
- } catch (e: Exception) {
507
+ } catch (_: Exception) {
578
508
  promise.resolve(null)
579
509
  }
580
510
  }
581
511
  }
582
-
583
512
  return promise
584
513
  }
585
514
 
586
515
  fun addMarker(
587
516
  id: String,
588
517
  opts: MarkerOptions,
589
- ) {
518
+ ) = onUi {
590
519
  if (googleMap == null) {
591
520
  pendingMarkers.add(id to opts)
592
- return
593
- }
594
-
595
- onUi {
596
- markersById.remove(id)?.remove()
521
+ return@onUi
597
522
  }
523
+ markersById.remove(id)?.remove()
598
524
  internalAddMarker(id, opts)
599
525
  }
600
526
 
601
527
  private fun internalAddMarker(
602
528
  id: String,
603
529
  opts: MarkerOptions,
604
- ) {
605
- onUi {
606
- val marker =
607
- googleMap?.addMarker(opts).also {
608
- it?.tag = id
609
- }
610
- if (marker != null) {
611
- markersById[id] = marker
612
- }
613
- }
530
+ ) = onUi {
531
+ val marker = googleMap?.addMarker(opts).also { it?.tag = id }
532
+ if (marker != null) markersById[id] = marker
614
533
  }
615
534
 
616
535
  fun updateMarker(
617
536
  id: String,
618
537
  block: (Marker) -> Unit,
619
- ) {
620
- val marker = markersById[id] ?: return
621
- onUi {
622
- block(marker)
623
- }
538
+ ) = onUi {
539
+ val marker = markersById[id] ?: return@onUi
540
+ block(marker)
624
541
  }
625
542
 
626
- fun removeMarker(id: String) {
543
+ fun removeMarker(id: String) =
627
544
  onUi {
628
- val marker = markersById.remove(id)
629
- marker?.remove()
545
+ markersById.remove(id)?.remove()
630
546
  }
631
- }
632
547
 
633
- fun clearMarkers() {
548
+ fun clearMarkers() =
634
549
  onUi {
635
550
  markersById.values.forEach { it.remove() }
551
+ markersById.clear()
552
+ pendingMarkers.clear()
636
553
  }
637
- markersById.clear()
638
- pendingMarkers.clear()
639
- }
640
554
 
641
555
  fun addPolyline(
642
556
  id: String,
643
557
  opts: PolylineOptions,
644
- ) {
558
+ ) = onUi {
645
559
  if (googleMap == null) {
646
560
  pendingPolylines.add(id to opts)
647
- return
648
- }
649
- onUi {
650
- polylinesById.remove(id)?.remove()
561
+ return@onUi
651
562
  }
563
+ polylinesById.remove(id)?.remove()
652
564
  internalAddPolyline(id, opts)
653
565
  }
654
566
 
655
567
  private fun internalAddPolyline(
656
568
  id: String,
657
569
  opts: PolylineOptions,
658
- ) {
659
- onUi {
660
- val polyline =
661
- googleMap?.addPolyline(opts).also {
662
- it?.tag = id
663
- }
664
- if (polyline != null) {
665
- polylinesById[id] = polyline
666
- }
667
- }
570
+ ) = onUi {
571
+ val pl = googleMap?.addPolyline(opts).also { it?.tag = id }
572
+ if (pl != null) polylinesById[id] = pl
668
573
  }
669
574
 
670
575
  fun updatePolyline(
671
576
  id: String,
672
577
  block: (Polyline) -> Unit,
673
- ) {
674
- val pl = polylinesById[id] ?: return
675
- onUi {
676
- block(pl)
677
- }
578
+ ) = onUi {
579
+ val pl = polylinesById[id] ?: return@onUi
580
+ block(pl)
678
581
  }
679
582
 
680
- fun removePolyline(id: String) {
583
+ fun removePolyline(id: String) =
681
584
  onUi {
682
585
  polylinesById.remove(id)?.remove()
683
586
  }
684
- }
685
587
 
686
- fun clearPolylines() {
588
+ fun clearPolylines() =
687
589
  onUi {
688
590
  polylinesById.values.forEach { it.remove() }
591
+ polylinesById.clear()
592
+ pendingPolylines.clear()
689
593
  }
690
- polylinesById.clear()
691
- pendingPolylines.clear()
692
- }
693
594
 
694
595
  fun addPolygon(
695
596
  id: String,
696
597
  opts: PolygonOptions,
697
- ) {
598
+ ) = onUi {
698
599
  if (googleMap == null) {
699
600
  pendingPolygons.add(id to opts)
700
- return
701
- }
702
-
703
- onUi {
704
- polygonsById.remove(id)?.remove()
601
+ return@onUi
705
602
  }
603
+ polygonsById.remove(id)?.remove()
706
604
  internalAddPolygon(id, opts)
707
605
  }
708
606
 
709
607
  private fun internalAddPolygon(
710
608
  id: String,
711
609
  opts: PolygonOptions,
712
- ) {
713
- onUi {
714
- val polygon =
715
- googleMap?.addPolygon(opts).also {
716
- it?.tag = id
717
- }
718
- if (polygon != null) {
719
- polygonsById[id] = polygon
720
- }
721
- }
610
+ ) = onUi {
611
+ val polygon = googleMap?.addPolygon(opts).also { it?.tag = id }
612
+ if (polygon != null) polygonsById[id] = polygon
722
613
  }
723
614
 
724
615
  fun updatePolygon(
725
616
  id: String,
726
617
  block: (Polygon) -> Unit,
727
- ) {
728
- val polygon = polygonsById[id] ?: return
729
- onUi {
730
- block(polygon)
731
- }
618
+ ) = onUi {
619
+ val polygon = polygonsById[id] ?: return@onUi
620
+ block(polygon)
732
621
  }
733
622
 
734
- fun removePolygon(id: String) {
623
+ fun removePolygon(id: String) =
735
624
  onUi {
736
625
  polygonsById.remove(id)?.remove()
737
626
  }
738
- }
739
627
 
740
- fun clearPolygons() {
628
+ fun clearPolygons() =
741
629
  onUi {
742
630
  polygonsById.values.forEach { it.remove() }
631
+ polygonsById.clear()
632
+ pendingPolygons.clear()
743
633
  }
744
- polygonsById.clear()
745
- pendingPolygons.clear()
746
- }
747
634
 
748
635
  fun addCircle(
749
636
  id: String,
750
637
  opts: CircleOptions,
751
- ) {
638
+ ) = onUi {
752
639
  if (googleMap == null) {
753
640
  pendingCircles.add(id to opts)
754
- return
755
- }
756
-
757
- onUi {
758
- circlesById.remove(id)?.remove()
641
+ return@onUi
759
642
  }
643
+ circlesById.remove(id)?.remove()
760
644
  internalAddCircle(id, opts)
761
645
  }
762
646
 
763
647
  private fun internalAddCircle(
764
648
  id: String,
765
649
  opts: CircleOptions,
766
- ) {
767
- onUi {
768
- val circle =
769
- googleMap?.addCircle(opts).also {
770
- it?.tag = id
771
- }
772
- if (circle != null) {
773
- circlesById[id] = circle
774
- }
775
- }
650
+ ) = onUi {
651
+ val circle = googleMap?.addCircle(opts).also { it?.tag = id }
652
+ if (circle != null) circlesById[id] = circle
776
653
  }
777
654
 
778
655
  fun updateCircle(
779
656
  id: String,
780
657
  block: (Circle) -> Unit,
781
- ) {
782
- val circle = circlesById[id] ?: return
783
- onUi {
784
- block(circle)
785
- }
658
+ ) = onUi {
659
+ val circle = circlesById[id] ?: return@onUi
660
+ block(circle)
786
661
  }
787
662
 
788
- fun removeCircle(id: String) {
663
+ fun removeCircle(id: String) =
789
664
  onUi {
790
665
  circlesById.remove(id)?.remove()
791
666
  }
792
- }
793
667
 
794
- fun clearCircles() {
668
+ fun clearCircles() =
795
669
  onUi {
796
670
  circlesById.values.forEach { it.remove() }
671
+ circlesById.clear()
672
+ pendingCircles.clear()
797
673
  }
798
- circlesById.clear()
799
- pendingCircles.clear()
800
- }
801
674
 
802
675
  fun addHeatmap(
803
676
  id: String,
804
677
  opts: TileOverlayOptions,
805
- ) {
678
+ ) = onUi {
806
679
  if (googleMap == null) {
807
680
  pendingHeatmaps.add(id to opts)
808
- return
809
- }
810
-
811
- onUi {
812
- heatmapsById.remove(id)?.remove()
681
+ return@onUi
813
682
  }
683
+ heatmapsById.remove(id)?.remove()
814
684
  internalAddHeatmap(id, opts)
815
685
  }
816
686
 
817
687
  private fun internalAddHeatmap(
818
688
  id: String,
819
689
  opts: TileOverlayOptions,
820
- ) {
821
- onUi {
822
- val heatmap =
823
- googleMap?.addTileOverlay(opts)
824
- if (heatmap != null) {
825
- heatmapsById[id] = heatmap
826
- }
827
- }
690
+ ) = onUi {
691
+ val overlay = googleMap?.addTileOverlay(opts)
692
+ if (overlay != null) heatmapsById[id] = overlay
828
693
  }
829
694
 
830
- fun removeHeatmap(id: String) {
695
+ fun removeHeatmap(id: String) =
831
696
  onUi {
832
697
  heatmapsById.remove(id)?.remove()
833
698
  }
834
- }
835
699
 
836
- fun clearHeatmaps() {
700
+ fun clearHeatmaps() =
837
701
  onUi {
838
702
  heatmapsById.values.forEach { it.remove() }
703
+ heatmapsById.clear()
704
+ pendingHeatmaps.clear()
839
705
  }
840
- heatmapsById.clear()
841
- pendingHeatmaps.clear()
842
- }
843
706
 
844
707
  fun addKmlLayer(
845
708
  id: String,
846
709
  kmlString: String,
847
- ) {
710
+ ) = onUi {
848
711
  if (googleMap == null) {
849
712
  pendingKmlLayers.add(id to kmlString)
850
- return
851
- }
852
- onUi {
853
- kmlLayersById.remove(id)?.removeLayerFromMap()
713
+ return@onUi
854
714
  }
715
+ kmlLayersById.remove(id)?.removeLayerFromMap()
855
716
  internalAddKmlLayer(id, kmlString)
856
717
  }
857
718
 
858
719
  private fun internalAddKmlLayer(
859
720
  id: String,
860
721
  kmlString: String,
861
- ) {
862
- onUi {
863
- try {
864
- val inputStream = ByteArrayInputStream(kmlString.toByteArray(StandardCharsets.UTF_8))
865
- val layer = KmlLayer(googleMap, inputStream, context)
866
- kmlLayersById[id] = layer
867
- layer.addLayerToMap()
868
- } catch (e: Exception) {
869
- // / ignore
870
- }
722
+ ) = onUi {
723
+ try {
724
+ val inputStream = ByteArrayInputStream(kmlString.toByteArray(StandardCharsets.UTF_8))
725
+ val layer = KmlLayer(googleMap, inputStream, context)
726
+ kmlLayersById[id] = layer
727
+ layer.addLayerToMap()
728
+ } catch (_: Exception) {
729
+ // ignore
871
730
  }
872
731
  }
873
732
 
874
- fun removeKmlLayer(id: String) {
733
+ fun removeKmlLayer(id: String) =
875
734
  onUi {
876
735
  kmlLayersById.remove(id)?.removeLayerFromMap()
877
736
  }
878
- }
879
737
 
880
- fun clearKmlLayer() {
738
+ fun clearKmlLayer() =
881
739
  onUi {
882
740
  kmlLayersById.values.forEach { it.removeLayerFromMap() }
741
+ kmlLayersById.clear()
742
+ pendingKmlLayers.clear()
883
743
  }
884
- kmlLayersById.clear()
885
- pendingKmlLayers.clear()
886
- }
887
744
 
888
745
  fun addUrlTileOverlay(
889
746
  id: String,
890
747
  opts: TileOverlayOptions,
891
- ) {
748
+ ) = onUi {
892
749
  if (googleMap == null) {
893
750
  pendingUrlTilesOverlays.add(id to opts)
894
- return
895
- }
896
-
897
- onUi {
898
- urlTileOverlaysById.remove(id)?.remove()
751
+ return@onUi
899
752
  }
753
+ urlTileOverlaysById.remove(id)?.remove()
900
754
  internalAddUrlTileOverlay(id, opts)
901
755
  }
902
756
 
903
757
  private fun internalAddUrlTileOverlay(
904
758
  id: String,
905
759
  opts: TileOverlayOptions,
906
- ) {
907
- onUi {
908
- val urlTile =
909
- googleMap?.addTileOverlay(opts)
910
- if (urlTile != null) {
911
- urlTileOverlaysById[id] = urlTile
912
- }
913
- }
760
+ ) = onUi {
761
+ val overlay = googleMap?.addTileOverlay(opts)
762
+ if (overlay != null) urlTileOverlaysById[id] = overlay
914
763
  }
915
764
 
916
- fun removeUrlTileOverlay(id: String) {
765
+ fun removeUrlTileOverlay(id: String) =
917
766
  onUi {
918
767
  urlTileOverlaysById.remove(id)?.remove()
919
768
  }
920
- }
921
769
 
922
- fun clearUrlTileOverlays() {
770
+ fun clearUrlTileOverlays() =
923
771
  onUi {
924
772
  urlTileOverlaysById.values.forEach { it.remove() }
773
+ urlTileOverlaysById.clear()
774
+ pendingUrlTilesOverlays.clear()
925
775
  }
926
- urlTileOverlaysById.clear()
927
- pendingUrlTilesOverlays.clear()
928
- }
929
776
 
930
- fun destroyInternal() {
931
- if (destroyed) return
932
- destroyed = true
777
+ fun destroyInternal() =
933
778
  onUi {
779
+ if (destroyed) return@onUi
780
+ destroyed = true
934
781
  locationHandler.stop()
935
782
  markerBuilder.cancelAllJobs()
936
783
  clearMarkers()
@@ -969,7 +816,6 @@ class GoogleMapsViewImpl(
969
816
  reactContext.removeLifecycleEventListener(this)
970
817
  initialized = false
971
818
  }
972
- }
973
819
 
974
820
  override fun requestLayout() {
975
821
  super.requestLayout()
@@ -983,130 +829,126 @@ class GoogleMapsViewImpl(
983
829
  }
984
830
  }
985
831
 
986
- override fun onAttachedToWindow() {
987
- super.onAttachedToWindow()
988
- locationHandler.start()
989
- }
832
+ override fun onAttachedToWindow() =
833
+ onUi {
834
+ super.onAttachedToWindow()
835
+ locationHandler.start()
836
+ }
990
837
 
991
- override fun onDetachedFromWindow() {
992
- super.onDetachedFromWindow()
993
- locationHandler.stop()
994
- }
838
+ override fun onDetachedFromWindow() =
839
+ onUi {
840
+ super.onDetachedFromWindow()
841
+ locationHandler.stop()
842
+ }
995
843
 
996
- override fun onHostResume() {
844
+ override fun onHostResume() =
997
845
  onUi {
998
846
  locationHandler.start()
999
847
  mapView?.onResume()
1000
848
  }
1001
- }
1002
849
 
1003
- override fun onHostPause() {
850
+ override fun onHostPause() =
1004
851
  onUi {
1005
852
  locationHandler.stop()
1006
853
  mapView?.onPause()
1007
854
  }
1008
- }
1009
855
 
1010
856
  override fun onHostDestroy() {
1011
857
  destroyInternal()
1012
858
  }
1013
859
 
1014
860
  override fun onMarkerClick(marker: Marker): Boolean {
1015
- marker.showInfoWindow()
1016
- onMarkerPress?.invoke(marker.tag?.toString())
861
+ onUi {
862
+ marker.showInfoWindow()
863
+ onMarkerPress?.invoke(marker.tag?.toString())
864
+ }
1017
865
  return false
1018
866
  }
1019
867
 
1020
- override fun onPolylineClick(polyline: Polyline) {
1021
- onPolylinePress?.invoke(polyline.tag?.toString())
1022
- }
868
+ override fun onPolylineClick(polyline: Polyline) =
869
+ onUi {
870
+ onPolylinePress?.invoke(polyline.tag?.toString())
871
+ }
1023
872
 
1024
- override fun onPolygonClick(polygon: Polygon) {
1025
- onPolygonPress?.invoke(polygon.tag?.toString())
1026
- }
873
+ override fun onPolygonClick(polygon: Polygon) =
874
+ onUi {
875
+ onPolygonPress?.invoke(polygon.tag?.toString())
876
+ }
1027
877
 
1028
- override fun onCircleClick(circle: Circle) {
1029
- onCirclePress?.invoke(circle.tag?.toString())
1030
- }
878
+ override fun onCircleClick(circle: Circle) =
879
+ onUi {
880
+ onCirclePress?.invoke(circle.tag?.toString())
881
+ }
1031
882
 
1032
- override fun onMapClick(coordinates: LatLng) {
1033
- onMapPress?.invoke(
1034
- coordinates.toRnLatLng(),
1035
- )
1036
- }
883
+ override fun onMapClick(coordinates: LatLng) =
884
+ onUi {
885
+ onMapPress?.invoke(coordinates.toRnLatLng())
886
+ }
1037
887
 
1038
- override fun onMapLongClick(coordinates: LatLng) {
1039
- onMapLongPress?.invoke(
1040
- coordinates.toRnLatLng(),
1041
- )
1042
- }
888
+ override fun onMapLongClick(coordinates: LatLng) =
889
+ onUi {
890
+ onMapLongPress?.invoke(coordinates.toRnLatLng())
891
+ }
1043
892
 
1044
- override fun onMarkerDragStart(marker: Marker) {
1045
- onMarkerDragStart?.invoke(
1046
- marker.tag?.toString(),
1047
- marker.position.toRnLatLng(),
1048
- )
1049
- }
893
+ override fun onMarkerDragStart(marker: Marker) =
894
+ onUi {
895
+ onMarkerDragStart?.invoke(marker.tag?.toString(), marker.position.toRnLatLng())
896
+ }
1050
897
 
1051
- override fun onMarkerDrag(marker: Marker) {
1052
- onMarkerDrag?.invoke(
1053
- marker.tag?.toString(),
1054
- marker.position.toRnLatLng(),
1055
- )
1056
- }
898
+ override fun onMarkerDrag(marker: Marker) =
899
+ onUi {
900
+ onMarkerDrag?.invoke(marker.tag?.toString(), marker.position.toRnLatLng())
901
+ }
1057
902
 
1058
- override fun onMarkerDragEnd(marker: Marker) {
1059
- onMarkerDragEnd?.invoke(
1060
- marker.tag?.toString(),
1061
- marker.position.toRnLatLng(),
1062
- )
1063
- }
903
+ override fun onMarkerDragEnd(marker: Marker) =
904
+ onUi {
905
+ onMarkerDragEnd?.invoke(marker.tag?.toString(), marker.position.toRnLatLng())
906
+ }
1064
907
 
1065
- override fun onIndoorBuildingFocused() {
1066
- val building = googleMap?.focusedBuilding ?: return
1067
- onIndoorBuildingFocused?.invoke(building.toRNIndoorBuilding())
1068
- }
908
+ override fun onIndoorBuildingFocused() =
909
+ onUi {
910
+ val building = googleMap?.focusedBuilding ?: return@onUi
911
+ onIndoorBuildingFocused?.invoke(building.toRNIndoorBuilding())
912
+ }
1069
913
 
1070
- override fun onIndoorLevelActivated(indoorBuilding: IndoorBuilding) {
1071
- val activeLevel = indoorBuilding.levels.getOrNull(indoorBuilding.activeLevelIndex) ?: return
1072
- onIndoorLevelActivated?.invoke(
1073
- activeLevel.toRNIndoorLevel(
1074
- indoorBuilding.activeLevelIndex,
1075
- true,
1076
- ),
1077
- )
1078
- }
914
+ override fun onIndoorLevelActivated(indoorBuilding: IndoorBuilding) =
915
+ onUi {
916
+ val activeLevel =
917
+ indoorBuilding.levels.getOrNull(indoorBuilding.activeLevelIndex) ?: return@onUi
918
+ onIndoorLevelActivated?.invoke(
919
+ activeLevel.toRNIndoorLevel(indoorBuilding.activeLevelIndex, true),
920
+ )
921
+ }
1079
922
 
1080
- override fun onPoiClick(poi: PointOfInterest) {
1081
- onPoiPress?.invoke(poi.placeId, poi.name, poi.latLng.toRnLatLng())
1082
- }
923
+ override fun onPoiClick(poi: PointOfInterest) =
924
+ onUi {
925
+ onPoiPress?.invoke(poi.placeId, poi.name, poi.latLng.toRnLatLng())
926
+ }
1083
927
 
1084
- override fun onInfoWindowClick(marker: Marker) {
1085
- onInfoWindowPress?.invoke(marker.tag?.toString())
1086
- }
928
+ override fun onInfoWindowClick(marker: Marker) =
929
+ onUi {
930
+ onInfoWindowPress?.invoke(marker.tag?.toString())
931
+ }
1087
932
 
1088
- override fun onInfoWindowClose(marker: Marker) {
1089
- onInfoWindowClose?.invoke(marker.tag?.toString())
1090
- }
933
+ override fun onInfoWindowClose(marker: Marker) =
934
+ onUi {
935
+ onInfoWindowClose?.invoke(marker.tag?.toString())
936
+ }
1091
937
 
1092
- override fun onInfoWindowLongClick(marker: Marker) {
1093
- onInfoWindowLongPress?.invoke(marker.tag?.toString())
1094
- }
938
+ override fun onInfoWindowLongClick(marker: Marker) =
939
+ onUi {
940
+ onInfoWindowLongPress?.invoke(marker.tag?.toString())
941
+ }
1095
942
 
1096
- override fun onMyLocationClick(location: Location) {
1097
- onMyLocationPress?.invoke(location.toRnLocation())
1098
- }
943
+ override fun onMyLocationClick(location: Location) =
944
+ onUi {
945
+ onMyLocationPress?.invoke(location.toRnLocation())
946
+ }
1099
947
 
1100
948
  override fun onMyLocationButtonClick(): Boolean {
1101
- onMyLocationButtonPress?.invoke(true)
949
+ onUi {
950
+ onMyLocationButtonPress?.invoke(true)
951
+ }
1102
952
  return false
1103
953
  }
1104
954
  }
1105
-
1106
- private inline fun onUi(crossinline block: () -> Unit) {
1107
- if (UiThreadUtil.isOnUiThread()) {
1108
- block()
1109
- } else {
1110
- UiThreadUtil.runOnUiThread { block() }
1111
- }
1112
- }