Skip to content

Commit cdaa01a

Browse files
authored
refactor(map): unify update logic and defaults across Android and iOS
2 parents 31d5ff5 + f15d638 commit cdaa01a

24 files changed

+505
-642
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
concurrency:
1010
group: release-${{ github.ref_name }}
1111
cancel-in-progress: true
12-
12+
1313
permissions:
1414
contents: read
1515

PULL_REQUEST_TEMPLATE/pull_request_template.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,39 @@ CI already runs linting, formatting, and build checks automatically.
1414
---
1515

1616
### Summary
17+
1718
Short description of what this PR changes or adds.
1819

1920
---
2021

2122
### Type of change
22-
- [ ] Feature
23-
- [ ] Fix
24-
- [ ] Refactor
25-
- [ ] Internal / CI
26-
- [ ] Documentation
23+
24+
- [ ] Feature
25+
- [ ] Fix
26+
- [ ] Refactor
27+
- [ ] Internal / CI
28+
- [ ] Documentation
2729

2830
---
2931

3032
### Scope
31-
- [ ] Android
32-
- [ ] iOS
33-
- [ ] Core
34-
- [ ] Example App
35-
- [ ] Docs
33+
34+
- [ ] Android
35+
- [ ] iOS
36+
- [ ] Core
37+
- [ ] Example App
38+
- [ ] Docs
3639

3740
---
3841

3942
### Related
43+
4044
List any related issues, pull requests, or discussions.
4145
Use the format:
4246
`Fixes #123`, `Refs #456`, `Close #789`
4347

4448
---
4549

4650
### Additional notes
51+
4752
_(Optional – anything relevant for the reviewer)_

android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt

Lines changed: 37 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,9 @@ class GoogleMapsViewImpl(
293293
userInterfaceStyle?.let {
294294
googleMap?.mapColorScheme = it
295295
}
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)
301299
}
302300
}
303301

@@ -340,56 +338,34 @@ class GoogleMapsViewImpl(
340338
set(value) {
341339
field = value
342340
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
362358
}
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-
}
379359
}
380360
}
381361

