Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup scroll to pin fix (#841)
Browse files Browse the repository at this point in the history
weisJ authored Aug 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 904d337 commit f07a1d7
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
@@ -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

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

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

updateUnpinnedShortcuts()
AppState.shared.selection = item.id
if (item.isUnpinned) {
AppState.shared.scrollTarget = item.id
}
13 changes: 4 additions & 9 deletions Maccy/Views/HistoryListView.swift
Original file line number Diff line number Diff line change
@@ -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) {
@@ -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

0 comments on commit f07a1d7

Please sign in to comment.