android / nowinandroid

A fully functional Android app built entirely with Kotlin and Jetpack Compose
Apache License 2.0
17.37k stars 3.17k forks source link

[Bug]: Redundant full screen recompositions on UI state change #1168

Open Trace95 opened 10 months ago

Trace95 commented 10 months ago

Is there an existing issue for this?

Is there a StackOverflow question about this issue?

What happened?

When performing any sort of UI action that results in a state change, for example, toggling one of the options in the interests tab, the entire UI is recomposed even though only one item in the list needs to be recomposed. You can reproduce this easily by checking the layout inspector with the show recompositions toggle on and toggling one of the options in the interests tab.

Relevant logcat output

No response

Code of Conduct

rishi2062 commented 10 months ago

Can i look into it?? , maybe a problem of state hoisting.

rishi2062 commented 10 months ago

In this bug, whenever toggling one of the options in interests tab, it is leading with what happen when we click to toggle it. Here, every time we toggle the option, it adds or removes the followedTopicId, resulting the followableTopicList in updating everytime, making LazyColumn to recompose every time and so whole UI is getting recompositions. To Fix this either we have to change

  1. In interests section, instead of fetching followableTopicList, we can fetch TopicList directly, and handle onFollowButton to update the follow toggle as same
  2. When the activity comes to OnResume State we will update our topicList with followableTopicList, so that when that page opens every time, first time it will get recomposed and thereafter any changes will be stored to followableTopicList.

Inorder to follow these steps, a lot of code changes needed.

Open for any discussion, suggestion or new ideas to follow up this issue. Correct me if i am wrong anywhere.