question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rememberCameraPositionState() should accept `inputs` parameter

See original GitHub issue

I noticed that in version 2.7.0 of maps-compose the function rememberCameraPositionState does not accept an inputs parameter although it just delegates to rememberSaveable, which has vararg inputs: Any?. Is this a deliberate design decision?

I have a situation where the value actually should be recreated because latitude and longitude change after the user has selected a different location.

I’m happy to provide a pull request if this is a desired change.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
arriolaccommented, Oct 20, 2022

Adding inputs to rememberMarkerState will not recreate the Marker so in theory you can expose inputs to both remember functions. But, recreating CameraPositionState needs to set the associated GoogleMap and MarkerState needs to set the correct internal Marker. These side effects make implementing this feature not so straightforward actually… I suggest holding off on the pull request for that reason.

1reaction
svenjacobscommented, Sep 8, 2022

Good point. In case of rememberCameraPositionState() I tried to work around it by using

val pos = remember(latitude, longitude) { LatLng(latitude, longitude) }
val cameraPositionState = rememberSaveable(pos, saver = CameraPositionState.Saver) {
    CameraPositionState(
        position = CameraPosition.fromLatLngZoom(pos, 17f),
    )
}

which works as expected but applying the same pattern to rememberMarkerState() did not work. The inner workings of Marker probably don’t take state changes into account at the moment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compose and other libraries - Android Developers
Any subclass of ActivityResultContract can be used as the first argument to rememberLauncherForActivityResult() . This means that you can use this technique ...
Read more >
Demo of crash when using HorizontalPager's scrollToPage ...
Configuring the map can be done by passing a MapProperties object into the GoogleMap composable, or for UI-related configurations, use ...
Read more >
Integrate Google Maps into the Jetpack Compose app
By just calling GoogleMap() we are going to show a map in our app. ... We can pass many parameters to this composable,...
Read more >
Jetpack Compose pass parameter to viewModel
you need to create a factory to pass dynamic parameter to ViewModel like this: class MyViewModelFactory(private val dbname: String) ...
Read more >
Composable Functions - Medium
You need to pass any and all information as parameters when you call it. ... When this value changes, Compose will automatically re-execute...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found