damus

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

commit f70273365451dd3e8f7caa0350ec6221ee0c65d3
parent 9008c609e24a837201a7daf1ec9fbb809d125b99
Author: William Casarin <jb55@jb55.com>
Date:   Fri, 30 Jun 2023 09:59:58 -0700

nav: remove environmentObjects

environment objects are implicit arguments that cannot be checked by the
compiler. They are a common source of crashes. Use a main
NavigationCoordinator in DamusState for the core app, and pass in other
coordinators in the account setup view for the parts of the app that
don't have a DamusState.

Diffstat:
Mdamus/ContentView.swift | 9++-------
Mdamus/Models/DamusState.swift | 3++-
Mdamus/Util/Router.swift | 38+++++++++++++-------------------------
Mdamus/Views/BookmarksView.swift | 3---
Mdamus/Views/CreateAccountView.swift | 6+++---
Mdamus/Views/DirectMessagesView.swift | 4+---
Mdamus/Views/EULAView.swift | 6+++---
Mdamus/Views/FollowingView.swift | 13+++----------
Mdamus/Views/LoginView.swift | 13++++++-------
Mdamus/Views/Notifications/EventGroupView.swift | 3---
Mdamus/Views/Notifications/NotificationItemView.swift | 6------
Mdamus/Views/Notifications/NotificationsView.swift | 2--
Mdamus/Views/Notifications/ProfilePicturesView.swift | 4+---
Mdamus/Views/Profile/ProfileView.swift | 7++-----
Mdamus/Views/QRCodeView.swift | 7++-----
Mdamus/Views/Reactions/ReactionView.swift | 2--
Mdamus/Views/ReactionsView.swift | 2--
Mdamus/Views/RelayFilterView.swift | 3---
Mdamus/Views/Reposts/RepostView.swift | 2--
Mdamus/Views/RepostsView.swift | 2--
Mdamus/Views/Search/SearchingEventView.swift | 2--
Mdamus/Views/SearchHomeView.swift | 8+-------
Mdamus/Views/SearchResultsView.swift | 5-----
Mdamus/Views/SearchView.swift | 2--
Mdamus/Views/SideMenuView.swift | 5+----
Mdamus/Views/Timeline/InnerTimelineView.swift | 4+---
Mdamus/Views/TimelineView.swift | 2--
Mdamus/Views/Wallet/ConnectWalletView.swift | 6+++---
Mdamus/Views/Wallet/WalletView.swift | 7++-----
29 files changed, 46 insertions(+), 130 deletions(-)

