Open bubenheimer opened 9 months ago
Another consequence: updating padding and camera position together is not possible - camera will always be set instantly, then eventually padding when applying composition. This means that the camera will not be centered within the updated padding.
If CameraPositionState.position
was backed by MutableState
, then the API could update padding and camera in the appropriate order.
This is related to #142
This issue remains unresolved.
android-maps-compose 4.3.3
Setting
CameraPositionState.position
is not stateful. (Setting the property calls through to theGoogleMap
SDK and immediately changes the camera position on the map.) This is an invalid Compose architectural decision:position
is its primary public property, so setting it must be stateful to not completely defy user expectations.MarkerState.position
is stateful. The behavior ofCameraPositionState
is 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 forCameraPositionState
instead ofMutableState
:This approach is normally sound, but not valid here, because setting
CameraStatePosition.position
is 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.https://github.com/googlemaps/android-maps-compose/blob/f857fc48bf1a05191d363cd8fdb19692b284fc30/maps-compose/src/main/java/com/google/maps/android/compose/CameraPositionState.kt#L97-L111