Skip to content

Commit 6e88712

Browse files
authored
Merge pull request #27 from jasonlong/advisor/009-keep-grouped-selection-visible
Keep grouped selections visible while scrolling
2 parents b84c431 + 95ca529 commit 6e88712

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

Octodot/Views/NotificationListView.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ struct NotificationListView: View {
2424
}
2525
}
2626

27+
enum ScrollPlacement: Equatable {
28+
case minimal
29+
case top
30+
}
31+
2732
struct ScrollRequest: Equatable {
2833
let targetID: String
34+
let placement: ScrollPlacement
2935
let visibleIDs: [String]
3036
}
3137

@@ -60,7 +66,12 @@ struct NotificationListView: View {
6066
}
6167

6268
await Task.yield()
63-
proxy.scrollTo(scrollRequest.targetID)
69+
switch scrollRequest.placement {
70+
case .minimal:
71+
proxy.scrollTo(scrollRequest.targetID)
72+
case .top:
73+
proxy.scrollTo(scrollRequest.targetID, anchor: .top)
74+
}
6475
}
6576
}
6677
}
@@ -115,15 +126,19 @@ struct NotificationListView: View {
115126
}
116127

117128
let targetID: String
129+
let placement: ScrollPlacement
118130
if groupByRepo,
119131
selectedIndex == 0 || notifications[selectedIndex - 1].repository != notifications[selectedIndex].repository {
120132
targetID = "repo:\(notifications[selectedIndex].repository)"
133+
placement = .top
121134
} else {
122135
targetID = selectedNotificationID
136+
placement = .minimal
123137
}
124138

125139
return ScrollRequest(
126140
targetID: targetID,
141+
placement: placement,
127142
visibleIDs: notifications.map(\.id)
128143
)
129144
}

OctodotTests/AppShellTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ struct AppShellTests {
203203
)
204204

205205
#expect(request?.targetID == "1")
206+
#expect(request?.placement == .minimal)
206207
#expect(request?.visibleIDs == ["0", "1", "2"])
207208
#expect(NotificationListView.scrollRequest(
208209
selectedNotificationID: "999",
@@ -252,8 +253,11 @@ struct AppShellTests {
252253
)
253254

254255
#expect(firstInFirstGroup?.targetID == "repo:acme/alpha")
256+
#expect(firstInFirstGroup?.placement == .top)
255257
#expect(secondInSameGroup?.targetID == "2")
258+
#expect(secondInSameGroup?.placement == .minimal)
256259
#expect(firstInSecondGroup?.targetID == "repo:acme/beta")
260+
#expect(firstInSecondGroup?.placement == .top)
257261
}
258262

259263
@Test func notificationListBuildsRepositoryHeadersOnlyAtBoundaries() {

0 commit comments

Comments
 (0)