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(
152
152
153
153
val cameraPositionStates = mapItems.associate { item ->
154
154
item.id to rememberCameraPositionState(
155
- key = item.id,
156
155
init = { position = CameraPosition .fromLatLngZoom(item.location, item.zoom) }
157
156
)
158
157
}
Original file line number Diff line number Diff line change @@ -40,12 +40,35 @@ import java.lang.Integer.MAX_VALUE
40
40
import kotlin.coroutines.resume
41
41
import kotlin.coroutines.resumeWithException
42
42
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
+
43
59
/* *
44
60
* Create and [rememberSaveable] a [CameraPositionState] using [CameraPositionState.Saver].
45
61
* [init] will be called when the [CameraPositionState] is first created to configure its
46
62
* initial state. Remember that the camera state can be applied when the map has been
47
63
* loaded.
48
64
*/
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
+ )
49
72
@Composable
50
73
public inline fun rememberCameraPositionState (
51
74
key : String? = null,
You can’t perform that action at this time.
0 commit comments