Skip to content
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 @@ -152,7 +152,6 @@ fun MapsInLazyColumn(

val cameraPositionStates = mapItems.associate { item ->
item.id to rememberCameraPositionState(
key = item.id,
init = { position = CameraPosition.fromLatLngZoom(item.location, item.zoom) }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,35 @@ import java.lang.Integer.MAX_VALUE
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException

/**
* Creates and remembers a [CameraPositionState] using [rememberSaveable].
*
* The camera position state is saved across configuration changes and process death,
* ensuring the map retains its last position.
*
* @param init A lambda that is called when the [CameraPositionState] is first created to
* configure its initial state, such as its position or zoom level.
*/
@Composable
public inline fun rememberCameraPositionState(
crossinline init: CameraPositionState.() -> Unit = {}
): CameraPositionState = rememberSaveable(saver = CameraPositionState.Saver) {
CameraPositionState().apply(init)
}

/**
* Create and [rememberSaveable] a [CameraPositionState] using [CameraPositionState.Saver].
* [init] will be called when the [CameraPositionState] is first created to configure its
* initial state. Remember that the camera state can be applied when the map has been
* loaded.
*/
@Deprecated(
message = "The 'key' parameter is deprecated. Please use the new `rememberCameraPositionState` function without a key.",
replaceWith = ReplaceWith(
"rememberCameraPositionState(init)",
"com.google.maps.android.compose.rememberCameraPositionState"
)
)
@Composable
public inline fun rememberCameraPositionState(
key: String? = null,
Expand Down
Loading