Add scroll queue detection in notification view
This will stop injecting events into the timeline if you're scrolling
This commit is contained in:
@@ -45,7 +45,8 @@ enum NotificationItem {
|
||||
}
|
||||
}
|
||||
|
||||
class NotificationsModel: ObservableObject {
|
||||
class NotificationsModel: ObservableObject, ScrollQueue {
|
||||
|
||||
var incoming_zaps: [Zap]
|
||||
var incoming_events: [NostrEvent]
|
||||
var should_queue: Bool
|
||||
@@ -73,6 +74,10 @@ class NotificationsModel: ObservableObject {
|
||||
self.notifications = []
|
||||
}
|
||||
|
||||
func set_should_queue(_ val: Bool) {
|
||||
self.should_queue = val
|
||||
}
|
||||
|
||||
func uniq_pubkeys() -> [String] {
|
||||
var pks = Set<String>()
|
||||
|
||||
|
||||
@@ -8,12 +8,16 @@
|
||||
import Foundation
|
||||
|
||||
/// Used for holding back events until they're ready to be displayed
|
||||
class EventHolder: ObservableObject {
|
||||
class EventHolder: ObservableObject, ScrollQueue {
|
||||
private var has_event: Set<String>
|
||||
@Published var events: [NostrEvent]
|
||||
@Published var incoming: [NostrEvent]
|
||||
var should_queue: Bool
|
||||
|
||||
func set_should_queue(_ val: Bool) {
|
||||
self.should_queue = val
|
||||
}
|
||||
|
||||
var queued: Int {
|
||||
return incoming.count
|
||||
}
|
||||
|
||||
@@ -22,6 +22,12 @@ struct NotificationsView: View {
|
||||
NotificationItemView(state: state, item: item)
|
||||
}
|
||||
}
|
||||
.background(GeometryReader { proxy -> Color in
|
||||
DispatchQueue.main.async {
|
||||
handle_scroll_queue(proxy, queue: self.notifications)
|
||||
}
|
||||
return Color.clear
|
||||
})
|
||||
.padding(.horizontal)
|
||||
}
|
||||
.onReceive(handle_notify(.scroll_to_top)) { notif in
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user