react-native-google-maps-plus 1.1.0-dev.2 → 1.1.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 (57) hide show
  1. package/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt +37 -102
  2. package/android/src/main/java/com/rngooglemapsplus/LocationHandler.kt +3 -3
  3. package/android/src/main/java/com/rngooglemapsplus/MapCircleBuilder.kt +16 -2
  4. package/android/src/main/java/com/rngooglemapsplus/MapMarkerBuilder.kt +25 -0
  5. package/android/src/main/java/com/rngooglemapsplus/MapPolygonBuilder.kt +18 -1
  6. package/android/src/main/java/com/rngooglemapsplus/MapPolylineBuilder.kt.kt +26 -9
  7. package/android/src/main/java/com/rngooglemapsplus/RNGoogleMapsPlusView.kt +46 -72
  8. package/ios/GoogleMapViewImpl.swift +94 -212
  9. package/ios/LocationHandler.swift +2 -10
  10. package/ios/MapCircleBuilder.swift +23 -8
  11. package/ios/MapHelper.swift +6 -4
  12. package/ios/MapMarkerBuilder.swift +39 -41
  13. package/ios/MapPolygonBuilder.swift +25 -7
  14. package/ios/MapPolylineBuilder.swift +27 -11
  15. package/ios/RNGoogleMapsPlusView.swift +9 -14
  16. package/ios/extensions/RNCircle+Extension.swift +0 -13
  17. package/ios/extensions/RNPolygon+Extension.swift.swift +2 -19
  18. package/ios/extensions/RNPolyline+Extension.swift.swift +1 -26
  19. package/lib/module/types.js.map +1 -1
  20. package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts +2 -3
  21. package/lib/typescript/src/RNGoogleMapsPlusView.nitro.d.ts.map +1 -1
  22. package/lib/typescript/src/types.d.ts +5 -1
  23. package/lib/typescript/src/types.d.ts.map +1 -1
  24. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.cpp +10 -15
  25. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.hpp +2 -4
  26. package/nitrogen/generated/android/c++/JRNCircle.hpp +4 -4
  27. package/nitrogen/generated/android/c++/JRNMapZoomConfig.hpp +57 -0
  28. package/nitrogen/generated/android/c++/views/JHybridRNGoogleMapsPlusViewStateUpdater.cpp +2 -6
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/HybridRNGoogleMapsPlusViewSpec.kt +1 -7
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNCircle.kt +1 -1
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNMapZoomConfig.kt +32 -0
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/views/HybridRNGoogleMapsPlusViewManager.kt +1 -1
  33. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Bridge.cpp +13 -13
  34. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Bridge.hpp +57 -33
  35. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Umbrella.hpp +3 -0
  36. package/nitrogen/generated/ios/c++/HybridRNGoogleMapsPlusViewSpecSwift.hpp +8 -12
  37. package/nitrogen/generated/ios/c++/views/HybridRNGoogleMapsPlusViewComponent.mm +4 -9
  38. package/nitrogen/generated/ios/swift/HybridRNGoogleMapsPlusViewSpec.swift +1 -2
  39. package/nitrogen/generated/ios/swift/HybridRNGoogleMapsPlusViewSpec_cxx.swift +46 -94
  40. package/nitrogen/generated/ios/swift/RNCamera.swift +1 -8
  41. package/nitrogen/generated/ios/swift/RNCircle.swift +5 -17
  42. package/nitrogen/generated/ios/swift/RNInitialProps.swift +1 -8
  43. package/nitrogen/generated/ios/swift/RNLocationConfig.swift +2 -16
  44. package/nitrogen/generated/ios/swift/RNMapZoomConfig.swift +70 -0
  45. package/nitrogen/generated/ios/swift/RNMarker.swift +2 -16
  46. package/nitrogen/generated/ios/swift/RNPolygon.swift +11 -15
  47. package/nitrogen/generated/ios/swift/RNPolyline.swift +11 -15
  48. package/nitrogen/generated/shared/c++/HybridRNGoogleMapsPlusViewSpec.cpp +2 -4
  49. package/nitrogen/generated/shared/c++/HybridRNGoogleMapsPlusViewSpec.hpp +5 -4
  50. package/nitrogen/generated/shared/c++/RNCircle.hpp +5 -5
  51. package/nitrogen/generated/shared/c++/RNMapZoomConfig.hpp +71 -0
  52. package/nitrogen/generated/shared/c++/views/HybridRNGoogleMapsPlusViewComponent.cpp +7 -19
  53. package/nitrogen/generated/shared/c++/views/HybridRNGoogleMapsPlusViewComponent.hpp +2 -2
  54. package/nitrogen/generated/shared/json/RNGoogleMapsPlusViewConfig.json +1 -2
  55. package/package.json +13 -13
  56. package/src/RNGoogleMapsPlusView.nitro.ts +2 -2
  57. package/src/types.ts +6 -1
