damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit b70ce53b88472d4062a4fc110e546d7f9142d4ac
parent 16e3c4e1cf526f8c256705fe6009085409490e88
Author: William Casarin <jb55@jb55.com>
Date:   Tue,  3 Jan 2023 23:00:22 -0800

navigation: fix navigation popping issues in threads

Changelog-Fixed: Fix navigation popping in threads

Diffstat:
Mdamus/Views/ThreadV2View.swift | 60++++++++++++++++++++++++++++++++++++------------------------
Mdamus/Views/TimelineView.swift | 28++++++++++++++++++++--------
2 files changed, 56 insertions(+), 32 deletions(-)

diff --git a/damus/Views/ThreadV2View.swift b/damus/Views/ThreadV2View.swift @@ -232,28 +232,41 @@ struct BuildThreadV2View: View { struct ThreadV2View: View { let damus: DamusState 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 { + NavigationLink(destination: MaybeBuildThreadView, isActive: $navigating) { + EmptyView() + } ScrollViewReader { reader in ScrollView { VStack { // MARK: - Parents events view VStack { ForEach(thread.parentEvents, id: \.id) { event in - NavigationLink(destination: BuildThreadV2View( + EventView( + event: event, + highlight: .none, + has_action_bar: true, damus: damus, - event_id: event.id - )){ - EventView( - event: event, - highlight: .none, - has_action_bar: true, - damus: damus, - show_friend_icon: true, // TODO: change it - size: .small - ) + show_friend_icon: true, // TODO: change it + size: .small + ) + .onTapGesture { + nav_target = event.id + navigating = true } - .buttonStyle(.plain) .onAppear { // TODO: find another solution to prevent layout shifting and layout blocking on large responses reader.scrollTo("main", anchor: .bottom) @@ -283,19 +296,18 @@ struct ThreadV2View: View { // MARK: - Responses of the actual event view ForEach(thread.childEvents, id: \.id) { event in - NavigationLink(destination: BuildThreadV2View( + EventView( + event: event, + highlight: .none, + has_action_bar: true, damus: damus, - event_id: event.id - )){ - EventView( - event: event, - highlight: .none, - has_action_bar: true, - damus: damus, - show_friend_icon: true, // TODO: change it - size: .small - ) - }.buttonStyle(.plain) + show_friend_icon: true, // TODO: change it + size: .small + ) + .onTapGesture { + nav_target = event.id + navigating = true + } } }.padding() }.navigationBarTitle("Thread") diff --git a/damus/Views/TimelineView.swift b/damus/Views/TimelineView.swift @@ -17,8 +17,23 @@ struct InnerTimelineView: View { let damus: DamusState let show_friend_icon: 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 { + NavigationLink(destination: MaybeBuildThreadView, isActive: $navigating) { + EmptyView() + } LazyVStack { if events.isEmpty { EmptyTimelineView() @@ -28,14 +43,11 @@ struct InnerTimelineView: View { //let is_chatroom = should_show_chatroom(ev) //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) - } - .isDetailLink(true) - .buttonStyle(PlainButtonStyle()) + EventView(event: ev, highlight: .none, has_action_bar: true, damus: damus, show_friend_icon: show_friend_icon) + .onTapGesture { + nav_target = ev + navigating = true + } } } }