From b37ff03e4b3981e8b05852297ae8ce65050a5d54 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Fri, 22 Apr 2022 19:02:54 +0200 Subject: [PATCH] Refactor hidden navlinks and send behind in ZStack --- Passepartout/App/Views/AddHostView.swift | 18 ++++++++++-------- .../App/Views/AddProviderView+Name.swift | 18 ++++++++++-------- Passepartout/App/Views/AddProviderView.swift | 6 ++---- .../App/Views/OrganizerView+Profiles.swift | 13 ++++++++----- Passepartout/App/Views/ShortcutsView+Add.swift | 5 ++--- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/Passepartout/App/Views/AddHostView.swift b/Passepartout/App/Views/AddHostView.swift index 36a2bb36..1a0c757d 100644 --- a/Passepartout/App/Views/AddHostView.swift +++ b/Passepartout/App/Views/AddHostView.swift @@ -54,6 +54,7 @@ struct AddHostView: View { var body: some View { ZStack { + hiddenAccountLink List { if viewModel.processedProfile.isPlaceholder { processingView @@ -61,14 +62,6 @@ struct AddHostView: View { completeView } }.animation(.default, value: viewModel) - - // hidden - NavigationLink("", isActive: $isEnteringCredentials) { - AddProfileView.AccountWrapperView( - profile: $viewModel.processedProfile, - bindings: bindings - ) - } }.toolbar { themeCloseItem(isPresented: bindings.$isPresented) ToolbarItem(placement: .primaryAction) { @@ -133,6 +126,15 @@ struct AddHostView: View { } } } + + private var hiddenAccountLink: some View { + NavigationLink("", isActive: $isEnteringCredentials) { + AddProfileView.AccountWrapperView( + profile: $viewModel.processedProfile, + bindings: bindings + ) + } + } private var nextString: String { if !viewModel.processedProfile.isPlaceholder { diff --git a/Passepartout/App/Views/AddProviderView+Name.swift b/Passepartout/App/Views/AddProviderView+Name.swift index a0102924..c35daa59 100644 --- a/Passepartout/App/Views/AddProviderView+Name.swift +++ b/Passepartout/App/Views/AddProviderView+Name.swift @@ -53,6 +53,7 @@ extension AddProviderView { var body: some View { ZStack { + hiddenAccountLink List { AddProfileView.ProfileNameSection( profileName: $viewModel.profileName, @@ -70,14 +71,6 @@ extension AddProviderView { ) } } - - // hidden - NavigationLink("", isActive: $isEnteringCredentials) { - AddProfileView.AccountWrapperView( - profile: $profile, - bindings: bindings - ) - } }.toolbar { Button { saveProfile(replacingExisting: false) @@ -87,6 +80,15 @@ extension AddProviderView { }.alert(isPresented: $viewModel.isAskingOverwrite, content: alertOverwriteExistingProfile) .navigationTitle(providerMetadata.fullName) } + + private var hiddenAccountLink: some View { + NavigationLink("", isActive: $isEnteringCredentials) { + AddProfileView.AccountWrapperView( + profile: $profile, + bindings: bindings + ) + } + } private func alertOverwriteExistingProfile() -> Alert { return Alert( diff --git a/Passepartout/App/Views/AddProviderView.swift b/Passepartout/App/Views/AddProviderView.swift index b8c90344..547d3e40 100644 --- a/Passepartout/App/Views/AddProviderView.swift +++ b/Passepartout/App/Views/AddProviderView.swift @@ -74,6 +74,7 @@ struct AddProviderView: View { var body: some View { ZStack { + ForEach(providers, id: \.navigationId, content: hiddenProviderLink) ScrollViewReader { scrollProxy in List { mainSection @@ -85,9 +86,6 @@ struct AddProviderView: View { }.disabled(viewModel.pendingOperation != nil) .animation(.default, value: providers) } - - // hidden - ForEach(providers, id: \.navigationId, content: providerNavigationLink) }.toolbar { themeCloseItem(isPresented: bindings.$isPresented) }.sheet(isPresented: $viewModel.isPaywallPresented) { @@ -131,7 +129,7 @@ struct AddProviderView: View { }.withTrailingProgress(when: isFetchingProvider(metadata.name)) } - private func providerNavigationLink(_ metadata: ProviderMetadata) -> some View { + private func hiddenProviderLink(_ metadata: ProviderMetadata) -> some View { NavigationLink("", tag: metadata, selection: $viewModel.selectedProvider) { NameView( profile: $viewModel.pendingProfile, diff --git a/Passepartout/App/Views/OrganizerView+Profiles.swift b/Passepartout/App/Views/OrganizerView+Profiles.swift index 361f2edd..53d20b73 100644 --- a/Passepartout/App/Views/OrganizerView+Profiles.swift +++ b/Passepartout/App/Views/OrganizerView+Profiles.swift @@ -54,10 +54,7 @@ extension OrganizerView { var body: some View { debugChanges() return ZStack { - NavigationLink("", isActive: $isPresentingProfile) { - ProfileView() - }.onAppear(perform: presentActiveProfile) - + hiddenProfileLink mainView if profileManager.headers.isEmpty { emptyView @@ -89,7 +86,7 @@ extension OrganizerView { .themeInformativeText() } } - + private func profileButton(forHeader header: Profile.Header) -> some View { Button { presentProfile(withId: header.id) @@ -100,6 +97,12 @@ extension OrganizerView { ) } } + + private var hiddenProfileLink: some View { + NavigationLink("", isActive: $isPresentingProfile) { + ProfileView() + }.onAppear(perform: presentActiveProfile) + } } } diff --git a/Passepartout/App/Views/ShortcutsView+Add.swift b/Passepartout/App/Views/ShortcutsView+Add.swift index ac4d3a0b..f32695c6 100644 --- a/Passepartout/App/Views/ShortcutsView+Add.swift +++ b/Passepartout/App/Views/ShortcutsView+Add.swift @@ -47,6 +47,7 @@ extension ShortcutsView { var body: some View { ZStack { + hiddenProviderLocationLink List { Section( header: Text(Unlocalized.VPN.vpn) @@ -68,8 +69,6 @@ extension ShortcutsView { Button(L10n.Shortcuts.Add.Items.UntrustCellular.caption, action: addUntrustCellular) } } - - providerLocationLink }.navigationTitle(L10n.Shortcuts.Add.title) } @@ -84,7 +83,7 @@ extension ShortcutsView { } } - private var providerLocationLink: some View { + private var hiddenProviderLocationLink: some View { NavigationLink("", isActive: $isPresentingProviderLocation) { ProviderLocationView( currentProfile: pendingProfile,