-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating contentPadding
causes recompositions
#293
Comments
If you would like to upvote the priority of this issue, please comment below or react with 👍 so we can see what is popular when we triage.@lucas-livefront Thank you for opening this issue. 🙏
This is an automated message, feel free to ignore. |
Thanks for the very detailed report! |
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
|
@pseudoankit what type of object is |
@lucas-livefront you can call |
Very nice find @pseudoankit. I was embarrassingly unaware of the It does completely solve the recomposition issue however the animation is slightly delayed. 🤔 mapEffect.mp4 |
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
Screen.Recording.2023-03-17.at.2.25.15.PM.mov
Screen.Recording.2023-03-17.at.2.27.12.PM.mov
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.The text was updated successfully, but these errors were encountered: