-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMapCircleBuilder.kt
More file actions
57 lines (48 loc) · 1.61 KB
/
MapCircleBuilder.kt
File metadata and controls
57 lines (48 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.rngooglemapsplus
import android.graphics.Color
import com.facebook.react.uimanager.PixelUtil.dpToPx
import com.google.android.gms.maps.model.Circle
import com.google.android.gms.maps.model.CircleOptions
import com.rngooglemapsplus.extensions.toColor
import com.rngooglemapsplus.extensions.toLatLng
class MapCircleBuilder {
fun build(circle: RNCircle): CircleOptions =
CircleOptions().apply {
center(circle.center.toLatLng())
radius(circle.radius)
circle.strokeWidth?.let { strokeWidth(it.dpToPx()) }
circle.strokeColor?.let { strokeColor(it.toColor()) }
circle.fillColor?.let { fillColor(it.toColor()) }
circle.pressable?.let { clickable(it) }
circle.zIndex?.let { zIndex(it.toFloat()) }
}
fun update(
prev: RNCircle,
next: RNCircle,
circle: Circle,
) {
if (prev.center.latitude != next.center.latitude ||
prev.center.longitude != next.center.longitude
) {
circle.center = next.center.toLatLng()
}
if (prev.radius != next.radius) {
circle.radius = next.radius
}
if (prev.strokeWidth != next.strokeWidth) {
circle.strokeWidth = next.strokeWidth?.dpToPx() ?: 1f
}
if (prev.strokeColor != next.strokeColor) {
circle.strokeColor = next.strokeColor?.toColor() ?: Color.BLACK
}
if (prev.fillColor != next.fillColor) {
circle.fillColor = next.fillColor?.toColor() ?: Color.TRANSPARENT
}
if (prev.pressable != next.pressable) {
circle.isClickable = next.pressable ?: false
}
if (prev.zIndex != next.zIndex) {
circle.zIndex = next.zIndex?.toFloat() ?: 0f
}
}
}