Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving the scroll position when returning back #2635

Conversation

EpicDima
Copy link
Contributor

Fixes #2531

if (listViewState != null) {
listView.onRestoreInstanceState(listViewState)
}
onScreenExiting { listViewState = listView.onSaveInstanceState() }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but this is a bit surprising: there's already a backstack mechanism built in to save and restore view state. When we create a new BackstackFrame instance, the BackstackFrame constructor invokes view.saveHierarchyState(). When we go back and bring a view back to be current, NavigatingActivity.goBack() latest.restore(currentView) which calls view.restoreHierarchyState(viewState)

Before adding this new behavior, I'd want to understand why the normal view state saving behavior isn't working here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I debugged through this, and the explanation here is that the view state is getting restored when we navigate back, but at that point the listview has no adapter. We load the data from the db async and restore the view state afterwards.

@pyricau
Copy link
Member

pyricau commented Mar 26, 2024

Similar ish fix but not relying on storing the view state inside screen fields (which survive config changes): #2646

@pyricau pyricau closed this Mar 26, 2024
@EpicDima EpicDima deleted the epicdima/save_scroll_state_on_back_navigation branch March 31, 2024 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LeakActivity not preserving list position on back navigation from leak details
2 participants