googlemaps / android-maps-compose

Jetpack Compose composables for the Maps SDK for Android
https://developers.google.com/maps/documentation/android-sdk/maps-compose
Apache License 2.0
1.14k stars 135 forks source link

Immutable Collection prevent composition many times even if required #306

Open pseudoankit opened 1 year ago

pseudoankit commented 1 year ago

I need to draw polylines if I pass List<LatLng> it's fine but recomposing unnecessarily

https://user-images.githubusercontent.com/54987308/231945860-6d484479-51b3-41c4-9d0f-edb1875f887d.mov


if I pass ImmutableList<LatLng> it's skipping composition even if required many times

https://user-images.githubusercontent.com/54987308/231947188-6521e465-a799-48d0-8d08-c5c6f7f7ec6d.mov

wangela commented 1 year ago

If you would like to upvote the priority of this issue, please comment below or react with :+1: so we can see what is popular when we triage.

@pseudoankit Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.

pseudoankit commented 1 year ago

Update : Even if we mark data class with @Stable then also many times it skips composition

pseudoankit commented 1 year ago

Update 2: got some workaround wrapping the compose method with key block and providing the list as key seems to work when using ImmutableCollection

data class Polyline(val latLngs : ImmutableList<LatLng>)
val mapPolylineList = persistentListOf<Polyline>()
key(mapPolylineList) {
    PlotPolyline(mapPolyline = mapPolylineList)
}
GaneshShetty951 commented 1 year ago

Update 2: got some workaround wrapping the compose method with key block and providing the list as key seems to work when using ImmutableCollection

data class Polyline(val latLngs : ImmutableList<LatLng>)
val mapPolylineList = persistentListOf<Polyline>()
key(mapPolylineList) {
    PlotPolyline(mapPolyline = mapPolylineList)
}

Any explanation on how this works ??

pseudoankit commented 1 year ago

@GaneshShetty951 it's does exactly same how having parms in composable works but for some reasons composable annotated with @GoogeMapsCompose was not behaving correctly so key block also does the same if value changes then only it will recompose it's block

mosmb commented 1 year ago

Exact same behavior with Marker. Using ImmutableCollection does not trigger a recomposition of Marker which causes some markers to not appear