Refactor hidden navlinks and send behind in ZStack

This commit is contained in:
Davide De Rosa 2022-04-22 19:02:54 +02:00
parent 2432f0d97a
commit b37ff03e4b
5 changed files with 32 additions and 28 deletions

View File

@ -54,6 +54,7 @@ struct AddHostView: View {
var body: some View { var body: some View {
ZStack { ZStack {
hiddenAccountLink
List { List {
if viewModel.processedProfile.isPlaceholder { if viewModel.processedProfile.isPlaceholder {
processingView processingView
@ -61,14 +62,6 @@ struct AddHostView: View {
completeView completeView
} }
}.animation(.default, value: viewModel) }.animation(.default, value: viewModel)
// hidden
NavigationLink("", isActive: $isEnteringCredentials) {
AddProfileView.AccountWrapperView(
profile: $viewModel.processedProfile,
bindings: bindings
)
}
}.toolbar { }.toolbar {
themeCloseItem(isPresented: bindings.$isPresented) themeCloseItem(isPresented: bindings.$isPresented)
ToolbarItem(placement: .primaryAction) { 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 { private var nextString: String {
if !viewModel.processedProfile.isPlaceholder { if !viewModel.processedProfile.isPlaceholder {

View File

@ -53,6 +53,7 @@ extension AddProviderView {
var body: some View { var body: some View {
ZStack { ZStack {
hiddenAccountLink
List { List {
AddProfileView.ProfileNameSection( AddProfileView.ProfileNameSection(
profileName: $viewModel.profileName, profileName: $viewModel.profileName,
@ -70,14 +71,6 @@ extension AddProviderView {
) )
} }
} }
// hidden
NavigationLink("", isActive: $isEnteringCredentials) {
AddProfileView.AccountWrapperView(
profile: $profile,
bindings: bindings
)
}
}.toolbar { }.toolbar {
Button { Button {
saveProfile(replacingExisting: false) saveProfile(replacingExisting: false)
@ -87,6 +80,15 @@ extension AddProviderView {
}.alert(isPresented: $viewModel.isAskingOverwrite, content: alertOverwriteExistingProfile) }.alert(isPresented: $viewModel.isAskingOverwrite, content: alertOverwriteExistingProfile)
.navigationTitle(providerMetadata.fullName) .navigationTitle(providerMetadata.fullName)
} }
private var hiddenAccountLink: some View {
NavigationLink("", isActive: $isEnteringCredentials) {
AddProfileView.AccountWrapperView(
profile: $profile,
bindings: bindings
)
}
}
private func alertOverwriteExistingProfile() -> Alert { private func alertOverwriteExistingProfile() -> Alert {
return Alert( return Alert(

View File

@ -74,6 +74,7 @@ struct AddProviderView: View {
var body: some View { var body: some View {
ZStack { ZStack {
ForEach(providers, id: \.navigationId, content: hiddenProviderLink)
ScrollViewReader { scrollProxy in ScrollViewReader { scrollProxy in
List { List {
mainSection mainSection
@ -85,9 +86,6 @@ struct AddProviderView: View {
}.disabled(viewModel.pendingOperation != nil) }.disabled(viewModel.pendingOperation != nil)
.animation(.default, value: providers) .animation(.default, value: providers)
} }
// hidden
ForEach(providers, id: \.navigationId, content: providerNavigationLink)
}.toolbar { }.toolbar {
themeCloseItem(isPresented: bindings.$isPresented) themeCloseItem(isPresented: bindings.$isPresented)
}.sheet(isPresented: $viewModel.isPaywallPresented) { }.sheet(isPresented: $viewModel.isPaywallPresented) {
@ -131,7 +129,7 @@ struct AddProviderView: View {
}.withTrailingProgress(when: isFetchingProvider(metadata.name)) }.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) { NavigationLink("", tag: metadata, selection: $viewModel.selectedProvider) {
NameView( NameView(
profile: $viewModel.pendingProfile, profile: $viewModel.pendingProfile,

View File

@ -54,10 +54,7 @@ extension OrganizerView {
var body: some View { var body: some View {
debugChanges() debugChanges()
return ZStack { return ZStack {
NavigationLink("", isActive: $isPresentingProfile) { hiddenProfileLink
ProfileView()
}.onAppear(perform: presentActiveProfile)
mainView mainView
if profileManager.headers.isEmpty { if profileManager.headers.isEmpty {
emptyView emptyView
@ -89,7 +86,7 @@ extension OrganizerView {
.themeInformativeText() .themeInformativeText()
} }
} }
private func profileButton(forHeader header: Profile.Header) -> some View { private func profileButton(forHeader header: Profile.Header) -> some View {
Button { Button {
presentProfile(withId: header.id) presentProfile(withId: header.id)
@ -100,6 +97,12 @@ extension OrganizerView {
) )
} }
} }
private var hiddenProfileLink: some View {
NavigationLink("", isActive: $isPresentingProfile) {
ProfileView()
}.onAppear(perform: presentActiveProfile)
}
} }
} }

View File

@ -47,6 +47,7 @@ extension ShortcutsView {
var body: some View { var body: some View {
ZStack { ZStack {
hiddenProviderLocationLink
List { List {
Section( Section(
header: Text(Unlocalized.VPN.vpn) header: Text(Unlocalized.VPN.vpn)
@ -68,8 +69,6 @@ extension ShortcutsView {
Button(L10n.Shortcuts.Add.Items.UntrustCellular.caption, action: addUntrustCellular) Button(L10n.Shortcuts.Add.Items.UntrustCellular.caption, action: addUntrustCellular)
} }
} }
providerLocationLink
}.navigationTitle(L10n.Shortcuts.Add.title) }.navigationTitle(L10n.Shortcuts.Add.title)
} }
@ -84,7 +83,7 @@ extension ShortcutsView {
} }
} }
private var providerLocationLink: some View { private var hiddenProviderLocationLink: some View {
NavigationLink("", isActive: $isPresentingProviderLocation) { NavigationLink("", isActive: $isPresentingProviderLocation) {
ProviderLocationView( ProviderLocationView(
currentProfile: pendingProfile, currentProfile: pendingProfile,