-
Notifications
You must be signed in to change notification settings - Fork 181
Setting CameraPositionState.position is not stateful #523
Copy link
Copy link
Open
Labels
priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
Activity
Metadata
Metadata
Assignees
Labels
priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
android-maps-compose 4.3.3
Setting
CameraPositionState.positionis not stateful. (Setting the property calls through to theGoogleMapSDK and immediately changes the camera position on the map.) This is an invalid Compose architectural decision:positionis its primary public property, so setting it must be stateful to not completely defy user expectations.MarkerState.positionis stateful. The behavior ofCameraPositionStateis different when it should be the same.The general impact is that setting it via snapshot state does not work correctly. This is a fundamental violation of normal Compose behavior.
For example, a user might attempt something like this to control camera position, which mimics the behavior of
rememberUpdatedState(), but forCameraPositionStateinstead ofMutableState:This approach is normally sound, but not valid here, because setting
CameraStatePosition.positionis a side effect (irreversible), instead of setting snapshot state. For example, if the composition is cancelled, the new camera position remains set.CameraPositionState.move()can only be called from the main thread, so disallowing setter access in favor of this method is not a great workaround.android-maps-compose/maps-compose/src/main/java/com/google/maps/android/compose/CameraPositionState.kt
Lines 97 to 111 in f857fc4