summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-08-26 10:37:21 -0700
committerFuwn <[email protected]>2025-08-26 10:37:21 -0700
commitfc2e32feeceda4b7668c99546d3f91d769cbf226 (patch)
treee822ac46831649bff231a5e15aa8cf0c940a29d0
parentfeat: Development commit (diff)
downloadsora-testing-fc2e32feeceda4b7668c99546d3f91d769cbf226.tar.xz
sora-testing-fc2e32feeceda4b7668c99546d3f91d769cbf226.zip
feat: Development commit
-rw-r--r--Sora/Data/PostGridViewState/PostGridViewState.swift1
-rw-r--r--Sora/Views/Post/Grid/PostGridView.swift76
2 files changed, 0 insertions, 77 deletions
diff --git a/Sora/Data/PostGridViewState/PostGridViewState.swift b/Sora/Data/PostGridViewState/PostGridViewState.swift
index 95e3396..266d05c 100644
--- a/Sora/Data/PostGridViewState/PostGridViewState.swift
+++ b/Sora/Data/PostGridViewState/PostGridViewState.swift
@@ -4,6 +4,5 @@ struct PostGridViewState: Equatable {
var posts: [BooruPost] = []
var currentPage: Int = 1
var selectedPost: BooruPost?
- var scrollPostID: String?
let createdAt = Date()
}
diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift
index 955abd4..2f2ec6d 100644
--- a/Sora/Views/Post/Grid/PostGridView.swift
+++ b/Sora/Views/Post/Grid/PostGridView.swift
@@ -15,25 +15,7 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
@State private var suppressNextSearchSubmit = false
@State private var searchTask: Task<Void, Never>?
@State private var suggestions: [BooruTag] = []
- private static let topID = "PostGridScrollTop"
- @State private var scrollID: String?
@State private var cachedColumnsData: ColumnsDataCache?
- @State private var scrollDebounceTask: Task<Void, Never>?
- @State private var lastScrollCaptureTime: CFTimeInterval = CFAbsoluteTimeGetCurrent()
-
- private var throttledScrollID: Binding<String?> {
- Binding(
- get: { scrollID },
- set: { newValue in
- let now = CFAbsoluteTimeGetCurrent()
-
- if now - lastScrollCaptureTime > 0.5 {
- lastScrollCaptureTime = now
- scrollID = newValue
- }
- }
- )
- }
@Environment(\.isSearching)
private var isSearching
@@ -100,7 +82,6 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
}
}
.transaction { $0.animation = nil }
- .scrollTargetLayout()
}
}
#if os(macOS)
@@ -116,7 +97,6 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
}
.gridStyle(columns: columnCount)
.transaction { $0.animation = nil }
- .scrollTargetLayout()
#if os(macOS)
.padding(8)
#else
@@ -151,16 +131,10 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
var body: some View {
ScrollView {
- Color.clear
- .frame(height: 0)
- .id(Self.topID)
- .scrollTargetLayout()
-
gridContent
.id(queryID)
.transition(.opacity)
}
- .scrollPosition(id: throttledScrollID, anchor: .top)
#if os(iOS)
.searchable(
text: $manager.searchText,
@@ -239,23 +213,6 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
updateViewState(for: queryID, selectedPost: newPost, resetSelectedPost: newPost == nil)
}
- .onChange(of: scrollID) { _, newValue in
- guard manager.historyIndex >= 0 && manager.historyIndex < manager.searchHistory.count else {
- return
- }
-
- scrollDebounceTask?.cancel()
-
- scrollDebounceTask = Task {
- try? await Task.sleep(nanoseconds: 200_000_000)
-
- guard !Task.isCancelled else { return }
-
- let queryID = manager.searchHistory[manager.historyIndex].id
-
- updateViewState(for: queryID, scrollPostID: newValue)
- }
- }
.onChange(of: manager.historyIndex) { _, newIndex in
guard newIndex >= 0 && newIndex < manager.searchHistory.count else { return }
@@ -277,12 +234,6 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
)
}
}
-
- if let savedID = viewStates[queryID]?.scrollPostID {
- scrollID = savedID
- } else {
- scrollID = Self.topID
- }
}
.toolbar {
#if os(macOS)
@@ -397,24 +348,6 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
isPresented: $isSearchHistoryPresented
)
}
- .onAppear {
- let targetScrollID = viewStates[queryID]?.scrollPostID ?? Self.topID
-
- if scrollID == nil || scrollID != targetScrollID {
- scrollID = targetScrollID
- }
- }
- .onDisappear {
- guard manager.historyIndex >= 0 && manager.historyIndex < manager.searchHistory.count else {
- return
- }
-
- let queryID = manager.searchHistory[manager.historyIndex].id
-
- if viewStates[queryID]?.scrollPostID != scrollID {
- updateViewState(for: queryID, scrollPostID: scrollID)
- }
- }
#if os(iOS)
.gesture(
DragGesture()
@@ -473,7 +406,6 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
posts: [BooruPost] = [],
currentPage: Int? = nil,
selectedPost: BooruPost? = nil,
- scrollPostID: String? = nil,
resetSelectedPost: Bool = false,
) {
let wasNewlyCreated = viewStates[queryID] == nil
@@ -489,14 +421,6 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
state.selectedPost = nil
}
- if let scrollPostID {
- state.scrollPostID = scrollPostID
- }
-
- if wasNewlyCreated && state.scrollPostID == nil {
- state.scrollPostID = Self.topID
- }
-
viewStates[queryID] = state
if wasNewlyCreated {