airbnb / mavericks

Mavericks: Android on Autopilot
https://airbnb.io/mavericks/
Apache License 2.0
5.85k stars 499 forks source link

need help. #636

Closed xuexixuexijpg closed 2 years ago

xuexixuexijpg commented 2 years ago

Hello, I used this library as an exercise, I found a problem, when I return from the current fragmentto the previous fragment, the scroll state of the previous fragmentlist is not saved, because the MavericksViewModelis not saved to the fragment status? But using Google's ViewModelpreserves the original scroll state. Is there any way or api to solve it? In addition, I did not use epoxyto build, because I practiced a single activity architecture, using epoxyin fragmentto report adapter leaks and the memory seems to increase rapidly. The currently used version of navigation and viewmodel is 2.5.0-rc01, the version of fragment is 1.5.0-rc01, and the version of mavericks is 2.7. Or is there anyone with the same problem? Is there any good solution? thanks

Snipaste_2022-06-16_11-01-16

xuexixuexijpg commented 2 years ago

image

Is it the wrong way for me to do this? The same is true for using withStatein the invalidatecallback in the fragment

xuexixuexijpg commented 2 years ago

image

This is the code that uses Google's ViewModel, and returns the same data filled with MavericksViewModel

gpeal commented 2 years ago

Would https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#PREVENT_WHEN_EMPTY help?

xuexixuexijpg commented 2 years ago

image

I still don't understand why Google's ViewModelcan save the scroll position without setting this property. But it solved the problem, thank you very much~

gpeal commented 2 years ago

This has nothing to do with ViewModel, it has to do with the fact that RecyclerView has no items at the point in which it tries to restore scroll state.