Open lucas-livefront opened 1 year ago
@lucas-livefront Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:
google-maps
tagThis is an automated message, feel free to ignore.
Thanks for the very detailed report!
I think we can avoid recomposing the GoogleMap
's content
when padding changes. Not immediately sure how much of the performance hit is from that recomposition or just the padding being a heavy operation that likely wasn't originally meant to be animated. I'll report back with more info.
Much appreciated. The capacity to animate in a clean way is super valuable to my app!
@lucas-livefront I am also having some sort of similar usecase and I need to update padding multiple time but I didn't faced any recomposition below is my approach
MapEffect(key1 = padding) { map ->
map.setPadding(padding.start, padding.top, padding.end, padding.bottom)
}
@pseudoankit what type of object is map
? I have not seen this setPadding
function exposes by the Google Maps Compose API.
@lucas-livefront you can call MapEffect
block inside GoogleCompose
and check this
Very nice find @pseudoankit. I was embarrassingly unaware of the MapEffect
utility.
It does completely solve the recomposition issue however the animation is slightly delayed. 🤔 Definitely an improvement!
Introduction
The crux of my issue is that when I provide
contentPadding
to theGoogleMap
component it causes recompositions. I need to update the content padding often because I have a bottom sheet for displaying search results! (we modeled it after the Google Maps app) If I have many pins (20-50) on the map the UX is severely hindered and there is a lot of lag.We really want to update the content padding dynamically as it creates a nice UX and allows us to better utilize the
GoogleMap
animation APIs. Not to mention, it allows us to keep theGoogle
logo visible.Anyway, since this API is merely a wrapper around the XML Google Maps implementation I suspect there are some limitations to how well you can optimize this behavior. However, I must expose this issue as it isn't an easy thing to fix on my end and it seriously affects the major production app that I work on with many millions of users.
I can do a few things to kludge this:
Environment details
Steps to reproduce
I made a repo to reproduce this and illuminate the issues I am seeing!
Clone the repo!
Add your API key to
local.properties
by inserting this line and replacing<your-key>
with a valid key!Then simply run the app and turn on the layout inspector and monitor the recompositions! There are two examples:
MapExample
andCustomComponentExample
.MapExample
is meant to illustrate the many recompositions that occur when we adjust content padding.CustomComponentExample
is meant to illustrate how we can avoid recompositions while still updating content padding!In order to experiment with the two different examples go to
MainActivity.kt
and you can swap them out!Demos
MapExample
CustomComponentExample
April 7, 2023 Update
Due to the comment by @pseudoankit I added a
MapEffectExample
as well. This helps illustrate the pros and cons of that approach.