scroll to note in thread

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-04-17 06:03:37 -07:00
parent f2631bd086
commit 41911908e7
3 changed files with 37 additions and 22 deletions

View File

@@ -54,7 +54,7 @@ struct ContentView: View {
.navigationBarTitle("Note") .navigationBarTitle("Note")
.environmentObject(profiles) .environmentObject(profiles)
NavigationLink(destination: evdet) { NavigationLink(destination: evdet) {
EventView(event: ev, highlighted: false) EventView(event: ev, highlighted: false, has_action_bar: true)
} }
.buttonStyle(PlainButtonStyle()) .buttonStyle(PlainButtonStyle())
} }

View File

@@ -61,29 +61,40 @@ struct EventDetailView: View {
} }
var body: some View { var body: some View {
ScrollView { ScrollViewReader { proxy in
ForEach(events, id: \.id) { ev in ScrollView {
if ev.id == event.id { ForEach(events, id: \.id) { ev in
EventView(event: ev, highlighted: ev.id == event.id) let is_active_id = ev.id == event.id
} else { if is_active_id {
let evdet = EventDetailView(event: ev, pool: pool) EventView(event: ev, highlighted: is_active_id, has_action_bar: true)
.navigationBarTitle("Note") .onAppear() {
.environmentObject(profiles) 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) { NavigationLink(destination: evdet) {
EventView(event: ev, highlighted: ev.id == event.id) EventView(event: ev, highlighted: is_active_id, has_action_bar: true)
}
.buttonStyle(PlainButtonStyle())
} }
.buttonStyle(PlainButtonStyle())
} }
} }
} .padding()
.padding() .onDisappear() {
.onDisappear() { unsubscribe_to_thread()
unsubscribe_to_thread() }
} .onAppear() {
.onAppear() { self.add_event(event)
self.add_event(event) subscribe_to_thread()
subscribe_to_thread()
}
} }
} }

View File

@@ -12,6 +12,7 @@ import CachedAsyncImage
struct EventView: View { struct EventView: View {
let event: NostrEvent let event: NostrEvent
let highlighted: Bool let highlighted: Bool
let has_action_bar: Bool
@EnvironmentObject var profiles: Profiles @EnvironmentObject var profiles: Profiles
@@ -41,12 +42,15 @@ struct EventView: View {
Spacer() Spacer()
EventActionBar(event: event, profiles: profiles) if has_action_bar {
EventActionBar(event: event)
}
Divider() Divider()
.padding([.top], 4) .padding([.top], 4)
} }
} }
.id(event.id)
.frame(minHeight: PFP_SIZE) .frame(minHeight: PFP_SIZE)
.padding([.bottom], 4) .padding([.bottom], 4)
} }