Add scroll queue detection in notification view

This will stop injecting events into the timeline if you're scrolling
This commit is contained in:
William Casarin
2023-02-26 14:14:25 -08:00
parent 75fd8de456
commit 4b5c217213
4 changed files with 33 additions and 14 deletions

View File

@@ -27,17 +27,6 @@ struct TimelineView: View {
MainContent
}
func handle_scroll(_ proxy: GeometryProxy) {
let offset = -proxy.frame(in: .named("scroll")).origin.y
guard offset >= 0 else {
return
}
let val = offset > 0
if self.events.should_queue != val {
self.events.should_queue = val
}
}
var realtime_bar_opacity: Double {
colorScheme == .dark ? 0.2 : 0.1
}
@@ -55,7 +44,7 @@ struct TimelineView: View {
.disabled(loading)
.background(GeometryReader { proxy -> Color in
DispatchQueue.main.async {
handle_scroll(proxy)
handle_scroll_queue(proxy, queue: self.events)
}
return Color.clear
})
@@ -82,3 +71,18 @@ struct TimelineView_Previews: PreviewProvider {
}
protocol ScrollQueue {
var should_queue: Bool { get }
func set_should_queue(_ val: Bool)
}
func handle_scroll_queue(_ proxy: GeometryProxy, queue: ScrollQueue) {
let offset = -proxy.frame(in: .named("scroll")).origin.y
guard offset >= 0 else {
return
}
let val = offset > 0
if queue.should_queue != val {
queue.set_should_queue(val)
}
}