Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: switched from set() to update() #564

Merged
merged 8 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ public fun Circle(
update = {
update(onClick) { this.onCircleClick = it }

set(center) { this.circle.center = it }
set(clickable) { this.circle.isClickable = it }
set(fillColor) { this.circle.fillColor = it.toArgb() }
set(radius) { this.circle.radius = it }
set(strokeColor) { this.circle.strokeColor = it.toArgb() }
set(strokePattern) { this.circle.strokePattern = it }
set(strokeWidth) { this.circle.strokeWidth = it }
set(tag) { this.circle.tag = it }
set(visible) { this.circle.isVisible = it }
set(zIndex) { this.circle.zIndex = it }
update(center) { this.circle.center = it }
update(clickable) { this.circle.isClickable = it }
update(fillColor) { this.circle.fillColor = it.toArgb() }
update(radius) { this.circle.radius = it }
update(strokeColor) { this.circle.strokeColor = it.toArgb() }
update(strokePattern) { this.circle.strokePattern = it }
update(strokeWidth) { this.circle.strokeWidth = it }
update(tag) { this.circle.tag = it }
update(visible) { this.circle.isVisible = it }
update(zIndex) { this.circle.zIndex = it }
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ public fun GroundOverlay(
update = {
update(onClick) { this.onGroundOverlayClick = it }

set(bearing) { this.groundOverlay.bearing = it }
set(clickable) { this.groundOverlay.isClickable = it }
set(image) { this.groundOverlay.setImage(it) }
set(position) { this.groundOverlay.position(it) }
set(tag) { this.groundOverlay.tag = it }
set(transparency) { this.groundOverlay.transparency = it }
set(visible) { this.groundOverlay.isVisible = it }
set(zIndex) { this.groundOverlay.zIndex = it }
update(bearing) { this.groundOverlay.bearing = it }
update(clickable) { this.groundOverlay.isClickable = it }
update(image) { this.groundOverlay.setImage(it) }
update(position) { this.groundOverlay.position(it) }
update(tag) { this.groundOverlay.tag = it }
update(transparency) { this.groundOverlay.transparency = it }
update(visible) { this.groundOverlay.isVisible = it }
update(zIndex) { this.groundOverlay.zIndex = it }
}
)
}
Expand Down
114 changes: 66 additions & 48 deletions maps-compose/src/main/java/com/google/maps/android/compose/Marker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ public fun rememberMarkerState(

/**
* A composable for a marker on the map.
* @param contentDescription the content description for accessibility purposes
* @param state the [MarkerState] to be used to control or observe the marker
* state such as its position and info window
* @param contentDescription the content description for accessibility purposes
* @param state such as its position and info window
* @param alpha the alpha (opacity) of the marker
* @param anchor the anchor for the marker image
* @param draggable sets the draggability for the marker
Expand All @@ -156,8 +156,8 @@ public fun rememberMarkerState(
@Composable
@GoogleMapComposable
public fun Marker(
contentDescription: String? = "",
state: MarkerState = rememberMarkerState(),
contentDescription: String? = "",
alpha: Float = 1.0f,
anchor: Offset = Offset(0.5f, 1.0f),
draggable: Boolean = false,
Expand All @@ -176,8 +176,8 @@ public fun Marker(
onInfoWindowLongClick: (Marker) -> Unit = {},
) {
MarkerImpl(
contentDescription = contentDescription,
state = state,
contentDescription = contentDescription,
alpha = alpha,
anchor = anchor,
draggable = draggable,
Expand All @@ -203,7 +203,8 @@ public fun Marker(
* @param keys unique keys representing the state of this Marker. Any changes to one of the key will
* trigger a rendering of the content composable and thus the rendering of an updated marker.
* @param state the [MarkerState] to be used to control or observe the marker
* state such as its position and info window
* @param state such as its position and info window
* @param contentDescription the content description for accessibility purposes
* @param alpha the alpha (opacity) of the marker
* @param anchor the anchor for the marker image
* @param draggable sets the draggability for the marker
Expand All @@ -226,6 +227,7 @@ public fun Marker(
public fun MarkerComposable(
vararg keys: Any,
state: MarkerState = rememberMarkerState(),
contentDescription: String? = "",
alpha: Float = 1.0f,
anchor: Offset = Offset(0.5f, 1.0f),
draggable: Boolean = false,
Expand All @@ -247,6 +249,7 @@ public fun MarkerComposable(

MarkerImpl(
state = state,
contentDescription = contentDescription,
alpha = alpha,
anchor = anchor,
draggable = draggable,
Expand All @@ -272,7 +275,7 @@ public fun MarkerComposable(
* [com.google.maps.android.compose.Marker].
*
* @param state the [MarkerState] to be used to control or observe the marker
* state such as its position and info window
* @param state such as its position and info window
* @param alpha the alpha (opacity) of the marker
* @param anchor the anchor for the marker image
* @param draggable sets the draggability for the marker
Expand Down Expand Up @@ -342,7 +345,7 @@ public fun MarkerInfoWindow(
* [com.google.maps.android.compose.Marker].
*
* @param state the [MarkerState] to be used to control or observe the marker
* state such as its position and info window
* @param state such as its position and info window
* @param alpha the alpha (opacity) of the marker
* @param anchor the anchor for the marker image
* @param draggable sets the draggability for the marker
Expand Down Expand Up @@ -410,7 +413,8 @@ public fun MarkerInfoWindowContent(
* Internal implementation for a marker on a Google map.
*
* @param state the [MarkerState] to be used to control or observe the marker
* state such as its position and info window
* @param state such as its position and info window
* @param contentDescription the content description for accessibility purposes
* @param alpha the alpha (opacity) of the marker
* @param anchor the anchor for the marker image
* @param draggable sets the draggability for the marker
Expand All @@ -436,8 +440,8 @@ public fun MarkerInfoWindowContent(
@Composable
@GoogleMapComposable
private fun MarkerImpl(
contentDescription: String? = "",
state: MarkerState = rememberMarkerState(),
contentDescription: String? = "",
alpha: Float = 1.0f,
anchor: Offset = Offset(0.5f, 1.0f),
draggable: Boolean = false,
Expand Down Expand Up @@ -497,29 +501,29 @@ private fun MarkerImpl(
update(infoContent) { this.infoContent = it }
update(infoWindow) { this.infoWindow = it }

set(alpha) { this.marker.alpha = it }
set(anchor) { this.marker.setAnchor(it.x, it.y) }
set(draggable) { this.marker.isDraggable = it }
set(flat) { this.marker.isFlat = it }
set(icon) { this.marker.setIcon(it) }
set(infoWindowAnchor) { this.marker.setInfoWindowAnchor(it.x, it.y) }
set(state.position) { this.marker.position = it }
set(rotation) { this.marker.rotation = it }
set(snippet) {
update(alpha) { this.marker.alpha = it }
update(anchor) { this.marker.setAnchor(it.x, it.y) }
update(draggable) { this.marker.isDraggable = it }
update(flat) { this.marker.isFlat = it }
update(icon) { this.marker.setIcon(it) }
update(infoWindowAnchor) { this.marker.setInfoWindowAnchor(it.x, it.y) }
update(state.position) { this.marker.position = it }
update(rotation) { this.marker.rotation = it }
update(snippet) {
this.marker.snippet = it
if (this.marker.isInfoWindowShown) {
this.marker.showInfoWindow()
}
}
set(tag) { this.marker.tag = it }
set(title) {
update(tag) { this.marker.tag = it }
update(title) {
this.marker.title = it
if (this.marker.isInfoWindowShown) {
this.marker.showInfoWindow()
}
}
set(visible) { this.marker.isVisible = it }
set(zIndex) { this.marker.zIndex = it }
update(visible) { this.marker.isVisible = it }
update(zIndex) { this.marker.zIndex = it }
}
)
}
Expand All @@ -529,7 +533,8 @@ private fun MarkerImpl(
* A composable for an advanced marker on the map.
*
* @param state the [MarkerState] to be used to control or observe the marker
* state such as its position and info window
* @param contentDescription the content description for accessibility purposes
* @param state such as its position and info window
* @param alpha the alpha (opacity) of the marker
* @param anchor the anchor for the marker image
* @param draggable sets the draggability for the marker
Expand All @@ -553,6 +558,7 @@ private fun MarkerImpl(
@GoogleMapComposable
public fun AdvancedMarker(
state: MarkerState = rememberMarkerState(),
contentDescription: String? = "",
alpha: Float = 1.0f,
anchor: Offset = Offset(0.5f, 1.0f),
draggable: Boolean = false,
Expand All @@ -572,9 +578,9 @@ public fun AdvancedMarker(
iconView: View? = null,
collisionBehavior: Int = AdvancedMarkerOptions.CollisionBehavior.REQUIRED
) {

AdvancedMarkerImpl(
state = state,
contentDescription = contentDescription,
alpha = alpha,
anchor = anchor,
draggable = draggable,
Expand All @@ -600,7 +606,8 @@ public fun AdvancedMarker(
* Internal implementation for an advanced marker on a Google map.
*
* @param state the [MarkerState] to be used to control or observe the marker
* state such as its position and info window
* @param contentDescription the content description for accessibility purposes
* @param state such as its position and info window
* @param alpha the alpha (opacity) of the marker
* @param anchor the anchor for the marker image
* @param draggable sets the draggability for the marker
Expand Down Expand Up @@ -628,8 +635,8 @@ public fun AdvancedMarker(
@Composable
@GoogleMapComposable
private fun AdvancedMarkerImpl(

state: MarkerState = rememberMarkerState(),
contentDescription: String? = "",
alpha: Float = 1.0f,
anchor: Offset = Offset(0.5f, 1.0f),
draggable: Boolean = false,
Expand All @@ -655,17 +662,28 @@ private fun AdvancedMarkerImpl(
val mapApplier = currentComposer.applier as? MapApplier
val compositionContext = rememberCompositionContext()

val advancedMarkerOptions = AdvancedMarkerOptions()
.position(state.position)
.collisionBehavior(collisionBehavior)
if (iconView != null) {
advancedMarkerOptions.iconView(iconView)
} else if (pinConfig != null) {
advancedMarkerOptions.icon(BitmapDescriptorFactory.fromPinConfig(pinConfig))
}

ComposeNode<MarkerNode, MapApplier>(
factory = {
kikoso marked this conversation as resolved.
Show resolved Hide resolved
val advancedMarkerOptions = AdvancedMarkerOptions()
.position(state.position)
.collisionBehavior(collisionBehavior)
if (iconView != null) {
advancedMarkerOptions.iconView(iconView)
} else if (pinConfig != null) {
advancedMarkerOptions.icon(BitmapDescriptorFactory.fromPinConfig(pinConfig))
}
advancedMarkerOptions.contentDescription(contentDescription)
advancedMarkerOptions.alpha(alpha)
advancedMarkerOptions.anchor(anchor.x, anchor.y)
advancedMarkerOptions.draggable(draggable)
advancedMarkerOptions.flat(flat)
advancedMarkerOptions.infoWindowAnchor(infoWindowAnchor.x, infoWindowAnchor.y)
advancedMarkerOptions.position(state.position)
advancedMarkerOptions.rotation(rotation)
advancedMarkerOptions.snippet(snippet)
advancedMarkerOptions.title(title)
advancedMarkerOptions.visible(visible)
advancedMarkerOptions.zIndex(zIndex)
val marker = mapApplier?.map?.addMarker(advancedMarkerOptions)
?: error("Error adding marker")
marker.tag = tag
Expand All @@ -689,27 +707,27 @@ private fun AdvancedMarkerImpl(
update(infoContent) { this.infoContent = it }
update(infoWindow) { this.infoWindow = it }

set(alpha) { this.marker.alpha = it }
set(anchor) { this.marker.setAnchor(it.x, it.y) }
set(draggable) { this.marker.isDraggable = it }
set(flat) { this.marker.isFlat = it }
set(infoWindowAnchor) { this.marker.setInfoWindowAnchor(it.x, it.y) }
set(state.position) { this.marker.position = it }
set(rotation) { this.marker.rotation = it }
set(snippet) {
update(alpha) { this.marker.alpha = it }
update(anchor) { this.marker.setAnchor(it.x, it.y) }
update(draggable) { this.marker.isDraggable = it }
update(flat) { this.marker.isFlat = it }
update(infoWindowAnchor) { this.marker.setInfoWindowAnchor(it.x, it.y) }
update(state.position) { this.marker.position = it }
update(rotation) { this.marker.rotation = it }
update(snippet) {
this.marker.snippet = it
if (this.marker.isInfoWindowShown) {
this.marker.showInfoWindow()
}
}
set(tag) { this.marker.tag = it }
set(title) {
update(tag) { this.marker.tag = it }
update(title) {
this.marker.title = it
if (this.marker.isInfoWindowShown) {
this.marker.showInfoWindow()
}
}
set(pinConfig) {
update(pinConfig) {
if (iconView == null) {
this.marker.setIcon(pinConfig?.let { it1 ->
BitmapDescriptorFactory.fromPinConfig(
Expand All @@ -719,8 +737,8 @@ private fun AdvancedMarkerImpl(
}
}

set(visible) { this.marker.isVisible = it }
set(zIndex) { this.marker.zIndex = it }
update(visible) { this.marker.isVisible = it }
update(zIndex) { this.marker.zIndex = it }
kikoso marked this conversation as resolved.
Show resolved Hide resolved
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,18 @@ public fun Polygon(
},
update = {
update(onClick) { this.onPolygonClick = it }

set(points) { this.polygon.points = it }
set(clickable) { this.polygon.isClickable = it }
set(fillColor) { this.polygon.fillColor = it.toArgb() }
set(geodesic) { this.polygon.isGeodesic = it }
set(holes) { this.polygon.holes = it }
set(strokeColor) { this.polygon.strokeColor = it.toArgb() }
set(strokeJointType) { this.polygon.strokeJointType = it }
set(strokePattern) { this.polygon.strokePattern = it }
set(strokeWidth) { this.polygon.strokeWidth = it }
set(tag) { this.polygon.tag = it }
set(visible) { this.polygon.isVisible = it }
set(zIndex) { this.polygon.zIndex = it }
update(points) { this.polygon.points = it }
update(clickable) { this.polygon.isClickable = it }
update(fillColor) { this.polygon.fillColor = it.toArgb() }
update(geodesic) { this.polygon.isGeodesic = it }
update(holes) { this.polygon.holes = it }
update(strokeColor) { this.polygon.strokeColor = it.toArgb() }
update(strokeJointType) { this.polygon.strokeJointType = it }
update(strokePattern) { this.polygon.strokePattern = it }
update(strokeWidth) { this.polygon.strokeWidth = it }
update(tag) { this.polygon.tag = it }
update(visible) { this.polygon.isVisible = it }
update(zIndex) { this.polygon.zIndex = it }
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,19 @@ private fun PolylineImpl(
update = {
update(onClick) { this.onPolylineClick = it }

set(points) { this.polyline.points = it }
set(spans) { this.polyline.spans = it }
set(clickable) { this.polyline.isClickable = it }
set(color) { this.polyline.color = it.toArgb() }
set(endCap) { this.polyline.endCap = it }
set(geodesic) { this.polyline.isGeodesic = it }
set(jointType) { this.polyline.jointType = it }
set(pattern) { this.polyline.pattern = it }
set(startCap) { this.polyline.startCap = it }
set(tag) { this.polyline.tag = it }
set(visible) { this.polyline.isVisible = it }
set(width) { this.polyline.width = it }
set(zIndex) { this.polyline.zIndex = it }
update(points) { this.polyline.points = it }
update(spans) { this.polyline.spans = it }
update(clickable) { this.polyline.isClickable = it }
update(color) { this.polyline.color = it.toArgb() }
update(endCap) { this.polyline.endCap = it }
update(geodesic) { this.polyline.isGeodesic = it }
update(jointType) { this.polyline.jointType = it }
update(pattern) { this.polyline.pattern = it }
update(startCap) { this.polyline.startCap = it }
update(tag) { this.polyline.tag = it }
update(visible) { this.polyline.isVisible = it }
update(width) { this.polyline.width = it }
update(zIndex) { this.polyline.zIndex = it }
}
)
}
Loading