Skip to content

Commit

Permalink
Cleanup scroll to pin fix (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
weisJ authored Aug 13, 2024
1 parent 904d337 commit f07a1d7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
4 changes: 1 addition & 3 deletions Maccy/Observables/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class AppState: Sendable {
var scrollTarget: UUID?
var selection: UUID? = nil {
didSet {
// Cancel scrolling
scrollTarget = nil

history.selectedItem = nil
footer.selectedItem = nil

Expand All @@ -28,6 +25,7 @@ class AppState: Sendable {
} else if let item = footer.items.first(where: { $0.id == selection }) {
footer.selectedItem = item
}
scrollTarget = selection
}
}

Expand Down
1 change: 0 additions & 1 deletion Maccy/Observables/History.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ class History {
}

updateUnpinnedShortcuts()
AppState.shared.selection = item.id
if (item.isUnpinned) {
AppState.shared.scrollTarget = item.id
}
Expand Down
13 changes: 4 additions & 9 deletions Maccy/Views/HistoryListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ struct HistoryListView: View {
HistoryItemView(item: item)
}
}
.task(id: appState.selection) {
.task(id: appState.scrollTarget) {
guard appState.scrollTarget != nil else { return }
try? await Task.sleep(for: .milliseconds(10))
guard !Task.isCancelled else { return }

if let selection = appState.selection {
if let selection = appState.scrollTarget {
proxy.scrollTo(selection)
appState.scrollTarget = nil
}
}
.onChange(of: scenePhase) {
Expand All @@ -54,13 +56,6 @@ struct HistoryListView: View {
modifierFlags.flags = []
}
}
.onChange(of: appState.scrollTarget) {
// Recheck if the target has been cleared in the meantime, due to navigation
if let targetId = appState.scrollTarget {
proxy.scrollTo(targetId)
appState.scrollTarget = nil
}
}
// Calculate the total height inside a scroll view.
.background {
GeometryReader { geo in
Expand Down

0 comments on commit f07a1d7

Please sign in to comment.