summaryrefslogtreecommitdiff
path: root/Sora/Views/Post/Grid/PostGridView.swift
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-07-10 06:27:49 -0700
committerFuwn <[email protected]>2025-07-10 06:27:49 -0700
commitef1357a23f81772768d1726bb719f8d1317fbbf4 (patch)
tree443bf0deaaae36105290b8200b2feb47fe267467 /Sora/Views/Post/Grid/PostGridView.swift
parentfeat: Development commit (diff)
downloadsora-testing-ef1357a23f81772768d1726bb719f8d1317fbbf4.tar.xz
sora-testing-ef1357a23f81772768d1726bb719f8d1317fbbf4.zip
feat: Development commit
Diffstat (limited to 'Sora/Views/Post/Grid/PostGridView.swift')
-rw-r--r--Sora/Views/Post/Grid/PostGridView.swift31
1 files changed, 18 insertions, 13 deletions
diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift
index 5b48e1e..47df932 100644
--- a/Sora/Views/Post/Grid/PostGridView.swift
+++ b/Sora/Views/Post/Grid/PostGridView.swift
@@ -17,17 +17,20 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
@State private var suggestions: [BooruTag] = []
@State private var topItemID: BooruPost.ID?
@State private var debounceTask: Task<Void, Never>?
+ @State private var pendingScrollPosition: BooruPost.ID?
@Environment(\.isSearching)
private var isSearching
+ private var queryID: UUID {
+ manager.searchHistory[manager.historyIndex].id
+ }
+
private var activePosts: [BooruPost] {
guard manager.historyIndex >= 0 && manager.historyIndex < manager.searchHistory.count else {
return []
}
- let queryID = manager.searchHistory[manager.historyIndex].id
-
return viewStates[queryID]?.posts
.filter { settings.displayRatings.contains($0.rating) } ?? []
}
@@ -104,8 +107,8 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
}
}
}
- .id(manager.historyIndex)
- .animation(.easeInOut, value: manager.isLoading)
+ .id(queryID)
+ .animation(.easeInOut, value: manager.historyIndex)
}
.coordinateSpace(name: "scrollview")
.onPreferenceChange(ScrollPositionPreferenceKey.self) { preference in
@@ -131,7 +134,6 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
}
}
}
- .animation(.easeInOut, value: manager.historyIndex)
#if os(iOS)
.searchable(
text: $manager.searchText,
@@ -195,9 +197,15 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
}
.onChange(of: manager.posts) { _, newPosts in
if manager.historyIndex >= 0 && manager.historyIndex < manager.searchHistory.count {
- let queryID = manager.searchHistory[manager.historyIndex].id
-
updateViewState(for: queryID, posts: newPosts)
+
+ if let scrollID = pendingScrollPosition {
+ DispatchQueue.main.async {
+ proxy.scrollTo(scrollID, anchor: .top)
+
+ pendingScrollPosition = nil
+ }
+ }
}
}
.onChange(of: manager.currentPage) { _, newPage in
@@ -221,12 +229,7 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
manager.posts = state.posts
manager.currentPage = state.currentPage
manager.selectedPost = state.selectedPost
-
- if let scrollPosition = state.scrollPosition {
- DispatchQueue.main.async {
- proxy.scrollTo(scrollPosition, anchor: .top)
- }
- }
+ pendingScrollPosition = state.scrollPosition
} else {
manager.posts = []
manager.currentPage = 1
@@ -238,6 +241,8 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
replace: true
)
}
+
+ pendingScrollPosition = nil
}
}
.toolbar {