From 20ec8d472f9529f7be0026c50f1d4d5d3a96311e Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Tue, 19 Apr 2022 10:10:06 +0200 Subject: [PATCH] Add close button to modals Swipe down only works on iOS portrait and iPadOS. --- Passepartout/App/Shared/Constants/Theme.swift | 24 +++++++++++++++++-- Passepartout/App/iOS/Views/AboutView.swift | 5 ++++ .../iOS/Views/AddProfile/AddHostView.swift | 16 ++++++++----- .../Views/AddProfile/AddProviderView.swift | 6 +++++ Passepartout/App/iOS/Views/DonateView.swift | 6 +++-- .../App/iOS/Views/Paywall/PaywallView.swift | 3 +++ .../Views/Profile/ProfileView+Rename.swift | 7 ++++-- .../App/iOS/Views/ShortcutsView.swift | 6 ++++- 8 files changed, 60 insertions(+), 13 deletions(-) diff --git a/Passepartout/App/Shared/Constants/Theme.swift b/Passepartout/App/Shared/Constants/Theme.swift index 73a2607c..f1a83015 100644 --- a/Passepartout/App/Shared/Constants/Theme.swift +++ b/Passepartout/App/Shared/Constants/Theme.swift @@ -188,8 +188,8 @@ extension View { "heart.fill" } - var themeAboutImage: String { - "info.circle" + var themeCloseImage: String { + "xmark" } var themeDeleteImage: String { @@ -280,6 +280,26 @@ extension String { // MARK: Shortcuts extension View { + func themeCloseItem(presentationMode: Binding) -> some ToolbarContent { + ToolbarItem(placement: .navigationBarLeading) { + Button { + presentationMode.wrappedValue.dismiss() + } label: { + themeCloseImage.asSystemImage + } + } + } + + func themeCloseItem(isPresented: Binding) -> some ToolbarContent { + ToolbarItem(placement: .navigationBarLeading) { + Button { + isPresented.wrappedValue = false + } label: { + themeCloseImage.asSystemImage + } + } + } + func themeSaveButtonLabel() -> some View { // themeCheckmarkImage.asSystemImage Text(L10n.Global.Strings.save) diff --git a/Passepartout/App/iOS/Views/AboutView.swift b/Passepartout/App/iOS/Views/AboutView.swift index f2ce55c2..2287902a 100644 --- a/Passepartout/App/iOS/Views/AboutView.swift +++ b/Passepartout/App/iOS/Views/AboutView.swift @@ -26,6 +26,8 @@ import SwiftUI struct AboutView: View { + @Environment(\.presentationMode) private var presentationMode + private let versionString = Constants.Global.appVersionString private let readmeURL = Constants.URLs.readme @@ -47,6 +49,9 @@ struct AboutView: View { webSubview }.themeSecondaryView() .navigationTitle(L10n.About.title) + .toolbar { + themeCloseItem(presentationMode: presentationMode) + } } private var infoSubview: some View { diff --git a/Passepartout/App/iOS/Views/AddProfile/AddHostView.swift b/Passepartout/App/iOS/Views/AddProfile/AddHostView.swift index 259a7630..7d5e4462 100644 --- a/Passepartout/App/iOS/Views/AddProfile/AddHostView.swift +++ b/Passepartout/App/iOS/Views/AddProfile/AddHostView.swift @@ -77,12 +77,16 @@ struct AddHostView: View { .onDisappear(perform: dropResourcePermissions) } - private func toolbar() -> some View { - Button(nextString) { - if !viewModel.processedProfile.isPlaceholder { - saveProfile() - } else { - processProfile(replacingExisting: false) + @ToolbarContentBuilder + private func toolbar() -> some ToolbarContent { + themeCloseItem(isPresented: bindings.$isPresented) + ToolbarItem(placement: .primaryAction) { + Button(nextString) { + if !viewModel.processedProfile.isPlaceholder { + saveProfile() + } else { + processProfile(replacingExisting: false) + } } } } diff --git a/Passepartout/App/iOS/Views/AddProfile/AddProviderView.swift b/Passepartout/App/iOS/Views/AddProfile/AddProviderView.swift index 6f5a4fe7..aec2c079 100644 --- a/Passepartout/App/iOS/Views/AddProfile/AddProviderView.swift +++ b/Passepartout/App/iOS/Views/AddProfile/AddProviderView.swift @@ -82,6 +82,7 @@ struct AddProviderView: View { ForEach(viewModel.providers, id: \.navigationId, content: providerNavigationLink) }.themeSecondaryView() .navigationTitle(L10n.AddProfile.Shared.title) + .toolbar(content: toolbar) .sheet(isPresented: $viewModel.isPaywallPresented) { NavigationView { PaywallView(isPresented: $viewModel.isPaywallPresented) @@ -95,6 +96,11 @@ struct AddProviderView: View { } } + @ToolbarContentBuilder + private func toolbar() -> some ToolbarContent { + themeCloseItem(isPresented: bindings.$isPresented) + } + private var mainSection: some View { Section( footer: Text(L10n.AddProfile.Provider.Sections.Vpn.footer) diff --git a/Passepartout/App/iOS/Views/DonateView.swift b/Passepartout/App/iOS/Views/DonateView.swift index e35e4666..8ac16349 100644 --- a/Passepartout/App/iOS/Views/DonateView.swift +++ b/Passepartout/App/iOS/Views/DonateView.swift @@ -42,7 +42,7 @@ struct DonateView: View { } } - @Environment(\.scenePhase) private var scenePhase + @Environment(\.presentationMode) private var presentationMode @ObservedObject private var productManager: ProductManager @@ -60,7 +60,9 @@ struct DonateView: View { .disabled(pendingDonationIdentifier != nil) }.themeSecondaryView() .navigationTitle(L10n.Donate.title) - .alert(item: $alertType, content: presentedAlert) + .toolbar { + themeCloseItem(presentationMode: presentationMode) + }.alert(item: $alertType, content: presentedAlert) } private func presentedAlert(_ alertType: AlertType) -> Alert { diff --git a/Passepartout/App/iOS/Views/Paywall/PaywallView.swift b/Passepartout/App/iOS/Views/Paywall/PaywallView.swift index 61dd240f..1e11d811 100644 --- a/Passepartout/App/iOS/Views/Paywall/PaywallView.swift +++ b/Passepartout/App/iOS/Views/Paywall/PaywallView.swift @@ -60,5 +60,8 @@ struct PaywallView: View { ) } }.themeSecondaryView() + .toolbar { + themeCloseItem(isPresented: $isPresented) + } } } diff --git a/Passepartout/App/iOS/Views/Profile/ProfileView+Rename.swift b/Passepartout/App/iOS/Views/Profile/ProfileView+Rename.swift index aa730781..ae0fa0b9 100644 --- a/Passepartout/App/iOS/Views/Profile/ProfileView+Rename.swift +++ b/Passepartout/App/iOS/Views/Profile/ProfileView+Rename.swift @@ -55,8 +55,11 @@ extension ProfileView { }.themeSecondaryView() .navigationTitle(currentProfile.value.header.name) .toolbar { - Button(action: commitRenaming) { - themeDoneButtonLabel() + themeCloseItem(presentationMode: presentationMode) + ToolbarItem(placement: .primaryAction) { + Button(action: commitRenaming) { + themeDoneButtonLabel() + } } }.alert(isPresented: $isOverwritingExistingProfile, content: alertOverwriteExistingProfile) } diff --git a/Passepartout/App/iOS/Views/ShortcutsView.swift b/Passepartout/App/iOS/Views/ShortcutsView.swift index f3f963e3..df5aa839 100644 --- a/Passepartout/App/iOS/Views/ShortcutsView.swift +++ b/Passepartout/App/iOS/Views/ShortcutsView.swift @@ -45,6 +45,8 @@ struct ShortcutsView: View { @ObservedObject private var intentsManager: IntentsManager + @Environment(\.presentationMode) private var presentationMode + private let target: Profile @State private var modalType: ModalType? @@ -66,7 +68,9 @@ struct ShortcutsView: View { addSection }.themeSecondaryView() .navigationTitle(L10n.Organizer.Items.SiriShortcuts.caption) - .sheet(item: $modalType, content: presentedModal) + .toolbar { + themeCloseItem(presentationMode: presentationMode) + }.sheet(item: $modalType, content: presentedModal) .onAppear { intentsManager.reloadShortcuts() }.onReceive(intentsManager.shouldDismissIntentView) { _ in