Cannot keep the scroll position of horizontal nested RecyclerView in DiscoverFragment
Cannot keep the scroll position of horizontal nested RecyclerView in DiscoverFragment when I navigate to "navigation_trending" then back to DiscoverFragment
Related: https://github.com/airbnb/epoxy/issues/561
When I scroll up/down the position state is kept. I think It related to Navigation I created a pull request to fix this issue, please take a look at it https://github.com/chrisbanes/tivi/pull/482
Re-opening since we had to revert in #485
@chrisbanes
As I checked, Sometimes, the view is bound before we call onRestoreInstanceState, this lead to the crash.
from BaseEpoxyAdapter:
public void onRestoreInstanceState(@Nullable Bundle inState) {
// To simplify things we enforce that state is restored before views are bound, otherwise it
// is more difficult to update view state once they are bound
if (boundViewHolders.size() > 0) {
throw new IllegalStateException(
"State cannot be restored once views have been bound. It should be done before adding "
+ "the adapter to the recycler view.");
}
if (inState != null) {
viewHolderState = inState.getParcelable(SAVED_STATE_ARG_VIEW_HOLDERS);
if (viewHolderState == null) {
throw new IllegalStateException(
"Tried to restore instance state, but onSaveInstanceState was never called.");
}
}
}
I don't know why it happens. But, I think we can call onRestoreInstanceState safely by catching IllegalStateException exception when calling onRestoreInstanceState.
@chrisbanes how do you think?. If It is ok, I will open a new pull request to fix the issue.
Thank you
Do you have any update for this issue? I face the same problems :( @chrisbanes