damus

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

commit c0f9b0a8c04717330e4bb131fbf034d8c240d827
parent 7123b225a107b586a5599ff2f29e22e415f1d2ba
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 13 Jul 2023 06:50:21 -0700

views: allow embeddable views at top of timeline

This allows you to put stuff at the top of a timeline inside the scroll
view. We could also remove the scrollview from the timeline
eventually... but this works for now.

Diffstat:
Mdamus/ContentView.swift | 2+-
Mdamus/Views/SearchHomeView.swift | 2+-
Mdamus/Views/SearchView.swift | 2+-
Mdamus/Views/TimelineView.swift | 22++++++++++++++++++----
4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -142,7 +142,7 @@ struct ContentView: View { func contentTimelineView(filter: (@escaping (NostrEvent) -> Bool)) -> some View { ZStack { if let damus = self.damus_state { - TimelineView(events: home.events, loading: .constant(false), damus: damus, show_friend_icon: false, filter: filter) + TimelineView<AnyView>(events: home.events, loading: .constant(false), damus: damus, show_friend_icon: false, filter: filter) } } } diff --git a/damus/Views/SearchHomeView.swift b/damus/Views/SearchHomeView.swift @@ -44,7 +44,7 @@ struct SearchHomeView: View { } var GlobalContent: some View { - return TimelineView( + return TimelineView<AnyView>( events: model.events, loading: $model.loading, damus: damus_state, diff --git a/damus/Views/SearchView.swift b/damus/Views/SearchView.swift @@ -13,7 +13,7 @@ struct SearchView: View { @Environment(\.dismiss) var dismiss var body: some View { - TimelineView(events: search.events, loading: $search.loading, damus: appstate, show_friend_icon: true, filter: { _ in true }) + TimelineView<AnyView>(events: search.events, loading: $search.loading, damus: appstate, show_friend_icon: true, filter: { _ in true }) .navigationBarTitle(describe_search(search.search)) .onReceive(handle_notify(.switched_timeline)) { obj in dismiss() diff --git a/damus/Views/TimelineView.swift b/damus/Views/TimelineView.swift @@ -7,14 +7,24 @@ import SwiftUI -struct TimelineView: View { +struct TimelineView<Content: View>: View { @ObservedObject var events: EventHolder @Binding var loading: Bool let damus: DamusState let show_friend_icon: Bool let filter: (NostrEvent) -> Bool - + let content: Content? + + init(events: EventHolder, loading: Binding<Bool>, damus: DamusState, show_friend_icon: Bool, filter: @escaping (NostrEvent) -> Bool, content: (() -> Content)? = nil) { + self.events = events + self._loading = loading + self.damus = damus + self.show_friend_icon = show_friend_icon + self.filter = filter + self.content = content?() + } + var body: some View { MainContent } @@ -22,10 +32,14 @@ struct TimelineView: View { var MainContent: some View { ScrollViewReader { scroller in ScrollView { + if let content { + content + } + Color.white.opacity(0) .id("startblock") .frame(height: 1) - + InnerTimelineView(events: events, damus: damus, filter: loading ? { _ in true } : filter) .redacted(reason: loading ? .placeholder : []) .shimmer(loading) @@ -52,7 +66,7 @@ struct TimelineView: View { struct TimelineView_Previews: PreviewProvider { @StateObject static var events = test_event_holder static var previews: some View { - TimelineView(events: events, loading: .constant(true), damus: Constants.EXAMPLE_DEMOS, show_friend_icon: true, filter: { _ in true }) + TimelineView<AnyView>(events: events, loading: .constant(true), damus: Constants.EXAMPLE_DEMOS, show_friend_icon: true, filter: { _ in true }) } }