File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
maps-app/src/main/java/com/google/maps/android/compose
maps-compose/src/main/java/com/google/maps/android/compose Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,6 @@ fun MapsInLazyColumn(
152152
153153 val cameraPositionStates = mapItems.associate { item ->
154154 item.id to rememberCameraPositionState(
155- key = item.id,
156155 init = { position = CameraPosition .fromLatLngZoom(item.location, item.zoom) }
157156 )
158157 }
Original file line number Diff line number Diff line change @@ -40,12 +40,35 @@ import java.lang.Integer.MAX_VALUE
4040import kotlin.coroutines.resume
4141import kotlin.coroutines.resumeWithException
4242
43+ /* *
44+ * Creates and remembers a [CameraPositionState] using [rememberSaveable].
45+ *
46+ * The camera position state is saved across configuration changes and process death,
47+ * ensuring the map retains its last position.
48+ *
49+ * @param init A lambda that is called when the [CameraPositionState] is first created to
50+ * configure its initial state, such as its position or zoom level.
51+ */
52+ @Composable
53+ public inline fun rememberCameraPositionState (
54+ crossinline init : CameraPositionState .() -> Unit = {}
55+ ): CameraPositionState = rememberSaveable(saver = CameraPositionState .Saver ) {
56+ CameraPositionState ().apply (init )
57+ }
58+
4359/* *
4460 * Create and [rememberSaveable] a [CameraPositionState] using [CameraPositionState.Saver].
4561 * [init] will be called when the [CameraPositionState] is first created to configure its
4662 * initial state. Remember that the camera state can be applied when the map has been
4763 * loaded.
4864 */
65+ @Deprecated(
66+ message = " The 'key' parameter is deprecated. Please use the new `rememberCameraPositionState` function without a key." ,
67+ replaceWith = ReplaceWith (
68+ " rememberCameraPositionState(init)" ,
69+ " com.google.maps.android.compose.rememberCameraPositionState"
70+ )
71+ )
4972@Composable
5073public inline fun rememberCameraPositionState (
5174 key : String? = null,
You can’t perform that action at this time.
0 commit comments