facebook / litho

A declarative framework for building efficient UIs on Android.
https://fblitho.com
Apache License 2.0
7.69k stars 761 forks source link

LithoView update delay #1011

Closed hou3172568 closed 2 days ago

hou3172568 commented 2 weeks ago

Version

Litho 0.47

Issues and Steps to Reproduce

When using LithoView as an Item in Android RecyclerView, when holder reuse and fast sliding causes update delays, causing the last view style to appear before updating to the new style; then i use setRootSync API, there is not smooth

Expected Behavior

the item update without delay

Link to Code

//this case is reuse if (tree != null && null != dataListenerWrapper) { //for async, update delays request()?.let { //let root component updateState dataListenerWrapper?.onReceive(it) } //for sync,not smooth tree?.setRootSync(MyComponent.create().build()) } }

zielinskimz commented 1 week ago

Hey, it's hard to tell what may be wrong based on the small code sample that you shared. It would be helpful if you could create a small project that reproduces the issue so that we can take a look.

hou3172568 commented 1 week ago

In other words, the best practices for using LithoView in RecyclerView on Android

fbcbl commented 2 days ago

Hello,

Ideally, you should try to use Litho APIs to emulate the list you want to render. Therefore, the recommendation would be to actually use a LazyList.

If you have to integrate a LithoView item in a RecyclerView, it makes the solution more complex, because you have to manage the preparation (i.e, create it and set the root asynchronously, so that it can benefit from the background processing) of the ComponentTree for each LithoView, so that you have a performant implementation. This means, that you have to create a sliding window mechanism, and prepare the ComponentTree ahead of time, so that whenever the RecyclerView children are bound, you are able to just set the already prepared ComponentTree into that LithoView.

Thanks!