Add close button to modals

Swipe down only works on iOS portrait and iPadOS.
This commit is contained in:
Davide De Rosa 2022-04-19 10:10:06 +02:00
parent 991a283de9
commit 20ec8d472f
8 changed files with 60 additions and 13 deletions

View File

@ -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<PresentationMode>) -> some ToolbarContent {
ToolbarItem(placement: .navigationBarLeading) {
Button {
presentationMode.wrappedValue.dismiss()
} label: {
themeCloseImage.asSystemImage
}
}
}
func themeCloseItem(isPresented: Binding<Bool>) -> some ToolbarContent {
ToolbarItem(placement: .navigationBarLeading) {
Button {
isPresented.wrappedValue = false
} label: {
themeCloseImage.asSystemImage
}
}
}
func themeSaveButtonLabel() -> some View {
// themeCheckmarkImage.asSystemImage
Text(L10n.Global.Strings.save)

View File

@ -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 {

View File

@ -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)
}
}
}
}

View File

@ -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)

View File

@ -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 {

View File

@ -60,5 +60,8 @@ struct PaywallView: View {
)
}
}.themeSecondaryView()
.toolbar {
themeCloseItem(isPresented: $isPresented)
}
}
}

View File

@ -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)
}

View File

@ -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