google / flexbox-layout

Flexbox for Android
Apache License 2.0
18.27k stars 1.8k forks source link

FlexboxLayoutManager does not recycle views with Navgraph #628

Open ShahidAnjum opened 1 year ago

ShahidAnjum commented 1 year ago

Steps to reproduce

1: Create application with Navigation component (NavGraph and BottomNavigationView) 2: Create two fragments for Each tab of BottomNavigationView (HomeFragment & ListFragment) 3: Load items in (ListFragment) recycler view with pagination. Until here, there is no issue because view recycling is carried out correctly with each page's data. 4: Change the tab from ListFragment to HomeFragment, then back to ListFragment. View recycling fails at this point, and all views are created at once. However, the list's scroll state is preserved, which is handled by default when using NavGraph.

Expected behavior

View recycling should work properly even when the tab is switched, and only the list positions that are visible should be rendered. View recycling works perfectly fine when using LinearLayoutManager or GridLayoutManager

Version of the flexbox library

e.g. 3.0.0

Link to code

Github link of the sample project: https://github.com/ShahidAnjum/FlexBoxSample

ShahidAnjum commented 1 year ago

When the list gets too big, the app sometimes crashes and causes ANR. because when you switch the fragments in the navGraph, all the items are created at once.

thegypsydev commented 1 year ago

I also face this similar issue, please let us know if you find any solution

anjaliisinghh1 commented 1 year ago

Facing the same issue in my case as well. Please look into it.

iamMehedi commented 4 weeks ago

@thagikura any idea why this is happening or how it can be fixed?

iamMehedi commented 1 week ago

I have created a fork and updated the dependencies. The items in the grid uses DataBinding, I made a call to binding.executePendingBindings() after setting the variables in onBindViewHolder and made sure that at that point the item has a defined size. That seem to have resolved the issue for me.