Browse Source

navigation: fix navigation popping issues in threads

Changelog-Fixed: Fix navigation popping in threads
post-button-style
William Casarin 2 years ago
parent
commit
b70ce53b88
  1. 60
      damus/Views/ThreadV2View.swift
  2. 28
      damus/Views/TimelineView.swift

60
damus/Views/ThreadV2View.swift

@ -232,28 +232,41 @@ struct BuildThreadV2View: View {
struct ThreadV2View: View { struct ThreadV2View: View {
let damus: DamusState let damus: DamusState
let thread: ThreadV2 let thread: ThreadV2
@State var nav_target: String? = nil
@State var navigating: Bool = false
var MaybeBuildThreadView: some View {
Group {
if let evid = nav_target {
BuildThreadV2View(damus: damus, event_id: evid)
} else {
EmptyView()
}
}
}
var body: some View { var body: some View {
NavigationLink(destination: MaybeBuildThreadView, isActive: $navigating) {
EmptyView()
}
ScrollViewReader { reader in ScrollViewReader { reader in
ScrollView { ScrollView {
VStack { VStack {
// MARK: - Parents events view // MARK: - Parents events view
VStack { VStack {
ForEach(thread.parentEvents, id: \.id) { event in ForEach(thread.parentEvents, id: \.id) { event in
NavigationLink(destination: BuildThreadV2View( EventView(
event: event,
highlight: .none,
has_action_bar: true,
damus: damus, damus: damus,
event_id: event.id show_friend_icon: true, // TODO: change it
)){ size: .small
EventView( )
event: event, .onTapGesture {
highlight: .none, nav_target = event.id
has_action_bar: true, navigating = true
damus: damus,
show_friend_icon: true, // TODO: change it
size: .small
)
} }
.buttonStyle(.plain)
.onAppear { .onAppear {
// TODO: find another solution to prevent layout shifting and layout blocking on large responses // TODO: find another solution to prevent layout shifting and layout blocking on large responses
reader.scrollTo("main", anchor: .bottom) reader.scrollTo("main", anchor: .bottom)
@ -283,19 +296,18 @@ struct ThreadV2View: View {
// MARK: - Responses of the actual event view // MARK: - Responses of the actual event view
ForEach(thread.childEvents, id: \.id) { event in ForEach(thread.childEvents, id: \.id) { event in
NavigationLink(destination: BuildThreadV2View( EventView(
event: event,
highlight: .none,
has_action_bar: true,
damus: damus, damus: damus,
event_id: event.id show_friend_icon: true, // TODO: change it
)){ size: .small
EventView( )
event: event, .onTapGesture {
highlight: .none, nav_target = event.id
has_action_bar: true, navigating = true
damus: damus, }
show_friend_icon: true, // TODO: change it
size: .small
)
}.buttonStyle(.plain)
} }
}.padding() }.padding()
}.navigationBarTitle("Thread") }.navigationBarTitle("Thread")

28
damus/Views/TimelineView.swift

@ -17,8 +17,23 @@ struct InnerTimelineView: View {
let damus: DamusState let damus: DamusState
let show_friend_icon: Bool let show_friend_icon: Bool
let filter: (NostrEvent) -> Bool let filter: (NostrEvent) -> Bool
@State var nav_target: NostrEvent? = nil
@State var navigating: Bool = false
var MaybeBuildThreadView: some View {
Group {
if let ev = nav_target {
BuildThreadV2View(damus: damus, event_id: (ev.inner_event ?? ev).id)
} else {
EmptyView()
}
}
}
var body: some View { var body: some View {
NavigationLink(destination: MaybeBuildThreadView, isActive: $navigating) {
EmptyView()
}
LazyVStack { LazyVStack {
if events.isEmpty { if events.isEmpty {
EmptyTimelineView() EmptyTimelineView()
@ -28,14 +43,11 @@ struct InnerTimelineView: View {
//let is_chatroom = should_show_chatroom(ev) //let is_chatroom = should_show_chatroom(ev)
//let tv = ThreadView(thread: tm, damus: damus, is_chatroom: is_chatroom) //let tv = ThreadView(thread: tm, damus: damus, is_chatroom: is_chatroom)
NavigationLink(destination: BuildThreadV2View( EventView(event: ev, highlight: .none, has_action_bar: true, damus: damus, show_friend_icon: show_friend_icon)
damus: damus, .onTapGesture {
event_id: (ev.inner_event ?? ev).id nav_target = ev
)) { navigating = true
EventView(event: ev, highlight: .none, has_action_bar: true, damus: damus, show_friend_icon: show_friend_icon) }
}
.isDetailLink(true)
.buttonStyle(PlainButtonStyle())
} }
} }
} }

Loading…
Cancel
Save