Fix occasional stale timeline issue
Changelog-Changed: Added UX hint to make it easier to load new notes Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
@@ -66,7 +66,7 @@ struct FollowPackTimelineView<Content: View>: View {
|
|||||||
.coordinateSpace(name: "scroll")
|
.coordinateSpace(name: "scroll")
|
||||||
.onReceive(handle_notify(.scroll_to_top)) { () in
|
.onReceive(handle_notify(.scroll_to_top)) { () in
|
||||||
events.flush()
|
events.flush()
|
||||||
self.events.should_queue = false
|
self.events.set_should_queue(false)
|
||||||
scroll_to_event(scroller: scroller, id: "startblock", delay: 0.0, animate: true, anchor: .top)
|
scroll_to_event(scroller: scroller, id: "startblock", delay: 0.0, animate: true, anchor: .top)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,26 @@ struct InnerTimelineView: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
LazyVStack(spacing: 0) {
|
LazyVStack(spacing: 0) {
|
||||||
|
let incomingEvents = events.incoming.filter({ filter($0) })
|
||||||
|
if incomingEvents.count > 0 {
|
||||||
|
Button(
|
||||||
|
action: {
|
||||||
|
notify(.scroll_to_top)
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
HStack(spacing: 6) {
|
||||||
|
CondensedProfilePicturesView(state: state, pubkeys: incomingEvents.map({ $0.pubkey }), maxPictures: 3)
|
||||||
|
Text("Load new content", comment: "Button to load new notes in the timeline")
|
||||||
|
.bold()
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 20)
|
||||||
|
.padding(.vertical, 10)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.buttonStyle(NeutralButtonStyle(cornerRadius: 50))
|
||||||
|
.padding(.vertical, 10)
|
||||||
|
}
|
||||||
|
|
||||||
let events = self.events.events
|
let events = self.events.events
|
||||||
if events.isEmpty {
|
if events.isEmpty {
|
||||||
EmptyTimelineView()
|
EmptyTimelineView()
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ struct TimelineView<Content: View>: View {
|
|||||||
.coordinateSpace(name: "scroll")
|
.coordinateSpace(name: "scroll")
|
||||||
.onReceive(handle_notify(.scroll_to_top)) { () in
|
.onReceive(handle_notify(.scroll_to_top)) { () in
|
||||||
events.flush()
|
events.flush()
|
||||||
self.events.should_queue = false
|
self.events.set_should_queue(false)
|
||||||
scroll_to_event(scroller: scroller, id: "startblock", delay: 0.0, animate: true, anchor: .top)
|
scroll_to_event(scroller: scroller, id: "startblock", delay: 0.0, animate: true, anchor: .top)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,11 +122,8 @@ protocol ScrollQueue {
|
|||||||
|
|
||||||
func handle_scroll_queue(_ proxy: GeometryProxy, queue: ScrollQueue) {
|
func handle_scroll_queue(_ proxy: GeometryProxy, queue: ScrollQueue) {
|
||||||
let offset = -proxy.frame(in: .named("scroll")).origin.y
|
let offset = -proxy.frame(in: .named("scroll")).origin.y
|
||||||
guard offset >= 0 else {
|
let new_should_queue = offset > 0
|
||||||
return
|
if queue.should_queue != new_should_queue {
|
||||||
}
|
queue.set_should_queue(new_should_queue)
|
||||||
let val = offset > 0
|
|
||||||
if queue.should_queue != val {
|
|
||||||
queue.set_should_queue(val)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import Foundation
|
|||||||
class EventHolder: ObservableObject, ScrollQueue {
|
class EventHolder: ObservableObject, ScrollQueue {
|
||||||
private var has_event = Set<NoteId>()
|
private var has_event = Set<NoteId>()
|
||||||
@Published var events: [NostrEvent]
|
@Published var events: [NostrEvent]
|
||||||
var incoming: [NostrEvent]
|
@Published var incoming: [NostrEvent]
|
||||||
var should_queue = false
|
private(set) var should_queue = false
|
||||||
var on_queue: ((NostrEvent) -> Void)?
|
var on_queue: ((NostrEvent) -> Void)?
|
||||||
|
|
||||||
func set_should_queue(_ val: Bool) {
|
func set_should_queue(_ val: Bool) {
|
||||||
|
|||||||
Reference in New Issue
Block a user