@@ -293,11 +293,9 @@ class GoogleMapsViewImpl(
293
293
  userInterfaceStyle?.let {
294
294
  googleMap?.mapColorScheme = it
295
295
  }
296
- minZoomLevel?.let {
297
- googleMap?.setMinZoomPreference(it.toFloat())
298
- }
299
- maxZoomLevel?.let {
300
- googleMap?.setMaxZoomPreference(it.toFloat())
296
+ mapZoomConfig?.let {
297
+ googleMap?.setMinZoomPreference(it.min?.toFloat() ?: 2.0f)
298
+ googleMap?.setMaxZoomPreference(it.max?.toFloat() ?: 21.0f)
301
299
  }
302
300
  }
303
301
 
@@ -340,56 +338,34 @@ class GoogleMapsViewImpl(
340
338
  set(value) {
341
339
  field = value
342
340
  onUi {
343
- value?.let { v ->
344
- googleMap?.uiSettings?.apply {
345
- v.allGesturesEnabled?.let { setAllGesturesEnabled(it) }
346
- v.compassEnabled?.let { isCompassEnabled = it }
347
- v.indoorLevelPickerEnabled?.let { isIndoorLevelPickerEnabled = it }
348
- v.mapToolbarEnabled?.let { isMapToolbarEnabled = it }
349
- v.myLocationButtonEnabled?.let {
350
- googleMap?.setLocationSource(locationHandler)
351
- isMyLocationButtonEnabled = it
352
- }
353
- v.rotateEnabled?.let { isRotateGesturesEnabled = it }
354
- v.scrollEnabled?.let { isScrollGesturesEnabled = it }
355
- v.scrollDuringRotateOrZoomEnabled?.let {
356
- isScrollGesturesEnabledDuringRotateOrZoom = it
357
- }
358
- v.tiltEnabled?.let { isTiltGesturesEnabled = it }
359
- v.zoomControlsEnabled?.let { isZoomControlsEnabled = it }
360
- v.zoomGesturesEnabled?.let { isZoomGesturesEnabled = it }
361
- }
341
+ googleMap?.uiSettings?.apply {
342
+ setAllGesturesEnabled(value?.allGesturesEnabled ?: true)
343
+ isCompassEnabled = value?.compassEnabled ?: false
344
+ isIndoorLevelPickerEnabled = value?.indoorLevelPickerEnabled ?: false
345
+ isMapToolbarEnabled = value?.mapToolbarEnabled ?: false
346
+
347
+ val myLocationEnabled = value?.myLocationButtonEnabled ?: false
348
+ googleMap?.setLocationSource(if (myLocationEnabled) locationHandler else null)
349
+ isMyLocationButtonEnabled = myLocationEnabled
350
+
351
+ isRotateGesturesEnabled = value?.rotateEnabled ?: true
352
+ isScrollGesturesEnabled = value?.scrollEnabled ?: true
353
+ isScrollGesturesEnabledDuringRotateOrZoom =
354
+ value?.scrollDuringRotateOrZoomEnabled ?: true
355
+ isTiltGesturesEnabled = value?.tiltEnabled ?: true
356
+ isZoomControlsEnabled = value?.zoomControlsEnabled ?: false
357
+ isZoomGesturesEnabled = value?.zoomGesturesEnabled ?: false
362
358
  }
363
- ?: run {
364
- googleMap?.uiSettings?.apply {
365
- setAllGesturesEnabled(true)
366
- isCompassEnabled = false
367
- isIndoorLevelPickerEnabled = false
368
- isMapToolbarEnabled = false
369
- isMyLocationButtonEnabled = false
370
- googleMap?.setLocationSource(null)
371
- isRotateGesturesEnabled = true
372
- isScrollGesturesEnabled = true
373
- isScrollGesturesEnabledDuringRotateOrZoom = true
374
- isTiltGesturesEnabled = true
375
- isZoomControlsEnabled = false
376
- isZoomGesturesEnabled = false
377
- }
378
- }
379
359
  }
380
360
  }
381
361
 
382
362
  @SuppressLint("MissingPermission")
383
363
  var myLocationEnabled: Boolean? = null
384
364
  set(value) {
365
+ field = value
385
366
  onUi {
386
367
  try {
387
- value?.let {
388
- googleMap?.isMyLocationEnabled = it
389
- }
390
- ?: run {
391
- googleMap?.isMyLocationEnabled = false
392
- }
368
+ googleMap?.isMyLocationEnabled = value ?: false
393
369
  } catch (se: SecurityException) {
394
370
  onLocationError?.invoke(RNLocationErrorCode.PERMISSION_DENIED)
395
371
  } catch (ex: Exception) {
@@ -403,12 +379,7 @@ class GoogleMapsViewImpl(
403
379
  set(value) {
404
380
  field = value
405
381
  onUi {
406
- value?.let {
407
- googleMap?.isBuildingsEnabled = it
408
- }
409
- ?: run {
410
- googleMap?.isBuildingsEnabled = false
411
- }
382
+ googleMap?.isBuildingsEnabled = value ?: false
412
383
  }
413
384
  }
414
385
 
@@ -416,11 +387,7 @@ class GoogleMapsViewImpl(
416
387
  set(value) {
417
388
  field = value
418
389
  onUi {
419
- value?.let {
420
- googleMap?.isTrafficEnabled = it
421
- } ?: run {
422
- googleMap?.isTrafficEnabled = false
423
- }
390
+ googleMap?.isTrafficEnabled = value ?: false
424
391
  }
425
392
  }
426
393
 
@@ -428,12 +395,7 @@ class GoogleMapsViewImpl(
428
395
  set(value) {
429
396
  field = value
430
397
  onUi {
431
- value?.let {
432
- googleMap?.isIndoorEnabled = it
433
- }
434
- ?: run {
435
- googleMap?.isIndoorEnabled = false
436
- }
398
+ googleMap?.isIndoorEnabled = value ?: false
437
399
  }
438
400
  }
439
401
 
@@ -449,52 +411,29 @@ class GoogleMapsViewImpl(
449
411
  set(value) {
450
412
  field = value
451
413
  onUi {
452
- value?.let {
453
- googleMap?.mapColorScheme = it
454
- } ?: run {
455
- googleMap?.mapColorScheme = MapColorScheme.FOLLOW_SYSTEM
456
- }
414
+ googleMap?.mapColorScheme = value ?: MapColorScheme.FOLLOW_SYSTEM
457
415
  }
458
416
  }
459
417
 
460
- var minZoomLevel: Double? = null
418
+ var mapZoomConfig: RNMapZoomConfig? = null
461
419
  set(value) {
462
420
  field = value
463
421
  onUi {
464
- value?.let {
465
- googleMap?.setMinZoomPreference(it.toFloat())
466
- } ?: run {
467
- googleMap?.setMinZoomPreference(2.0f)
468
- }
469
- }
470
- }
471
-
472
- var maxZoomLevel: Double? = null
473
- set(value) {
474
- field = value
475
- onUi {
476
- value?.let {
477
- googleMap?.setMaxZoomPreference(it.toFloat())
478
- } ?: run {
479
- googleMap?.setMaxZoomPreference(21.0f)
480
- }
422
+ googleMap?.setMinZoomPreference(value?.min?.toFloat() ?: 2.0f)
423
+ googleMap?.setMaxZoomPreference(value?.max?.toFloat() ?: 21.0f)
481
424
  }
482
425
  }
483
426
 
484
427
  var mapPadding: RNMapPadding? = null
485
428
  set(value) {
486
429
  field = value
487
- value?.let {
488
- onUi {
489
- googleMap?.setPadding(
490
- it.left.dpToPx().toInt(),
491
- it.top.dpToPx().toInt(),
492
- it.right.dpToPx().toInt(),
493
- it.bottom.dpToPx().toInt(),
494
- )
495
- }
496
- } ?: run {
497
- googleMap?.setPadding(0, 0, 0, 0)
430
+ onUi {
431
+ googleMap?.setPadding(
432
+ value?.left?.dpToPx()?.toInt() ?: 0,
433
+ value?.top?.dpToPx()?.toInt() ?: 0,
434
+ value?.right?.dpToPx()?.toInt() ?: 0,
435
+ value?.bottom?.dpToPx()?.toInt() ?: 0,
436
+ )
498
437
  }
499
438
  }
500
439
 
@@ -502,11 +441,7 @@ class GoogleMapsViewImpl(
502
441
  set(value) {
503
442
  field = value
504
443
  onUi {
505
- value?.let {
506
- googleMap?.mapType = it
507
- } ?: run {
508
- googleMap?.mapType = 1
509
- }
444
+ googleMap?.mapType = value ?: 1
510
445
  }
511
446
  }
512
447
 
@@ -38,19 +38,19 @@ class LocationHandler(
38
38
 
39
39
  var priority: Int? = PRIORITY_DEFAULT
40
40
  set(value) {
41
- field = value
41
+ field = value ?: PRIORITY_DEFAULT
42
42
  start()
43
43
  }
44
44
 
45
45
  var interval: Long? = INTERVAL_DEFAULT
46
46
  set(value) {
47
- field = value
47
+ field = value ?: INTERVAL_DEFAULT
48
48
  buildLocationRequest()
49
49
  }
50
50
 
51
51
  var minUpdateInterval: Long? = MIN_UPDATE_INTERVAL
52
52
  set(value) {
53
- field = value
53
+ field = value ?: MIN_UPDATE_INTERVAL
54
54
  buildLocationRequest()
55
55
  }
56
56
 
@@ -1,19 +1,33 @@
1
1
  package com.rngooglemapsplus
2
2
 
3
+ import android.graphics.Color
3
4
  import com.facebook.react.uimanager.PixelUtil.dpToPx
5
+ import com.google.android.gms.maps.model.Circle
4
6
  import com.google.android.gms.maps.model.CircleOptions
5
7
  import com.google.android.gms.maps.model.LatLng
6
8
  import com.rngooglemapsplus.extensions.toColor
7
9
 
8
10
  class MapCircleBuilder {
9
- fun buildCircleOptions(circle: RNCircle): CircleOptions =
11
+ fun build(circle: RNCircle): CircleOptions =
10
12
  CircleOptions().apply {
11
13
  center(LatLng(circle.center.latitude, circle.center.longitude))
12
- circle.radius?.let { radius(it) }
14
+ radius(circle.radius)
13
15
  circle.strokeWidth?.let { strokeWidth(it.dpToPx()) }
14
16
  circle.strokeColor?.let { strokeColor(it.toColor()) }
15
17
  circle.fillColor?.let { fillColor(it.toColor()) }
16
18
  circle.pressable?.let { clickable(it) }
17
19
  circle.zIndex?.let { zIndex(it.toFloat()) }
18
20
  }
21
+
22
+ fun update(
23
+ circle: Circle,
24
+ next: RNCircle,
25
+ ) {
26
+ circle.center = LatLng(next.center.latitude, next.center.longitude)
27
+ circle.radius = next.radius
28
+ circle.strokeWidth = next.strokeWidth?.dpToPx() ?: 1f
29
+ circle.strokeColor = next.strokeColor?.toColor() ?: Color.BLACK
30
+ circle.fillColor = next.fillColor?.toColor() ?: Color.TRANSPARENT
31
+ circle.zIndex = next.zIndex?.toFloat() ?: 0f
32
+ }
19
33
  }
@@ -9,7 +9,9 @@ import com.facebook.react.uimanager.PixelUtil.dpToPx
9
9
  import com.google.android.gms.maps.model.BitmapDescriptor
10
10
  import com.google.android.gms.maps.model.BitmapDescriptorFactory
11
11
  import com.google.android.gms.maps.model.LatLng
12
+ import com.google.android.gms.maps.model.Marker
12
13
  import com.google.android.gms.maps.model.MarkerOptions
14
+ import com.rngooglemapsplus.extensions.markerStyleEquals
13
15
  import com.rngooglemapsplus.extensions.styleHash
14
16
  import kotlinx.coroutines.CoroutineScope
15
17
  import kotlinx.coroutines.Dispatchers
@@ -44,6 +46,29 @@ class MapMarkerBuilder(
44
46
  m.zIndex?.let { zIndex(it.toFloat()) }
45
47
  }
46
48
 
49
+ fun update(
50
+ marker: Marker,
51
+ prev: RNMarker,
52
+ next: RNMarker,
53
+ ) {
54
+ marker.position =
55
+ LatLng(
56
+ next.coordinate.latitude,
57
+ next.coordinate.longitude,
58
+ )
59
+ marker.zIndex = next.zIndex?.toFloat() ?: 0f
60
+
61
+ if (!prev.markerStyleEquals(next)) {
62
+ buildIconAsync(marker.id, next) { icon ->
63
+ marker.setIcon(icon)
64
+ }
65
+ }
66
+ marker.setAnchor(
67
+ (next.anchor?.x ?: 0.5).toFloat(),
68
+ (next.anchor?.y ?: 0.5).toFloat(),
69
+ )
70
+ }
71
+
47
72
  fun buildIconAsync(
48
73
  id: String,
49
74
  m: RNMarker,
@@ -1,11 +1,14 @@
1
1
  package com.rngooglemapsplus
2
2
 
3
+ import android.graphics.Color
3
4
  import com.facebook.react.uimanager.PixelUtil.dpToPx
5
+ import com.google.android.gms.maps.model.LatLng
6
+ import com.google.android.gms.maps.model.Polygon
4
7
  import com.google.android.gms.maps.model.PolygonOptions
5
8
  import com.rngooglemapsplus.extensions.toColor
6
9
 
7
10
  class MapPolygonBuilder {
8
- fun buildPolygonOptions(poly: RNPolygon): PolygonOptions =
11
+ fun build(poly: RNPolygon): PolygonOptions =
9
12
  PolygonOptions().apply {
10
13
  poly.coordinates.forEach { pt ->
11
14
  add(
@@ -19,4 +22,18 @@ class MapPolygonBuilder {
19
22
  poly.pressable?.let { clickable(it) }
20
23
  poly.zIndex?.let { zIndex(it.toFloat()) }
21
24
  }
25
+
26
+ fun update(
27
+ gmsPoly: Polygon,
28
+ next: RNPolygon,
29
+ ) {
30
+ gmsPoly.points =
31
+ next.coordinates.map {
32
+ LatLng(it.latitude, it.longitude)
33
+ }
34
+ gmsPoly.fillColor = next.fillColor?.toColor() ?: Color.TRANSPARENT
35
+ gmsPoly.strokeColor = next.strokeColor?.toColor() ?: Color.BLACK
36
+ gmsPoly.strokeWidth = next.strokeWidth?.dpToPx() ?: 1f
37
+ gmsPoly.zIndex = next.zIndex?.toFloat() ?: 0f
38
+ }
22
39
  }
@@ -1,40 +1,57 @@
1
1
  package com.rngooglemapsplus
2
2
 
3
+ import android.graphics.Color
3
4
  import com.facebook.react.uimanager.PixelUtil.dpToPx
4
5
  import com.google.android.gms.maps.model.ButtCap
5
6
  import com.google.android.gms.maps.model.Cap
6
7
  import com.google.android.gms.maps.model.JointType
8
+ import com.google.android.gms.maps.model.LatLng
9
+ import com.google.android.gms.maps.model.Polyline
7
10
  import com.google.android.gms.maps.model.PolylineOptions
8
11
  import com.google.android.gms.maps.model.RoundCap
9
12
  import com.google.android.gms.maps.model.SquareCap
10
13
  import com.rngooglemapsplus.extensions.toColor
11
14
 
12
15
  class MapPolylineBuilder {
13
- fun buildPolylineOptions(pl: RNPolyline): PolylineOptions =
16
+ fun build(pl: RNPolyline): PolylineOptions =
14
17
  PolylineOptions().apply {
15
18
  pl.coordinates.forEach { pt ->
16
- add(
17
- com.google.android.gms.maps.model
18
- .LatLng(pt.latitude, pt.longitude),
19
- )
19
+ add(LatLng(pt.latitude, pt.longitude))
20
20
  }
21
21
  pl.width?.let { width(it.dpToPx()) }
22
- pl.lineCap?.let { startCap(mapLineCap(it)) }
23
- pl.lineCap?.let { endCap(mapLineCap(it)) }
22
+ pl.lineCap?.let {
23
+ startCap(mapLineCap(it))
24
+ endCap(mapLineCap(it))
25
+ }
24
26
  pl.lineJoin?.let { jointType(mapLineJoin(it)) }
25
27
  pl.color?.let { color(it.toColor()) }
26
28
  pl.pressable?.let { clickable(it) }
27
29
  pl.zIndex?.let { zIndex(it.toFloat()) }
28
30
  }
29
31
 
30
- fun mapLineCap(type: RNLineCapType?): Cap =
32
+ fun update(
33
+ polyline: Polyline,
34
+ next: RNPolyline,
35
+ ) {
36
+ polyline.points = next.coordinates.map { LatLng(it.latitude, it.longitude) }
37
+
38
+ polyline.width = next.width?.dpToPx() ?: 1f
39
+ val cap = mapLineCap(next.lineCap ?: RNLineCapType.BUTT)
40
+ polyline.startCap = cap
41
+ polyline.endCap = cap
42
+ polyline.jointType = mapLineJoin(next.lineJoin ?: RNLineJoinType.MITER)
43
+ polyline.color = next.color?.toColor() ?: Color.BLACK
44
+ polyline.zIndex = next.zIndex?.toFloat() ?: 0f
45
+ }
46
+
47
+ private fun mapLineCap(type: RNLineCapType?): Cap =
31
48
  when (type) {
32
49
  RNLineCapType.ROUND -> RoundCap()
33
50
  RNLineCapType.SQUARE -> SquareCap()
34
51
  else -> ButtCap()
35
52
  }
36
53
 
37
- fun mapLineJoin(type: RNLineJoinType?): Int =
54
+ private fun mapLineJoin(type: RNLineJoinType?): Int =
38
55
  when (type) {
39
56
  RNLineJoinType.ROUND -> JointType.ROUND
40
57
  RNLineJoinType.BEVEL -> JointType.BEVEL
@@ -2,18 +2,14 @@ package com.rngooglemapsplus
2
2
 
3
3
  import com.facebook.proguard.annotations.DoNotStrip
4
4
  import com.facebook.react.bridge.UiThreadUtil
5
- import com.facebook.react.uimanager.PixelUtil.dpToPx
6
5
  import com.facebook.react.uimanager.ThemedReactContext
7
- import com.google.android.gms.maps.model.LatLng
8
6
  import com.google.android.gms.maps.model.MapStyleOptions
9
7
  import com.margelo.nitro.core.Promise
10
8
  import com.rngooglemapsplus.extensions.circleEquals
11
9
  import com.rngooglemapsplus.extensions.markerEquals
12
- import com.rngooglemapsplus.extensions.markerStyleEquals
13
10
  import com.rngooglemapsplus.extensions.polygonEquals
14
11
  import com.rngooglemapsplus.extensions.polylineEquals
15
12
  import com.rngooglemapsplus.extensions.toCameraPosition
16
- import com.rngooglemapsplus.extensions.toColor
17
13
  import com.rngooglemapsplus.extensions.toMapColorScheme
18
14
 
19
15
  @DoNotStrip
@@ -35,6 +31,8 @@ class RNGoogleMapsPlusView(
35
31
 
36
32
  override var initialProps: RNInitialProps? = null
37
33
  set(value) {
34
+ if (field == value) return
35
+ field = value
38
36
  view.initMapView(
39
37
  value?.mapId,
40
38
  value?.liteMode,
@@ -44,31 +42,43 @@ class RNGoogleMapsPlusView(
44
42
 
45
43
  override var uiSettings: RNMapUiSettings? = null
46
44
  set(value) {
45
+ if (field == value) return
46
+ field = value
47
47
  view.uiSettings = value
48
48
  }
49
49
 
50
50
  override var myLocationEnabled: Boolean? = null
51
51
  set(value) {
52
+ if (field == value) return
53
+ field = value
52
54
  view.myLocationEnabled = value
53
55
  }
54
56
 
55
57
  override var buildingEnabled: Boolean? = null
56
58
  set(value) {
59
+ if (field == value) return
60
+ field = value
57
61
  view.buildingEnabled = value
58
62
  }
59
63
 
60
64
  override var trafficEnabled: Boolean? = null
61
65
  set(value) {
66
+ if (field == value) return
67
+ field = value
62
68
  view.trafficEnabled = value
63
69
  }
64
70
 
65
71
  override var indoorEnabled: Boolean? = null
66
72
  set(value) {
73
+ if (field == value) return
74
+ field = value
67
75
  view.indoorEnabled = value
68
76
  }
69
77
 
70
78
  override var customMapStyle: String? = null
71
79
  set(value) {
80
+ if (field == value) return
81
+ field = value
72
82
  currentCustomMapStyle = value
73
83
  value?.let {
74
84
  view.customMapStyle = MapStyleOptions(it)
@@ -77,26 +87,29 @@ class RNGoogleMapsPlusView(
77
87
 
78
88
  override var userInterfaceStyle: RNUserInterfaceStyle? = null
79
89
  set(value) {
90
+ if (field == value) return
91
+ field = value
80
92
  view.userInterfaceStyle = value.toMapColorScheme()
81
93
  }
82
94
 
83
- override var minZoomLevel: Double? = null
84
- set(value) {
85
- view.minZoomLevel = value
86
- }
87
-
88
- override var maxZoomLevel: Double? = null
95
+ override var mapZoomConfig: RNMapZoomConfig? = null
89
96
  set(value) {
90
- view.maxZoomLevel = value
97
+ if (field == value) return
98
+ field = value
99
+ view.mapZoomConfig = value
91
100
  }
92
101
 
93
102
  override var mapPadding: RNMapPadding? = null
94
103
  set(value) {
104
+ if (field == value) return
105
+ field = value
95
106
  view.mapPadding = value
96
107
  }
97
108
 
98
109
  override var mapType: RNMapType? = null
99
110
  set(value) {
111
+ if (field == value) return
112
+ field = value
100
113
  value?.let {
101
114
  view.mapType = it.value
102
115
  }
@@ -104,8 +117,10 @@ class RNGoogleMapsPlusView(
104
117
 
105
118
  override var markers: Array<RNMarker>? = null
106
119
  set(value) {
120
+ if (field.contentEquals(value)) return
107
121
  val prevById = field?.associateBy { it.id } ?: emptyMap()
108
122
  val nextById = value?.associateBy { it.id } ?: emptyMap()
123
+ field = value
109
124
 
110
125
  (prevById.keys - nextById.keys).forEach { id ->
111
126
  markerBuilder.cancelIconJob(id)
@@ -122,38 +137,21 @@ class RNGoogleMapsPlusView(
122
137
  )
123
138
  }
124
139
  } else if (!prev.markerEquals(next)) {
125
- view.updateMarker(id) { m ->
140
+ view.updateMarker(id) { marker ->
126
141
  onUi {
127
- m.position =
128
- LatLng(
129
- next.coordinate.latitude,
130
- next.coordinate.longitude,
131
- )
132
- next.zIndex?.let { m.zIndex = it.toFloat() } ?: run {
133
- m.zIndex = 0f
134
- }
135
-
136
- if (!prev.markerStyleEquals(next)) {
137
- markerBuilder.buildIconAsync(id, next) { icon ->
138
- m.setIcon(icon)
139
- }
140
- }
141
- m.setAnchor(
142
- (next.anchor?.x ?: 0.5).toFloat(),
143
- (next.anchor?.y ?: 0.5).toFloat(),
144
- )
142
+ markerBuilder.update(marker, next, prev)
145
143
  }
146
144
  }
147
145
  }
148
146
  }
149
- field = value
150
147
  }
151
148
 
152
149
  override var polylines: Array<RNPolyline>? = null
153
150
  set(value) {
151
+ if (field.contentEquals(value)) return
154
152
  val prevById = field?.associateBy { it.id } ?: emptyMap()
155
153
  val nextById = value?.associateBy { it.id } ?: emptyMap()
156
-
154
+ field = value
157
155
  (prevById.keys - nextById.keys).forEach { id ->
158
156
  view.removePolyline(id)
159
157
  }
@@ -161,35 +159,23 @@ class RNGoogleMapsPlusView(
161
159
  nextById.forEach { (id, next) ->
162
160
  val prev = prevById[id]
163
161
  if (prev == null) {
164
- view.addPolyline(id, polylineBuilder.buildPolylineOptions(next))
162
+ view.addPolyline(id, polylineBuilder.build(next))
165
163
  } else if (!prev.polylineEquals(next)) {
166
- view.updatePolyline(id) { gms ->
164
+ view.updatePolyline(id) { polyline ->
167
165
  onUi {
168
- gms.points =
169
- next.coordinates.map {
170
-
171
- LatLng(it.latitude, it.longitude)
172
- }
173
- next.width?.let { gms.width = it.dpToPx() }
174
- next.lineCap?.let {
175
- val cap = polylineBuilder.mapLineCap(it)
176
- gms.startCap = cap
177
- gms.endCap = cap
178
- }
179
- next.lineJoin?.let { gms.jointType = polylineBuilder.mapLineJoin(it) }
180
- next.color?.let { gms.color = it.toColor() }
181
- next.zIndex?.let { gms.zIndex = it.toFloat() }
166
+ polylineBuilder.update(polyline, next)
182
167
  }
183
168
  }
184
169
  }
185
170
  }
186
- field = value
187
171
  }
188
172
 
189
173
  override var polygons: Array<RNPolygon>? = null
190
174
  set(value) {
175
+ if (field.contentEquals(value)) return
191
176
  val prevById = field?.associateBy { it.id } ?: emptyMap()
192
177
  val nextById = value?.associateBy { it.id } ?: emptyMap()
178
+ field = value
193
179
 
194
180
  (prevById.keys - nextById.keys).forEach { id ->
195
181
  view.removePolygon(id)
@@ -198,30 +184,21 @@ class RNGoogleMapsPlusView(
198
184
  nextById.forEach { (id, next) ->
199
185
  val prev = prevById[id]
200
186
  if (prev == null) {
201
- view.addPolygon(id, polygonBuilder.buildPolygonOptions(next))
187
+ view.addPolygon(id, polygonBuilder.build(next))
202
188
  } else if (!prev.polygonEquals(next)) {
203
- view.updatePolygon(id) { gmsPoly ->
204
- onUi {
205
- gmsPoly.points =
206
- next.coordinates.map {
207
- com.google.android.gms.maps.model
208
- .LatLng(it.latitude, it.longitude)
209
- }
210
- next.fillColor?.let { gmsPoly.fillColor = it.toColor() }
211
- next.strokeColor?.let { gmsPoly.strokeColor = it.toColor() }
212
- next.strokeWidth?.let { gmsPoly.strokeWidth = it.dpToPx() }
213
- next.zIndex?.let { gmsPoly.zIndex = it.toFloat() }
214
- }
189
+ view.updatePolygon(id) { polygon ->
190
+ onUi { polygonBuilder.update(polygon, next) }
215
191
  }
216
192
  }
217
193
  }
218
- field = value
219
194
  }
220
195
 
221
196
  override var circles: Array<RNCircle>? = null
222
197
  set(value) {
198
+ if (field.contentEquals(value)) return
223
199
  val prevById = field?.associateBy { it.id } ?: emptyMap()
224
200
  val nextById = value?.associateBy { it.id } ?: emptyMap()
201
+ field = value
225
202
 
226
203
  (prevById.keys - nextById.keys).forEach { id ->
227
204
  view.removeCircle(id)
@@ -230,25 +207,21 @@ class RNGoogleMapsPlusView(
230
207
  nextById.forEach { (id, next) ->
231
208
  val prev = prevById[id]
232
209
  if (prev == null) {
233
- view.addCircle(id, circleBuilder.buildCircleOptions(next))
210
+ view.addCircle(id, circleBuilder.build(next))
234
211
  } else if (!prev.circleEquals(next)) {
235
- view.updateCircle(id) { gmsCircle ->
212
+ view.updateCircle(id) { circle ->
236
213
  onUi {
237
- gmsCircle.center = LatLng(next.center.latitude, next.center.longitude)
238
- next.radius?.let { gmsCircle.radius = it }
239
- next.strokeWidth?.let { gmsCircle.strokeWidth = it.dpToPx() }
240
- next.strokeColor?.let { gmsCircle.strokeColor = it.toColor() }
241
- next.fillColor?.let { gmsCircle.fillColor = it.toColor() }
242
- next.zIndex?.let { gmsCircle.zIndex = it.toFloat() } ?: run { gmsCircle.zIndex = 0f }
214
+ circleBuilder.update(circle, next)
243
215
  }
244
216
  }
245
217
  }
246
218
  }
247
- field = value
248
219
  }
249
220
 
250
221
  override var locationConfig: RNLocationConfig? = null
251
222
  set(value) {
223
+ if (field == value) return
224
+ field = value
252
225
  view.locationConfig = value
253
226
  }
254
227
 
@@ -261,6 +234,7 @@ class RNGoogleMapsPlusView(
261
234
  set(cb) {
262
235
  view.onMapReady = cb
263
236
  }
237
+
264
238
  override var onLocationUpdate: ((RNLocation) -> Unit)? = null
265
239
  set(cb) {
266
240
  view.onLocationUpdate = cb