382362
@SuppressLint("MissingPermission")
383363
var myLocationEnabled: Boolean? = null
384364
set(value) {
365+
field = value
385366
onUi {
386367
try {
387-
value?.let {
388-
googleMap?.isMyLocationEnabled = it
389-
}
390-
?: run {
391-
googleMap?.isMyLocationEnabled = false
392-
}
368+
googleMap?.isMyLocationEnabled = value ?: false
393369
} catch (se: SecurityException) {
394370
onLocationError?.invoke(RNLocationErrorCode.PERMISSION_DENIED)
395371
} catch (ex: Exception) {
@@ -403,37 +379,23 @@ class GoogleMapsViewImpl(
403379
set(value) {
404380
field = value
405381
onUi {
406-
value?.let {
407-
googleMap?.isBuildingsEnabled = it
408-
}
409-
?: run {
410-
googleMap?.isBuildingsEnabled = false
411-
}
382+
googleMap?.isBuildingsEnabled = value ?: false
412383
}
413384
}
414385

415386
var trafficEnabled: Boolean? = null
416387
set(value) {
417388
field = value
418389
onUi {
419-
value?.let {
420-
googleMap?.isTrafficEnabled = it
421-
} ?: run {
422-
googleMap?.isTrafficEnabled = false
423-
}
390+
googleMap?.isTrafficEnabled = value ?: false
424391
}
425392
}
426393

427394
var indoorEnabled: Boolean? = null
428395
set(value) {
429396
field = value
430397
onUi {
431-
value?.let {
432-
googleMap?.isIndoorEnabled = it
433-
}
434-
?: run {
435-
googleMap?.isIndoorEnabled = false
436-
}
398+
googleMap?.isIndoorEnabled = value ?: false
437399
}
438400
}
439401

@@ -449,64 +411,37 @@ class GoogleMapsViewImpl(
449411
set(value) {
450412
field = value
451413
onUi {
452-
value?.let {
453-
googleMap?.mapColorScheme = it
454-
} ?: run {
455-
googleMap?.mapColorScheme = MapColorScheme.FOLLOW_SYSTEM
456-
}
414+
googleMap?.mapColorScheme = value ?: MapColorScheme.FOLLOW_SYSTEM
457415
}
458416
}
459417

460-
var minZoomLevel: Double? = null
418+
var mapZoomConfig: RNMapZoomConfig? = null
461419
set(value) {
462420
field = value
463421
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)
481424
}
482425
}
483426

484427
var mapPadding: RNMapPadding? = null
485428
set(value) {
486429
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+
)
498437
}
499438
}
500439

501440
var mapType: Int? = null
502441
set(value) {
503442
field = value
504443
onUi {
505-
value?.let {
506-
googleMap?.mapType = it
507-
} ?: run {
508-
googleMap?.mapType = 1
509-
}
444+
googleMap?.mapType = value ?: 1
510445
}
511446
}
512447

android/src/main/java/com/rngooglemapsplus/LocationHandler.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ class LocationHandler(
3838

3939
var priority: Int? = PRIORITY_DEFAULT
4040
set(value) {
41-
field = value
41+
field = value ?: PRIORITY_DEFAULT
4242
start()
4343
}
4444

4545
var interval: Long? = INTERVAL_DEFAULT
4646
set(value) {
47-
field = value
47+
field = value ?: INTERVAL_DEFAULT
4848
buildLocationRequest()
4949
}
5050

5151
var minUpdateInterval: Long? = MIN_UPDATE_INTERVAL
5252
set(value) {
53-
field = value
53+
field = value ?: MIN_UPDATE_INTERVAL
5454
buildLocationRequest()
5555
}
5656

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
package com.rngooglemapsplus
22

3+
import android.graphics.Color
34
import com.facebook.react.uimanager.PixelUtil.dpToPx
5+
import com.google.android.gms.maps.model.Circle
46
import com.google.android.gms.maps.model.CircleOptions
57
import com.google.android.gms.maps.model.LatLng
68
import com.rngooglemapsplus.extensions.toColor
79

810
class MapCircleBuilder {
9-
fun buildCircleOptions(circle: RNCircle): CircleOptions =
11+
fun build(circle: RNCircle): CircleOptions =
1012
CircleOptions().apply {
1113
center(LatLng(circle.center.latitude, circle.center.longitude))
12-
circle.radius?.let { radius(it) }
14+
radius(circle.radius)
1315
circle.strokeWidth?.let { strokeWidth(it.dpToPx()) }
1416
circle.strokeColor?.let { strokeColor(it.toColor()) }
1517
circle.fillColor?.let { fillColor(it.toColor()) }
1618
circle.pressable?.let { clickable(it) }
1719
circle.zIndex?.let { zIndex(it.toFloat()) }
1820
}
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+
}
1933
}

android/src/main/java/com/rngooglemapsplus/MapMarkerBuilder.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import com.facebook.react.uimanager.PixelUtil.dpToPx
99
import com.google.android.gms.maps.model.BitmapDescriptor
1010
import com.google.android.gms.maps.model.BitmapDescriptorFactory
1111
import com.google.android.gms.maps.model.LatLng
12+
import com.google.android.gms.maps.model.Marker
1213
import com.google.android.gms.maps.model.MarkerOptions
14+
import com.rngooglemapsplus.extensions.markerStyleEquals
1315
import com.rngooglemapsplus.extensions.styleHash
1416
import kotlinx.coroutines.CoroutineScope
1517
import kotlinx.coroutines.Dispatchers
@@ -44,6 +46,29 @@ class MapMarkerBuilder(
4446
m.zIndex?.let { zIndex(it.toFloat()) }
4547
}
4648

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+
4772
fun buildIconAsync(
4873
id: String,
4974
m: RNMarker,

0 commit comments

Comments
 (0)