diff --git a/damus/ContentView.swift b/damus/ContentView.swift @@ -143,7 +143,6 @@ struct ContentView: View { ZStack { if let damus = self.damus_state { TimelineView(events: home.events, loading: .constant(false), damus: damus, show_friend_icon: false, filter: filter) - .environmentObject(navigationCoordinator) } } } @@ -164,12 +163,10 @@ struct ContentView: View { case .search: if #available(iOS 16.0, *) { SearchHomeView(damus_state: damus_state!, model: SearchHomeModel(damus_state: damus_state!)) - .environmentObject(navigationCoordinator) .scrollDismissesKeyboard(.immediately) } else { // Fallback on earlier versions SearchHomeView(damus_state: damus_state!, model: SearchHomeModel(damus_state: damus_state!)) - .environmentObject(navigationCoordinator) } case .home: @@ -177,11 +174,9 @@ struct ContentView: View { case .notifications: NotificationsView(state: damus, notifications: home.notifications) - .environmentObject(navigationCoordinator) case .dms: DirectMessagesView(damus_state: damus_state!, model: damus_state!.dms, settings: damus_state!.settings) - .environmentObject(navigationCoordinator) } } .navigationBarTitle(timeline_name(selected_timeline), displayMode: .inline) @@ -282,7 +277,6 @@ struct ContentView: View { .tabViewStyle(.page(indexDisplayMode: .never)) .overlay( SideMenuView(damus_state: damus, isSidebarVisible: $isSideBarOpened.animation()) - .environmentObject(navigationCoordinator) ) .navigationDestination(for: Route.self) { route in route.view(navigationCordinator: navigationCoordinator, damusState: damus_state!) @@ -651,7 +645,8 @@ struct ContentView: View { bootstrap_relays: bootstrap_relays, replies: ReplyCounter(our_pubkey: pubkey), muted_threads: MutedThreadsManager(keypair: keypair), - wallet: WalletModel(settings: settings) + wallet: WalletModel(settings: settings), + nav: self.navigationCoordinator ) home.damus_state = self.damus_state! diff --git a/damus/Models/DamusState.swift b/damus/Models/DamusState.swift @@ -30,6 +30,7 @@ struct DamusState { let replies: ReplyCounter let muted_threads: MutedThreadsManager let wallet: WalletModel + let nav: NavigationCoordinator @discardableResult func add_zap(zap: Zapping) -> Bool { @@ -57,5 +58,5 @@ struct DamusState { } static var empty: DamusState { - return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(our_pubkey: ""), previews: PreviewCache(), zaps: Zaps(our_pubkey: ""), lnurls: LNUrls(), settings: UserSettingsStore(), relay_filters: RelayFilters(our_pubkey: ""), relay_metadata: RelayMetadatas(), drafts: Drafts(), events: EventCache(), bookmarks: BookmarksManager(pubkey: ""), postbox: PostBox(pool: RelayPool()), bootstrap_relays: [], replies: ReplyCounter(our_pubkey: ""), muted_threads: MutedThreadsManager(keypair: Keypair(pubkey: "", privkey: nil)), wallet: WalletModel(settings: UserSettingsStore())) } + return DamusState.init(pool: RelayPool(), keypair: Keypair(pubkey: "", privkey: ""), likes: EventCounter(our_pubkey: ""), boosts: EventCounter(our_pubkey: ""), contacts: Contacts(our_pubkey: ""), profiles: Profiles(), dms: DirectMessagesModel(our_pubkey: ""), previews: PreviewCache(), zaps: Zaps(our_pubkey: ""), lnurls: LNUrls(), settings: UserSettingsStore(), relay_filters: RelayFilters(our_pubkey: ""), relay_metadata: RelayMetadatas(), drafts: Drafts(), events: EventCache(), bookmarks: BookmarksManager(pubkey: ""), postbox: PostBox(pool: RelayPool()), bootstrap_relays: [], replies: ReplyCounter(our_pubkey: ""), muted_threads: MutedThreadsManager(keypair: Keypair(pubkey: "", privkey: nil)), wallet: WalletModel(settings: UserSettingsStore()), nav: NavigationCoordinator()) } } diff --git a/damus/Util/Router.swift b/damus/Util/Router.swift @@ -10,7 +10,7 @@ import SwiftUI enum Route: Hashable { case ProfileByKey(pubkey: String) case Profile(profile: ProfileModel, followers: FollowersModel) - case Followers(environmentObject: FollowersModel) + case Followers(followers: FollowersModel) case Relay(relay: String, showActionButtons: Binding<Bool>) case RelayDetail(relay: String, metadata: RelayMetadata) case Following(following: FollowingModel) @@ -38,34 +38,29 @@ enum Route: Hashable { case SaveKeys(account: CreateAccountModel) case Wallet(wallet: WalletModel) case WalletScanner(result: Binding<WalletScanResult>) - case FollowersYouKnow(friendedFollowers: [String]) + case FollowersYouKnow(friendedFollowers: [String], followers: FollowersModel) @ViewBuilder func view(navigationCordinator: NavigationCoordinator, damusState: DamusState) -> some View { switch self { case .ProfileByKey(let pubkey): ProfileView(damus_state: damusState, pubkey: pubkey) - .environmentObject(navigationCordinator) case .Profile(let profile, let followers): ProfileView(damus_state: damusState, profile: profile, followers: followers) - .environmentObject(navigationCordinator) - case .Followers(let environmentObject): - FollowersView(damus_state: damusState) - .environmentObject(environmentObject) + case .Followers(let followers): + FollowersView(damus_state: damusState, followers: followers) case .Relay(let relay, let showActionButtons): RelayView(state: damusState, relay: relay, showActionButtons: showActionButtons) case .RelayDetail(let relay, let metadata): RelayDetailView(state: damusState, relay: relay, nip11: metadata) case .Following(let following): FollowingView(damus_state: damusState, following: following) - .environmentObject(navigationCordinator) case .MuteList(let users): MutelistView(damus_state: damusState, users: users) case .RelayConfig: RelayConfigView(state: damusState) case .Bookmarks: BookmarksView(state: damusState) - .environmentObject(navigationCordinator) case .Config: ConfigView(state: damusState) case .EditMetadata: @@ -90,34 +85,26 @@ enum Route: Hashable { ThreadView(state: damusState, thread: thread) case .Reposts(let reposts): RepostsView(damus_state: damusState, model: reposts) - .environmentObject(navigationCordinator) case .Reactions(let reactions): ReactionsView(damus_state: damusState, model: reactions) - .environmentObject(navigationCordinator) case .Zaps(let target): ZapsView(state: damusState, target: target) case .Search(let search): SearchView(appstate: damusState, search: search) - .environmentObject(navigationCordinator) case .EULA: - EULAView() - .environmentObject(navigationCordinator) + EULAView(nav: navigationCordinator) case .Login: - LoginView() - .environmentObject(navigationCordinator) + LoginView(nav: navigationCordinator) case .CreateAccount: - CreateAccountView() - .environmentObject(navigationCordinator) + CreateAccountView(nav: navigationCordinator) case .SaveKeys(let account): SaveKeysView(account: account) - .environmentObject(navigationCordinator) case .Wallet(let walletModel): WalletView(damus_state: damusState, model: walletModel) - .environmentObject(navigationCordinator) case .WalletScanner(let walletScanResult): WalletScannerView(result: walletScanResult) - case .FollowersYouKnow(let friendedFollowers): - FollowersYouKnowView(damus_state: damusState, friended_followers: friendedFollowers) + case .FollowersYouKnow(let friendedFollowers, let followers): + FollowersYouKnowView(damus_state: damusState, friended_followers: friendedFollowers, followers: followers) } } @@ -183,8 +170,8 @@ enum Route: Hashable { return true case (.WalletScanner(_), .WalletScanner(_)): return true - case (.FollowersYouKnow(let lhs_friendedFollowers), .FollowersYouKnow(let rhs_friendedFollowers)): - return lhs_friendedFollowers == rhs_friendedFollowers + case (.FollowersYouKnow(_, _), .FollowersYouKnow(_, _)): + return true default: return false } @@ -268,9 +255,10 @@ enum Route: Hashable { hasher.combine("wallet") case .WalletScanner(_): hasher.combine("walletScanner") - case .FollowersYouKnow(let friendedFollowers): + case .FollowersYouKnow(let friendedFollowers, let followers): hasher.combine("followersYouKnow") hasher.combine(friendedFollowers) + hasher.combine(followers.sub_id) } } } diff --git a/damus/Views/BookmarksView.swift b/damus/Views/BookmarksView.swift @@ -14,7 +14,6 @@ struct BookmarksView: View { @State private var clearAllAlert: Bool = false @Environment(\.dismiss) var dismiss - @EnvironmentObject var navigationCoordinator: NavigationCoordinator @ObservedObject var manager: BookmarksManager init(state: DamusState) { @@ -39,8 +38,6 @@ struct BookmarksView: View { } else { ScrollView { InnerTimelineView(events: EventHolder(events: bookmarks, incoming: []), damus: state, filter: noneFilter) - .environmentObject(navigationCoordinator) - } } } diff --git a/damus/Views/CreateAccountView.swift b/damus/Views/CreateAccountView.swift @@ -10,7 +10,7 @@ import SwiftUI struct CreateAccountView: View { @StateObject var account: CreateAccountModel = CreateAccountModel() @StateObject var profileUploadViewModel = ProfileUploadingViewModel() - @EnvironmentObject var navigationCoordinator: NavigationCoordinator + var nav: NavigationCoordinator func SignupForm<FormContent: View>(@ViewBuilder content: () -> FormContent) -> some View { return VStack(alignment: .leading, spacing: 10.0, content: content) @@ -58,7 +58,7 @@ struct CreateAccountView: View { .padding(.top, 10) Button(action: { - navigationCoordinator.push(route: Route.SaveKeys(account: account)) + nav.push(route: Route.SaveKeys(account: account)) }) { HStack { Text("Create account now", comment: "Button to create account.") @@ -130,7 +130,7 @@ extension View { struct CreateAccountView_Previews: PreviewProvider { static var previews: some View { let model = CreateAccountModel(real: "", nick: "jb55", about: "") - return CreateAccountView(account: model) + return CreateAccountView(account: model, nav: .init()) } } diff --git a/damus/Views/DirectMessagesView.swift b/damus/Views/DirectMessagesView.swift @@ -19,8 +19,6 @@ struct DirectMessagesView: View { @ObservedObject var model: DirectMessagesModel @ObservedObject var settings: UserSettingsStore - @EnvironmentObject var navigationCoordinator: NavigationCoordinator - func MainContent(requests: Bool) -> some View { ScrollView { LazyVStack(spacing: 0) { @@ -53,7 +51,7 @@ struct DirectMessagesView: View { EventView(damus: damus_state, event: ev, pubkey: model.pubkey, options: options) .onTapGesture { self.model.set_active_dm_model(model) - navigationCoordinator.push(route: Route.DMChat(dms: self.model.active_model)) + damus_state.nav.push(route: Route.DMChat(dms: self.model.active_model)) } Divider() diff --git a/damus/Views/EULAView.swift b/damus/Views/EULAView.swift @@ -58,7 +58,7 @@ By using our Application, you signify your acceptance of this EULA. If you do no struct EULAView: View { @Environment(\.colorScheme) var colorScheme @Environment(\.dismiss) var dismiss - @EnvironmentObject var navigationCoordinator: NavigationCoordinator + var nav: NavigationCoordinator var body: some View { ZStack { @@ -91,7 +91,7 @@ struct EULAView: View { } Button(action: { - navigationCoordinator.push(route: Route.Login) + nav.push(route: Route.Login) }) { HStack { Text("Accept", comment: "Button to accept the end user license agreement before being allowed into the app.") @@ -120,6 +120,6 @@ struct EULAView: View { struct EULAView_Previews: PreviewProvider { static var previews: some View { - EULAView() + EULAView(nav: .init()) } } diff --git a/damus/Views/FollowingView.swift b/damus/Views/FollowingView.swift @@ -10,7 +10,6 @@ import SwiftUI struct FollowUserView: View { let target: FollowTarget let damus_state: DamusState - @EnvironmentObject var navigationCoordinator: NavigationCoordinator static let markdown = Markdown() @@ -18,7 +17,7 @@ struct FollowUserView: View { HStack { UserViewRow(damus_state: damus_state, pubkey: target.pubkey) .onTapGesture { - navigationCoordinator.push(route: Route.ProfileByKey(pubkey: target.pubkey)) + damus_state.nav.push(route: Route.ProfileByKey(pubkey: target.pubkey)) } FollowButtonView(target: target, follows_you: false, follow_state: damus_state.contacts.follow_state(target.pubkey)) @@ -30,8 +29,7 @@ struct FollowUserView: View { struct FollowersYouKnowView: View { let damus_state: DamusState let friended_followers: [String] - - @EnvironmentObject var followers: FollowersModel + @ObservedObject var followers: FollowersModel var body: some View { ScrollView { @@ -48,16 +46,13 @@ struct FollowersYouKnowView: View { struct FollowersView: View { let damus_state: DamusState - - @EnvironmentObject var followers: FollowersModel - @EnvironmentObject var navigationCoordinator: NavigationCoordinator + @ObservedObject var followers: FollowersModel var body: some View { ScrollView { LazyVStack(alignment: .leading) { ForEach(followers.contacts ?? [], id: \.self) { pk in FollowUserView(target: .pubkey(pk), damus_state: damus_state) - .environmentObject(navigationCoordinator) } } .padding(.horizontal) @@ -77,14 +72,12 @@ struct FollowingView: View { let following: FollowingModel - @EnvironmentObject var navigationCoordinator: NavigationCoordinator var body: some View { ScrollView { LazyVStack(alignment: .leading) { ForEach(following.contacts.reversed(), id: \.self) { pk in FollowUserView(target: .pubkey(pk), damus_state: damus_state) - .environmentObject(navigationCoordinator) } } .padding() diff --git a/damus/Views/LoginView.swift b/damus/Views/LoginView.swift @@ -37,7 +37,7 @@ struct LoginView: View { @State var is_pubkey: Bool = false @State var error: String? = nil @State private var credential_handler = CredentialHandler() - @EnvironmentObject var navigationCoordinator: NavigationCoordinator + var nav: NavigationCoordinator func get_error(parsed_key: ParsedKey?) -> String? { if self.error != nil { @@ -99,8 +99,7 @@ struct LoginView: View { .padding(.top, 10) } - CreateAccountPrompt() - .environmentObject(navigationCoordinator) + CreateAccountPrompt(nav: nav) .padding(.top, 10) Spacer() @@ -330,14 +329,14 @@ struct SignInEntry: View { } struct CreateAccountPrompt: View { - @EnvironmentObject var navigationCoordinator: NavigationCoordinator + var nav: NavigationCoordinator var body: some View { HStack { Text("New to Nostr?", comment: "Ask the user if they are new to Nostr") .foregroundColor(Color("DamusMediumGrey")) Button(NSLocalizedString("Create account", comment: "Button to navigate to create account view.")) { - navigationCoordinator.push(route: Route.CreateAccount) + nav.push(route: Route.CreateAccount) } Spacer() @@ -351,8 +350,8 @@ struct LoginView_Previews: PreviewProvider { let pubkey = "npub18m76awca3y37hkvuneavuw6pjj4525fw90necxmadrvjg0sdy6qsngq955" let bech32_pubkey = "KeyInput" Group { - LoginView(key: pubkey) - LoginView(key: bech32_pubkey) + LoginView(key: pubkey, nav: .init()) + LoginView(key: bech32_pubkey, nav: .init()) } } } diff --git a/damus/Views/Notifications/EventGroupView.swift b/damus/Views/Notifications/EventGroupView.swift @@ -193,8 +193,6 @@ struct EventGroupView: View { let event: NostrEvent? let group: EventGroupType - @EnvironmentObject var navigationCoordinator: NavigationCoordinator - func GroupDescription(_ pubkeys: [String]) -> some View { Text(verbatim: "\(reacting_to_text(profiles: state.profiles, our_pubkey: state.pubkey, group: group, ev: event, pubkeys: pubkeys))") } @@ -239,7 +237,6 @@ struct EventGroupView: View { let unique_pubkeys = event_group_unique_pubkeys(profiles: state.profiles, group: group) ProfilePicturesView(state: state, pubkeys: unique_pubkeys) - .environmentObject(navigationCoordinator) if let event { let thread = ThreadModel(event: event, damus_state: state) diff --git a/damus/Views/Notifications/NotificationItemView.swift b/damus/Views/Notifications/NotificationItemView.swift @@ -30,8 +30,6 @@ func notification_item_event(events: EventCache, notif: NotificationItem) -> Sho struct NotificationItemView: View { let state: DamusState let item: NotificationItem - - @EnvironmentObject var navigationCoordinator: NavigationCoordinator var show_item: ShowItem { notification_item_event(events: state.events, notif: item) @@ -50,19 +48,15 @@ struct NotificationItemView: View { switch item { case .repost(_, let evgrp): EventGroupView(state: state, event: ev, group: .repost(evgrp)) - .environmentObject(navigationCoordinator) case .event_zap(_, let zapgrp): EventGroupView(state: state, event: ev, group: .zap(zapgrp)) - .environmentObject(navigationCoordinator) case .profile_zap(let grp): EventGroupView(state: state, event: nil, group: .profile_zap(grp)) - .environmentObject(navigationCoordinator) case .reaction(_, let evgrp): EventGroupView(state: state, event: ev, group: .reaction(evgrp)) - .environmentObject(navigationCoordinator) case .reply(let ev): NavigationLink(value: Route.Thread(thread: ThreadModel(event: ev, damus_state: state))) { diff --git a/damus/Views/Notifications/NotificationsView.swift b/damus/Views/Notifications/NotificationsView.swift @@ -89,7 +89,6 @@ struct NotificationsView: View { @SceneStorage("NotificationsView.filter_state") var filter_state: NotificationFilterState = .all @Environment(\.colorScheme) var colorScheme - @EnvironmentObject var navigationCoordinator: NavigationCoordinator var mystery: some View { VStack(spacing: 20) { @@ -174,7 +173,6 @@ struct NotificationsView: View { .frame(height: 5) ForEach(filter.filter(contacts: state.contacts, items: notifications.notifications), id: \.id) { item in NotificationItemView(state: state, item: item) - .environmentObject(navigationCoordinator) } } .background(GeometryReader { proxy -> Color in diff --git a/damus/Views/Notifications/ProfilePicturesView.swift b/damus/Views/Notifications/ProfilePicturesView.swift @@ -10,15 +10,13 @@ import SwiftUI struct ProfilePicturesView: View { let state: DamusState let pubkeys: [String] - - @EnvironmentObject var navigationCoordinator: NavigationCoordinator var body: some View { HStack { ForEach(pubkeys.prefix(8), id: \.self) { pubkey in ProfilePicView(pubkey: pubkey, size: 32.0, highlight: .none, profiles: state.profiles, disable_animation: state.settings.disable_animation) .onTapGesture { - navigationCoordinator.push(route: Route.ProfileByKey(pubkey: pubkey)) + state.nav.push(route: Route.ProfileByKey(pubkey: pubkey)) } } } diff --git a/damus/Views/Profile/ProfileView.swift b/damus/Views/Profile/ProfileView.swift @@ -132,8 +132,6 @@ struct ProfileView: View { @StateObject var followers: FollowersModel @StateObject var zap_button_model: ZapButtonModel = ZapButtonModel() - @EnvironmentObject var navigationCoordinator: NavigationCoordinator - init(damus_state: DamusState, profile: ProfileModel, followers: FollowersModel) { self.damus_state = damus_state self._profile = StateObject(wrappedValue: profile) @@ -415,7 +413,7 @@ struct ProfileView: View { } if followers.contacts != nil { - NavigationLink(value: Route.Followers(environmentObject: followers)) { + NavigationLink(value: Route.Followers(followers: followers)) { followersCount } .buttonStyle(PlainButtonStyle()) @@ -451,7 +449,7 @@ struct ProfileView: View { if !friended_followers.isEmpty { Spacer() - NavigationLink(value: Route.FollowersYouKnow(friendedFollowers: friended_followers)) { + NavigationLink(value: Route.FollowersYouKnow(friendedFollowers: friended_followers, followers: followers)) { HStack { CondensedProfilePicturesView(state: damus_state, pubkeys: friended_followers, maxPictures: 3) Text(followedByString(friended_followers, profiles: damus_state.profiles)) @@ -521,7 +519,6 @@ struct ProfileView: View { } .fullScreenCover(isPresented: $show_qr_code) { QRCodeView(damus_state: damus_state, pubkey: profile.pubkey) - .environmentObject(navigationCoordinator) } if damus_state.is_privkey_user { diff --git a/damus/Views/QRCodeView.swift b/damus/Views/QRCodeView.swift @@ -45,16 +45,13 @@ struct QRCodeView: View { @State var pubkey: String @Environment(\.presentationMode) var presentationMode - @EnvironmentObject var navigationCoordinator: NavigationCoordinator @State private var selectedTab = 0 - @State var scanResult: ProfileScanResult? = nil - @State var profile: Profile? = nil @State var error: String? = nil - @State private var outerTrimEnd: CGFloat = 0 + var animationDuration: Double = 0.5 let generator = UIImpactFeedbackGenerator(style: .light) @@ -265,7 +262,7 @@ struct QRCodeView: View { func show_profile_after_delay() { DispatchQueue.main.asyncAfter(deadline: .now() + animationDuration) { if let scanResult { - navigationCoordinator.push(route: Route.ProfileByKey(pubkey: scanResult.pubkey)) + damus_state.nav.push(route: Route.ProfileByKey(pubkey: scanResult.pubkey)) } } } diff --git a/damus/Views/Reactions/ReactionView.swift b/damus/Views/Reactions/ReactionView.swift @@ -10,7 +10,6 @@ import SwiftUI struct ReactionView: View { let damus_state: DamusState let reaction: NostrEvent - @EnvironmentObject var navigationCoordinator: NavigationCoordinator var content: String { return to_reaction_emoji(ev: reaction) ?? "" @@ -23,7 +22,6 @@ struct ReactionView: View { .frame(width: 50, height: 50) FollowUserView(target: .pubkey(reaction.pubkey), damus_state: damus_state) - .environmentObject(navigationCoordinator) } } } diff --git a/damus/Views/ReactionsView.swift b/damus/Views/ReactionsView.swift @@ -10,7 +10,6 @@ import SwiftUI struct ReactionsView: View { let damus_state: DamusState @StateObject var model: ReactionsModel - @EnvironmentObject var navigationCoordinator: NavigationCoordinator @Environment(\.dismiss) var dismiss @@ -19,7 +18,6 @@ struct ReactionsView: View { LazyVStack { ForEach(model.events, id: \.id) { ev in ReactionView(damus_state: damus_state, reaction: ev) - .environmentObject(navigationCoordinator) } } .padding() diff --git a/damus/Views/RelayFilterView.swift b/damus/Views/RelayFilterView.swift @@ -10,9 +10,6 @@ import SwiftUI struct RelayFilterView: View { let state: DamusState let timeline: Timeline - //@State var relays: [RelayDescriptor] - //@EnvironmentObject var user_settings: UserSettingsStore - //@State var relays: [RelayDescriptor] init(state: DamusState, timeline: Timeline) { self.state = state diff --git a/damus/Views/Reposts/RepostView.swift b/damus/Views/Reposts/RepostView.swift @@ -10,11 +10,9 @@ import SwiftUI struct RepostView: View { let damus_state: DamusState let repost: NostrEvent - @EnvironmentObject var navigationCoordinator: NavigationCoordinator var body: some View { FollowUserView(target: .pubkey(repost.pubkey), damus_state: damus_state) - .environmentObject(navigationCoordinator) } } diff --git a/damus/Views/RepostsView.swift b/damus/Views/RepostsView.swift @@ -10,14 +10,12 @@ import SwiftUI struct RepostsView: View { let damus_state: DamusState @StateObject var model: RepostsModel - @EnvironmentObject var navigationCoordinator: NavigationCoordinator var body: some View { ScrollView { LazyVStack { ForEach(model.events, id: \.id) { ev in RepostView(damus_state: damus_state, repost: ev) - .environmentObject(navigationCoordinator) } } .padding() diff --git a/damus/Views/Search/SearchingEventView.swift b/damus/Views/Search/SearchingEventView.swift @@ -24,7 +24,6 @@ struct SearchingEventView: View { let state: DamusState let evid: String let search_type: SearchType - @EnvironmentObject var navigationCoordinator: NavigationCoordinator @State var search_state: SearchState = .searching @@ -108,7 +107,6 @@ struct SearchingEventView: View { case .found_profile(let pk): NavigationLink(value: Route.ProfileByKey(pubkey: pk)) { FollowUserView(target: .pubkey(pk), damus_state: state) - .environmentObject(navigationCoordinator) } .buttonStyle(PlainButtonStyle()) case .not_found: diff --git a/damus/Views/SearchHomeView.swift b/damus/Views/SearchHomeView.swift @@ -14,7 +14,6 @@ struct SearchHomeView: View { @StateObject var model: SearchHomeModel @State var search: String = "" @FocusState private var isFocused: Bool - @EnvironmentObject var navigationCoordinator: NavigationCoordinator let preferredLanguages = Set(Locale.preferredLanguages.map { localeToLanguage($0) }) @@ -68,7 +67,6 @@ struct SearchHomeView: View { return preferredLanguages.contains(note_lang) } ) - .environmentObject(navigationCoordinator) .refreshable { // Fetch new information by unsubscribing and resubscribing to the relay model.unsubscribe() @@ -78,7 +76,6 @@ struct SearchHomeView: View { var SearchContent: some View { SearchResultsView(damus_state: damus_state, search: $search) - .environmentObject(navigationCoordinator) .refreshable { // Fetch new information by unsubscribing and resubscribing to the relay model.unsubscribe() @@ -129,9 +126,6 @@ struct SearchHomeView: View { struct SearchHomeView_Previews: PreviewProvider { static var previews: some View { let state = test_damus_state() - SearchHomeView( - damus_state: state, - model: SearchHomeModel(damus_state: state) - ) + SearchHomeView(damus_state: state, model: SearchHomeModel(damus_state: state)) } } diff --git a/damus/Views/SearchResultsView.swift b/damus/Views/SearchResultsView.swift @@ -37,11 +37,9 @@ enum Search: Identifiable { struct InnerSearchResults: View { let damus_state: DamusState let search: Search? - @EnvironmentObject var navigationCoordinator: NavigationCoordinator func ProfileSearchResult(pk: String) -> some View { FollowUserView(target: .pubkey(pk), damus_state: damus_state) - .environmentObject(navigationCoordinator) } func HashtagSearch(_ ht: String) -> some View { @@ -70,7 +68,6 @@ struct InnerSearchResults: View { case .nip05(let addr): SearchingEventView(state: damus_state, evid: addr, search_type: .nip05) - .environmentObject(navigationCoordinator) case .profile(let prof): let decoded = try? bech32_decode(prof) @@ -109,12 +106,10 @@ struct SearchResultsView: View { let damus_state: DamusState @Binding var search: String @State var result: Search? = nil - @EnvironmentObject var navigationCoordinator: NavigationCoordinator var body: some View { ScrollView { InnerSearchResults(damus_state: damus_state, search: result) - .environmentObject(navigationCoordinator) .padding() } .frame(maxHeight: .infinity) diff --git a/damus/Views/SearchView.swift b/damus/Views/SearchView.swift @@ -11,11 +11,9 @@ struct SearchView: View { let appstate: DamusState @StateObject var search: SearchModel @Environment(\.dismiss) var dismiss - @EnvironmentObject var navigationCoordinator: NavigationCoordinator var body: some View { TimelineView(events: search.events, loading: $search.loading, damus: appstate, show_friend_icon: true, filter: { _ in true }) - .environmentObject(navigationCoordinator) .navigationBarTitle(describe_search(search.search)) .onReceive(handle_notify(.switched_timeline)) { obj in dismiss() diff --git a/damus/Views/SideMenuView.swift b/damus/Views/SideMenuView.swift @@ -11,11 +11,9 @@ struct SideMenuView: View { let damus_state: DamusState @Binding var isSidebarVisible: Bool @State var confirm_logout: Bool = false - @State private var showQRCode = false - + @Environment(\.colorScheme) var colorScheme - @EnvironmentObject var navigationCoordinator: NavigationCoordinator var sideBarWidth = min(UIScreen.main.bounds.size.width * 0.65, 400.0) let verticalSpacing: CGFloat = 20 @@ -162,7 +160,6 @@ struct SideMenuView: View { .dynamicTypeSize(.xSmall) }).fullScreenCover(isPresented: $showQRCode) { QRCodeView(damus_state: damus_state, pubkey: damus_state.pubkey) - .environmentObject(navigationCoordinator) } } .padding(.top, verticalSpacing) diff --git a/damus/Views/Timeline/InnerTimelineView.swift b/damus/Views/Timeline/InnerTimelineView.swift @@ -12,8 +12,6 @@ struct InnerTimelineView: View { @ObservedObject var events: EventHolder let state: DamusState let filter: (NostrEvent) -> Bool - - @EnvironmentObject var navigationCoordinator: NavigationCoordinator static var count: Int = 0 @@ -48,7 +46,7 @@ struct InnerTimelineView: View { .onTapGesture { let event = ev.get_inner_event(cache: state.events) ?? ev let thread = ThreadModel(event: event, damus_state: state) - navigationCoordinator.push(route: Route.Thread(thread: thread)) + state.nav.push(route: Route.Thread(thread: thread)) } .padding(.top, 7) .onAppear { diff --git a/damus/Views/TimelineView.swift b/damus/Views/TimelineView.swift @@ -8,7 +8,6 @@ import SwiftUI struct TimelineView: View { - @EnvironmentObject var navigationCoordinator: NavigationCoordinator @ObservedObject var events: EventHolder @Binding var loading: Bool @@ -28,7 +27,6 @@ struct TimelineView: View { .frame(height: 1) InnerTimelineView(events: events, damus: damus, filter: loading ? { _ in true } : filter) - .environmentObject(navigationCoordinator) .redacted(reason: loading ? .placeholder : []) .shimmer(loading) .disabled(loading) diff --git a/damus/Views/Wallet/ConnectWalletView.swift b/damus/Views/Wallet/ConnectWalletView.swift @@ -9,12 +9,12 @@ import SwiftUI struct ConnectWalletView: View { @Environment(\.openURL) private var openURL - @EnvironmentObject var navigationCoordinator: NavigationCoordinator @ObservedObject var model: WalletModel @State var scanning: Bool = false @State var error: String? = nil @State var wallet_scan_result: WalletScanResult = .scanning + var nav: NavigationCoordinator var body: some View { MainContent @@ -70,7 +70,7 @@ struct ConnectWalletView: View { } BigButton(NSLocalizedString("Attach Wallet", comment: "Text for button to attach Nostr Wallet Connect lightning wallet.")) { - navigationCoordinator.push(route: Route.WalletScanner(result: $wallet_scan_result)) + nav.push(route: Route.WalletScanner(result: $wallet_scan_result)) } if let err = self.error { @@ -96,6 +96,6 @@ struct ConnectWalletView: View { struct ConnectWalletView_Previews: PreviewProvider { static var previews: some View { - ConnectWalletView(model: WalletModel(settings: UserSettingsStore())) + ConnectWalletView(model: WalletModel(settings: UserSettingsStore()), nav: .init()) } } diff --git a/damus/Views/Wallet/WalletView.swift b/damus/Views/Wallet/WalletView.swift @@ -11,7 +11,6 @@ struct WalletView: View { let damus_state: DamusState @ObservedObject var model: WalletModel @ObservedObject var settings: UserSettingsStore - @EnvironmentObject var navigationCoordinator: NavigationCoordinator init(damus_state: DamusState, model: WalletModel? = nil) { self.damus_state = damus_state @@ -156,11 +155,9 @@ struct WalletView: View { var body: some View { switch model.connect_state { case .new: - ConnectWalletView(model: model) - .environmentObject(navigationCoordinator) + ConnectWalletView(model: model, nav: damus_state.nav) case .none: - ConnectWalletView(model: model) - .environmentObject(navigationCoordinator) + ConnectWalletView(model: model, nav: damus_state.nav) case .existing(let nwc): MainWalletView(nwc: nwc) .onAppear() {