googlemaps / googlemaps/android-maps-compose

Using rememberCameraPositionState and observing it via a lambda, makes entire map recompose instead of just of the lambda

Open
#216 7 comments 0 reactions 0 assignees View on GitHub
priority: p3 type: question
Dominant language
Kotlin
Stars
1.3k
Forks
181
Avg merge
2d 23h
Merged PRs (30d)
18

Description

I am using the `rememberCameraPositionState` like so, and then exposing a callback from my custom google map wrapper to observe the state

```
val cameraPositionState =
rememberCameraPositionState {
position =
CameraPosition.fromLatLngZoom(
mapInitialTargetLocation,
14f
)

//Custom callback exposed from map
onMapCameraPositionStateChanged: (CameraPositionState) -> Unit = {},

```

However when I try to use this map, and trigger an operation from the viewModel, it recomposes infinitely

```
fun ParentComposable(){

MapContent(viewModel::onCameraPositionStateChanged)

}

//Calling this function from above parent composable like so
// CustomerMap is my own wrapper around GoogleMap for convenience

private fun MapContent(
onCameraStateChanged : (CameraPositionState) -> Unit
) {
CustomerMap(
......,
onMapCameraPositionStateChanged = onCameraStateChanged
}
```

What am I doing wrong, or is it just a Google Map issue?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.