Skip to content

fix: minor enhancements for DraggableMarkersCollectionWithPolygonActi… #674

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

Merged
merged 2 commits into from
Jan 29, 2025
Merged
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 @@ -25,10 +25,10 @@ import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshots.SnapshotStateMap
import androidx.compose.runtime.toMutableStateMap
import androidx.compose.ui.Modifier
import com.google.android.gms.maps.model.LatLng
import com.google.maps.android.compose.GoogleMap
Expand Down Expand Up @@ -64,11 +64,10 @@ private class DraggableMarkersModel(dataModel: Map<LocationKey, LocationData>) {
// This initializes MarkerState from our model once (model is initial source of truth)
// and never updates it from the model afterwards.
// See SyncingDraggableMarkerWithDataModelActivity for rationale.
private val markerDataMap: SnapshotStateMap<LocationKey, MarkerState> = mutableStateMapOf(
*dataModel.entries.map { (locationKey, locationData) ->
private val markerDataMap: SnapshotStateMap<LocationKey, MarkerState> =
dataModel.entries.map { (locationKey, locationData) ->
locationKey to MarkerState(locationData.position)
}.toTypedArray()
)
}.toMutableStateMap()

/** Add new marker location to model */
fun addLocation(locationData: LocationData) {
Expand Down Expand Up @@ -165,20 +164,18 @@ private fun GoogleMapWithLocations(
* A draggable GoogleMap Marker representing a location on the map
*/
@Composable
private fun LocationMarker(
private inline fun LocationMarker(
markerState: MarkerState,
onClick: () -> Unit
) {
Marker(
state = markerState,
draggable = true,
onClick = {
onClick()

true
}
)
}
crossinline onClick: () -> Unit
) = Marker(
state = markerState,
draggable = true,
onClick = {
onClick()

true
}
)

/**
* A Polygon. Helps isolate recompositions while a Marker is being dragged.
Expand Down