commit 41911908e75cc7e67bb44b704e993aa9d75f8752
parent f2631bd0868ee3ccea2e6cbb651e0d36b5691667
Author: William Casarin <jb55@jb55.com>
Date: Sun, 17 Apr 2022 06:03:37 -0700
scroll to note in thread
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
3 files changed, 37 insertions(+), 22 deletions(-)
diff --git a/damus/ContentView.swift b/damus/ContentView.swift
@@ -54,7 +54,7 @@ struct ContentView: View {
.navigationBarTitle("Note")
.environmentObject(profiles)
NavigationLink(destination: evdet) {
- EventView(event: ev, highlighted: false)
+ EventView(event: ev, highlighted: false, has_action_bar: true)
}
.buttonStyle(PlainButtonStyle())
}
diff --git a/damus/Views/EventDetailView.swift b/damus/Views/EventDetailView.swift
@@ -61,29 +61,40 @@ struct EventDetailView: View {
}
var body: some View {
- ScrollView {
- ForEach(events, id: \.id) { ev in
- if ev.id == event.id {
- EventView(event: ev, highlighted: ev.id == event.id)
- } else {
- let evdet = EventDetailView(event: ev, pool: pool)
- .navigationBarTitle("Note")
- .environmentObject(profiles)
-
- NavigationLink(destination: evdet) {
- EventView(event: ev, highlighted: ev.id == event.id)
+ ScrollViewReader { proxy in
+ ScrollView {
+ ForEach(events, id: \.id) { ev in
+ let is_active_id = ev.id == event.id
+ if is_active_id {
+ EventView(event: ev, highlighted: is_active_id, has_action_bar: true)
+ .onAppear() {
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
+ withAnimation {
+ proxy.scrollTo(event.id)
+ }
+ }
+ }
+ } else {
+ let evdet = EventDetailView(event: ev, pool: pool)
+ .navigationBarTitle("Note")
+ .environmentObject(profiles)
+
+ NavigationLink(destination: evdet) {
+ EventView(event: ev, highlighted: is_active_id, has_action_bar: true)
+ }
+ .buttonStyle(PlainButtonStyle())
}
- .buttonStyle(PlainButtonStyle())
}
}
- }
- .padding()
- .onDisappear() {
- unsubscribe_to_thread()
- }
- .onAppear() {
- self.add_event(event)
- subscribe_to_thread()
+ .padding()
+ .onDisappear() {
+ unsubscribe_to_thread()
+ }
+ .onAppear() {
+ self.add_event(event)
+ subscribe_to_thread()
+
+ }
}
}
diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift
@@ -12,6 +12,7 @@ import CachedAsyncImage
struct EventView: View {
let event: NostrEvent
let highlighted: Bool
+ let has_action_bar: Bool
@EnvironmentObject var profiles: Profiles
@@ -41,12 +42,15 @@ struct EventView: View {
Spacer()
- EventActionBar(event: event, profiles: profiles)
+ if has_action_bar {
+ EventActionBar(event: event)
+ }
Divider()
.padding([.top], 4)
}
}
+ .id(event.id)
.frame(minHeight: PFP_SIZE)
.padding([.bottom], 4)
}