Use top anchor for scroll to top event
Changelog-Fixed: Scroll to top of events instead of the bottom Closes: #570
This commit is contained in:
@@ -33,14 +33,14 @@ func print_event(_ ev: NostrEvent) {
|
|||||||
print(ev.description)
|
print(ev.description)
|
||||||
}
|
}
|
||||||
|
|
||||||
func scroll_to_event(scroller: ScrollViewProxy, id: String, delay: Double, animate: Bool) {
|
func scroll_to_event(scroller: ScrollViewProxy, id: String, delay: Double, animate: Bool, anchor: UnitPoint = .bottom) {
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
|
||||||
if animate {
|
if animate {
|
||||||
withAnimation {
|
withAnimation {
|
||||||
scroller.scrollTo(id, anchor: .bottom)
|
scroller.scrollTo(id, anchor: anchor)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
scroller.scrollTo(id, anchor: .bottom)
|
scroller.scrollTo(id, anchor: anchor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ struct TimelineView: View {
|
|||||||
guard let event = events.filter(self.filter).first else {
|
guard let event = events.filter(self.filter).first else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
scroll_to_event(scroller: scroller, id: event.id, delay: 0.0, animate: true)
|
scroll_to_event(scroller: scroller, id: event.id, delay: 0.0, animate: true, anchor: .top)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user