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. 32
      damus/Views/ThreadV2View.swift
  2. 24
      damus/Views/TimelineView.swift

32
damus/Views/ThreadV2View.swift

@ -232,18 +232,29 @@ 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(
damus: damus,
event_id: event.id
)){
EventView( EventView(
event: event, event: event,
highlight: .none, highlight: .none,
@ -252,8 +263,10 @@ struct ThreadV2View: View {
show_friend_icon: true, // TODO: change it show_friend_icon: true, // TODO: change it
size: .small size: .small
) )
.onTapGesture {
nav_target = event.id
navigating = true
} }
.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,10 +296,6 @@ 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(
damus: damus,
event_id: event.id
)){
EventView( EventView(
event: event, event: event,
highlight: .none, highlight: .none,
@ -295,7 +304,10 @@ struct ThreadV2View: View {
show_friend_icon: true, // TODO: change it show_friend_icon: true, // TODO: change it
size: .small size: .small
) )
}.buttonStyle(.plain) .onTapGesture {
nav_target = event.id
navigating = true
}
} }
}.padding() }.padding()
}.navigationBarTitle("Thread") }.navigationBarTitle("Thread")

24
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(
damus: damus,
event_id: (ev.inner_event ?? ev).id
)) {
EventView(event: ev, highlight: .none, has_action_bar: true, damus: damus, show_friend_icon: show_friend_icon) EventView(event: ev, highlight: .none, has_action_bar: true, damus: damus, show_friend_icon: show_friend_icon)
.onTapGesture {
nav_target = ev
navigating = true
} }
.isDetailLink(true)
.buttonStyle(PlainButtonStyle())
} }
} }
} }

Loading…
Cancel
Save