Skip to content

Commit 12b7788

Browse files
authored
chore: merge dev into main
2 parents 5b02db9 + 4cd4c82 commit 12b7788

39 files changed

+447
-329
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,6 @@ dependencies {
136136
implementation "com.google.android.gms:play-services-base:${getExtOrDefault('googlePlayServicesBaseVersion')}"
137137
implementation "com.google.android.gms:play-services-maps:${getExtOrDefault('googlePlayServicesMapsVersion')}"
138138
implementation "com.google.android.gms:play-services-location:${getExtOrDefault('googlePlayServicesLocationVersion')}"
139-
implementation 'com.google.maps.android:android-maps-utils:3.10.0'
139+
implementation "com.google.maps.android:android-maps-utils:${getExtOrDefault('mapsUtilsVersion')}"
140140
implementation 'com.caverock:androidsvg-aar:1.4'
141141
}

android/gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ RNGoogleMapsPlus_minSdkVersion=26
33
RNGoogleMapsPlus_targetSdkVersion=36
44
RNGoogleMapsPlus_compileSdkVersion=36
55
RNGoogleMapsPlus_ndkVersion=27.1.12297006
6-
RNGoogleMapsPlus_googlePlayServicesBaseVersion=18.8.0
6+
RNGoogleMapsPlus_googlePlayServicesBaseVersion=18.9.0
77
RNGoogleMapsPlus_googlePlayServicesMapsVersion=19.2.0
88
RNGoogleMapsPlus_googlePlayServicesLocationVersion=21.3.0
9+
RNGoogleMapsPlus_mapsUtilsVersion=3.19.0

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.graphics.Color
44
import com.facebook.react.uimanager.PixelUtil.dpToPx
55
import com.google.android.gms.maps.model.Circle
66
import com.google.android.gms.maps.model.CircleOptions
7+
import com.rngooglemapsplus.extensions.centerEquals
78
import com.rngooglemapsplus.extensions.onUi
89
import com.rngooglemapsplus.extensions.toColor
910
import com.rngooglemapsplus.extensions.toLatLng
@@ -25,9 +26,7 @@ class MapCircleBuilder {
2526
next: RNCircle,
2627
circle: Circle,
2728
) = onUi {
28-
if (prev.center.latitude != next.center.latitude ||
29-
prev.center.longitude != next.center.longitude
30-
) {
29+
if (!prev.centerEquals(next)) {
3130
circle.center = next.center.toLatLng()
3231
}
3332

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

Lines changed: 51 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import com.google.android.gms.maps.model.BitmapDescriptor
1919
import com.google.android.gms.maps.model.BitmapDescriptorFactory
2020
import com.google.android.gms.maps.model.Marker
2121
import com.google.android.gms.maps.model.MarkerOptions
22+
import com.rngooglemapsplus.extensions.anchorEquals
23+
import com.rngooglemapsplus.extensions.coordinatesEquals
24+
import com.rngooglemapsplus.extensions.infoWindowAnchorEquals
25+
import com.rngooglemapsplus.extensions.markerInfoWindowStyleEquals
2226
import com.rngooglemapsplus.extensions.markerStyleEquals
2327
import com.rngooglemapsplus.extensions.onUi
2428
import com.rngooglemapsplus.extensions.styleHash
@@ -73,7 +77,10 @@ class MapMarkerBuilder(
7377
val height = (svg.documentHeight.takeIf { it > 0 } ?: 128f).toInt()
7478

7579
createBitmap(width, height).apply {
76-
Canvas(this).also(svg::renderToCanvas)
80+
density = context.resources.displayMetrics.densityDpi
81+
Canvas(this).also {
82+
svg.renderToCanvas(it)
83+
}
7784
}
7885
}
7986

@@ -94,10 +101,12 @@ class MapMarkerBuilder(
94101
val innerSvg = SVG.getFromString(svgText)
95102
val w = innerSvg.documentWidth.takeIf { it > 0 } ?: 128f
96103
val h = innerSvg.documentHeight.takeIf { it > 0 } ?: 128f
97-
val bmp = createBitmap(w.toInt(), h.toInt())
98-
val canvas = Canvas(bmp)
99-
innerSvg.renderToCanvas(canvas)
100-
bmp
104+
createBitmap(w.toInt(), h.toInt()).apply {
105+
density = context.resources.displayMetrics.densityDpi
106+
Canvas(this).also {
107+
innerSvg.renderToCanvas(it)
108+
}
109+
}
101110
} else {
102111
conn.inputStream.use { BitmapFactory.decodeStream(it) }
103112
}
@@ -169,51 +178,39 @@ class MapMarkerBuilder(
169178
next: RNMarker,
170179
marker: Marker,
171180
) = onUi {
172-
if (prev.coordinate.latitude != next.coordinate.latitude ||
173-
prev.coordinate.longitude != next.coordinate.longitude
174-
) {
181+
if (!prev.coordinatesEquals(next)) {
175182
marker.position = next.coordinate.toLatLng()
176183
}
177184

178185
if (!prev.markerStyleEquals(next)) {
179-
buildIconAsync(marker.id, next) { icon ->
186+
buildIconAsync(next) { icon ->
180187
marker.setIcon(icon)
181-
if (prev.infoWindowAnchor?.x != next.infoWindowAnchor?.x ||
182-
prev.infoWindowAnchor?.y != next.infoWindowAnchor?.y
183-
) {
184-
marker.setInfoWindowAnchor(
185-
(next.infoWindowAnchor?.x ?: 0.5f).toFloat(),
186-
(next.infoWindowAnchor?.y ?: 0f).toFloat(),
187-
)
188-
}
189-
190-
if (prev.anchor?.x != next.anchor?.x ||
191-
prev.anchor?.y != next.anchor?.y
192-
) {
188+
if (!prev.anchorEquals(next)) {
193189
marker.setAnchor(
194190
(next.anchor?.x ?: 0.5f).toFloat(),
195191
(next.anchor?.y ?: 1.0f).toFloat(),
196192
)
197193
}
194+
if (!prev.infoWindowAnchorEquals(next)) {
195+
marker.setInfoWindowAnchor(
196+
(next.infoWindowAnchor?.x ?: 0.5f).toFloat(),
197+
(next.infoWindowAnchor?.y ?: 0f).toFloat(),
198+
)
199+
}
198200
}
199201
} else {
200-
if (prev.infoWindowAnchor?.x != next.infoWindowAnchor?.x ||
201-
prev.infoWindowAnchor?.y != next.infoWindowAnchor?.y
202-
) {
203-
marker.setInfoWindowAnchor(
204-
(next.infoWindowAnchor?.x ?: 0.5f).toFloat(),
205-
(next.infoWindowAnchor?.y ?: 0f).toFloat(),
206-
)
207-
}
208-
209-
if (prev.anchor?.x != next.anchor?.x ||
210-
prev.anchor?.y != next.anchor?.y
211-
) {
202+
if (!prev.anchorEquals(next)) {
212203
marker.setAnchor(
213204
(next.anchor?.x ?: 0.5f).toFloat(),
214205
(next.anchor?.y ?: 1.0f).toFloat(),
215206
)
216207
}
208+
if (!prev.infoWindowAnchorEquals(next)) {
209+
marker.setInfoWindowAnchor(
210+
(next.infoWindowAnchor?.x ?: 0.5f).toFloat(),
211+
(next.infoWindowAnchor?.y ?: 0f).toFloat(),
212+
)
213+
}
217214
}
218215

219216
if (prev.title != next.title) {
@@ -244,17 +241,16 @@ class MapMarkerBuilder(
244241
marker.zIndex = next.zIndex?.toFloat() ?: 0f
245242
}
246243

247-
if (prev.infoWindowIconSvg != next.infoWindowIconSvg) {
244+
if (!prev.markerInfoWindowStyleEquals(next)) {
248245
marker.tag = MarkerTag(id = next.id, iconSvg = next.infoWindowIconSvg)
249246
}
250247
}
251248

252249
fun buildIconAsync(
253-
id: String,
254250
m: RNMarker,
255251
onReady: (BitmapDescriptor?) -> Unit,
256252
) {
257-
jobsById[id]?.cancel()
253+
jobsById[m.id]?.cancel()
258254

259255
m.iconSvg ?: return onReady(null)
260256

@@ -283,11 +279,11 @@ class MapMarkerBuilder(
283279
iconCache.evictAll()
284280
} catch (_: Throwable) {
285281
} finally {
286-
jobsById.remove(id)
282+
jobsById.remove(m.id)
287283
}
288284
}
289285

290-
jobsById[id] = job
286+
jobsById[m.id] = job
291287
}
292288

293289
fun cancelIconJob(id: String) {
@@ -337,27 +333,28 @@ class MapMarkerBuilder(
337333
coroutineContext.ensureActive()
338334
val svg = SVG.getFromString(m.iconSvg.svgString)
339335

340-
coroutineContext.ensureActive()
341-
svg.setDocumentWidth(m.iconSvg.width.dpToPx())
342-
svg.setDocumentHeight(m.iconSvg.height.dpToPx())
336+
val wPx =
337+
m.iconSvg.width
338+
.dpToPx()
339+
.toInt()
340+
val hPx =
341+
m.iconSvg.height
342+
.dpToPx()
343+
.toInt()
343344

344345
coroutineContext.ensureActive()
345-
bmp =
346-
createBitmap(
347-
m.iconSvg.width
348-
.dpToPx()
349-
.toInt(),
350-
m.iconSvg.height
351-
.dpToPx()
352-
.toInt(),
353-
Bitmap.Config.ARGB_8888,
354-
)
346+
svg.setDocumentWidth(wPx.toFloat())
347+
svg.setDocumentHeight(hPx.toFloat())
355348

356349
coroutineContext.ensureActive()
357-
val canvas = Canvas(bmp)
358-
svg.renderToCanvas(canvas)
350+
bmp =
351+
createBitmap(wPx, hPx, Bitmap.Config.ARGB_8888).apply {
352+
density = context.resources.displayMetrics.densityDpi
353+
Canvas(this).also {
354+
svg.renderToCanvas(it)
355+
}
356+
}
359357

360-
coroutineContext.ensureActive()
361358
return bmp
362359
} catch (t: Throwable) {
363360
try {

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

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import android.graphics.Color
44
import com.facebook.react.uimanager.PixelUtil.dpToPx
55
import com.google.android.gms.maps.model.Polygon
66
import com.google.android.gms.maps.model.PolygonOptions
7+
import com.rngooglemapsplus.extensions.coordinatesEquals
8+
import com.rngooglemapsplus.extensions.holesEquals
79
import com.rngooglemapsplus.extensions.onUi
810
import com.rngooglemapsplus.extensions.toColor
911
import com.rngooglemapsplus.extensions.toLatLng
12+
import com.rngooglemapsplus.extensions.toMapsPolygonHoles
1013

1114
class MapPolygonBuilder {
1215
fun build(poly: RNPolygon): PolygonOptions =
@@ -32,32 +35,12 @@ class MapPolygonBuilder {
3235
next: RNPolygon,
3336
poly: Polygon,
3437
) = onUi {
35-
val coordsChanged =
36-
prev.coordinates.size != next.coordinates.size ||
37-
!prev.coordinates.zip(next.coordinates).all { (a, b) ->
38-
a.latitude == b.latitude && a.longitude == b.longitude
39-
}
40-
41-
if (coordsChanged) {
38+
if (!prev.coordinatesEquals(next)) {
4239
poly.points = next.coordinates.map { it.toLatLng() }
4340
}
4441

45-
val prevHoles = prev.holes?.toList() ?: emptyList()
46-
val nextHoles = next.holes?.toList() ?: emptyList()
47-
val holesChanged =
48-
prevHoles.size != nextHoles.size ||
49-
!prevHoles.zip(nextHoles).all { (ha, hb) ->
50-
ha.coordinates.size == hb.coordinates.size &&
51-
ha.coordinates.zip(hb.coordinates).all { (a, b) ->
52-
a.latitude == b.latitude && a.longitude == b.longitude
53-
}
54-
}
55-
56-
if (holesChanged) {
57-
poly.holes =
58-
nextHoles.map { hole ->
59-
hole.coordinates.map { it.toLatLng() }
60-
}
42+
if (!prev.holesEquals(next)) {
43+
poly.holes = next.holes?.toMapsPolygonHoles() ?: emptyList()
6144
}
6245

6346
if (prev.fillColor != next.fillColor) {

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

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ package com.rngooglemapsplus
22

33
import android.graphics.Color
44
import com.facebook.react.uimanager.PixelUtil.dpToPx
5-
import com.google.android.gms.maps.model.ButtCap
6-
import com.google.android.gms.maps.model.Cap
7-
import com.google.android.gms.maps.model.JointType
85
import com.google.android.gms.maps.model.Polyline
96
import com.google.android.gms.maps.model.PolylineOptions
10-
import com.google.android.gms.maps.model.RoundCap
11-
import com.google.android.gms.maps.model.SquareCap
7+
import com.rngooglemapsplus.extensions.coordinatesEquals
128
import com.rngooglemapsplus.extensions.onUi
139
import com.rngooglemapsplus.extensions.toColor
1410
import com.rngooglemapsplus.extensions.toLatLng
11+
import com.rngooglemapsplus.extensions.toMapJointType
12+
import com.rngooglemapsplus.extensions.toMapLineCap
1513

1614
class MapPolylineBuilder {
1715
fun build(pl: RNPolyline): PolylineOptions =
@@ -21,10 +19,10 @@ class MapPolylineBuilder {
2119
}
2220
pl.width?.let { width(it.dpToPx()) }
2321
pl.lineCap?.let {
24-
startCap(mapLineCap(it))
25-
endCap(mapLineCap(it))
22+
startCap(it.toMapLineCap())
23+
endCap(it.toMapLineCap())
2624
}
27-
pl.lineJoin?.let { jointType(mapLineJoin(it)) }
25+
pl.lineJoin?.let { jointType(it.toMapJointType()) }
2826
pl.color?.let { color(it.toColor()) }
2927
pl.geodesic?.let { geodesic(it) }
3028
pl.pressable?.let { clickable(it) }
@@ -36,31 +34,21 @@ class MapPolylineBuilder {
3634
next: RNPolyline,
3735
polyline: Polyline,
3836
) = onUi {
39-
val coordsChanged =
40-
prev.coordinates.size != next.coordinates.size ||
41-
!prev.coordinates.zip(next.coordinates).all { (a, b) ->
42-
a.latitude == b.latitude && a.longitude == b.longitude
43-
}
44-
45-
if (coordsChanged) {
37+
if (!prev.coordinatesEquals(next)) {
4638
polyline.points = next.coordinates.map { it.toLatLng() }
4739
}
4840

4941
if (prev.width != next.width) {
5042
polyline.width = next.width?.dpToPx() ?: 1f
5143
}
5244

53-
val newCap = mapLineCap(next.lineCap ?: RNLineCapType.BUTT)
54-
val prevCap = mapLineCap(prev.lineCap ?: RNLineCapType.BUTT)
55-
if (newCap != prevCap) {
56-
polyline.startCap = newCap
57-
polyline.endCap = newCap
45+
if (prev.lineCap != next.lineCap) {
46+
polyline.startCap = next.lineCap.toMapLineCap()
47+
polyline.endCap = next.lineCap.toMapLineCap()
5848
}
5949

60-
val newJoin = mapLineJoin(next.lineJoin ?: RNLineJoinType.MITER)
61-
val prevJoin = mapLineJoin(prev.lineJoin ?: RNLineJoinType.MITER)
62-
if (newJoin != prevJoin) {
63-
polyline.jointType = newJoin
50+
if (prev.lineJoin != next.lineJoin) {
51+
polyline.jointType = next.lineJoin.toMapJointType()
6452
}
6553

6654
if (prev.color != next.color) {
@@ -79,19 +67,4 @@ class MapPolylineBuilder {
7967
polyline.zIndex = next.zIndex?.toFloat() ?: 0f
8068
}
8169
}
82-
83-
private fun mapLineCap(type: RNLineCapType?): Cap =
84-
when (type) {
85-
RNLineCapType.ROUND -> RoundCap()
86-
RNLineCapType.SQUARE -> SquareCap()
87-
else -> ButtCap()
88-
}
89-
90-
private fun mapLineJoin(type: RNLineJoinType?): Int =
91-
when (type) {
92-
RNLineJoinType.ROUND -> JointType.ROUND
93-
RNLineJoinType.BEVEL -> JointType.BEVEL
94-
RNLineJoinType.MITER -> JointType.DEFAULT
95-
null -> JointType.DEFAULT
96-
}
9770
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.rngooglemapsplus.extensions.markerEquals
1212
import com.rngooglemapsplus.extensions.polygonEquals
1313
import com.rngooglemapsplus.extensions.polylineEquals
1414
import com.rngooglemapsplus.extensions.toCameraPosition
15+
import com.rngooglemapsplus.extensions.toColor
1516
import com.rngooglemapsplus.extensions.toCompressFormat
1617
import com.rngooglemapsplus.extensions.toFileExtension
1718
import com.rngooglemapsplus.extensions.toGoogleMapType
@@ -48,6 +49,7 @@ class RNGoogleMapsPlusView(
4849
initialProps?.mapId?.let { mapId(it) }
4950
initialProps?.liteMode?.let { liteMode(it) }
5051
initialProps?.camera?.let { camera(it.toCameraPosition(current = null)) }
52+
initialProps?.backgroundColor?.let { backgroundColor(it.toColor()) }
5153
}
5254
view.initMapView(options)
5355
}
@@ -149,7 +151,7 @@ class RNGoogleMapsPlusView(
149151
val prev = prevById[id]
150152
when {
151153
prev == null ->
152-
markerBuilder.buildIconAsync(id, next) { icon ->
154+
markerBuilder.buildIconAsync(next) { icon ->
153155
view.addMarker(
154156
id,
155157
markerBuilder.build(next, icon),

0 commit comments

Comments
 (0)