diff options
| -rw-r--r-- | Sora/Views/Post/Grid/PostGridView.swift | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift index 192b40f..a942a93 100644 --- a/Sora/Views/Post/Grid/PostGridView.swift +++ b/Sora/Views/Post/Grid/PostGridView.swift @@ -177,6 +177,9 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length } .navigationDestination(for: BooruPost.self) { post in PostDetailsView(post: post) + .onDisappear { + updateViewState(for: queryID, scrollPosition: scrollPosition.wrappedValue) + } } .onChange(of: isSearchablePresented) { _, isPresented in if !isPresented, manager.searchText.isEmpty, !manager.isNavigatingHistory { @@ -209,6 +212,10 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length manager.posts = state.posts manager.currentPage = state.currentPage manager.selectedPost = state.selectedPost + + DispatchQueue.main.async { + scrollPosition.wrappedValue = state.scrollPosition + } } else { manager.posts = [] manager.currentPage = 1 @@ -392,6 +399,7 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length currentPage: Int? = nil, selectedPost: BooruPost? = nil, resetSelectedPost: Bool = false, + scrollPosition: BooruPost.ID? = nil ) { let wasNewlyCreated = viewStates[queryID] == nil var state = viewStates[queryID] ?? PostGridViewState() @@ -406,6 +414,10 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length state.selectedPost = nil } + if let scrollPosition { + state.scrollPosition = scrollPosition + } + viewStates[queryID] = state if wasNewlyCreated { |