diff --git a/Mail/Views/Bottom sheets/Actions/ActionsPanelViewModifier.swift b/Mail/Views/Bottom sheets/Actions/ActionsPanelViewModifier.swift
index 9748d3289a..ea02a42170 100644
--- a/Mail/Views/Bottom sheets/Actions/ActionsPanelViewModifier.swift
+++ b/Mail/Views/Bottom sheets/Actions/ActionsPanelViewModifier.swift
@@ -51,7 +51,8 @@ struct ActionsPanelViewModifier: ViewModifier {
}
}
.sheet(item: $moveAction) { moveAction in
- MoveEmailView.sheetView(moveAction: moveAction)
+ MoveEmailView(moveAction: moveAction)
+ .sheetViewStyle()
}
.floatingPanel(item: $reportJunkActionsTarget) { target in
ReportJunkView(mailboxManager: mailboxManager,
diff --git a/Mail/Views/Menu Drawer/MailboxManagement/MailboxesManagementView.swift b/Mail/Views/Menu Drawer/MailboxManagement/MailboxesManagementView.swift
index e53b3b761c..21b1a66a96 100644
--- a/Mail/Views/Menu Drawer/MailboxManagement/MailboxesManagementView.swift
+++ b/Mail/Views/Menu Drawer/MailboxManagement/MailboxesManagementView.swift
@@ -79,9 +79,8 @@ struct MailboxesManagementView: View {
}
}
.sheet(isPresented: $isShowingSwitchAccount) {
- SheetView {
- AccountListView()
- }
+ AccountListView()
+ .sheetViewStyle()
}
.sheet(isPresented: $isShowingManageAccount) {
AccountView(mailboxes: mailboxes)
diff --git a/Mail/Views/Menu Drawer/MenuDrawerView.swift b/Mail/Views/Menu Drawer/MenuDrawerView.swift
index 3d39b4a87e..092589854d 100644
--- a/Mail/Views/Menu Drawer/MenuDrawerView.swift
+++ b/Mail/Views/Menu Drawer/MenuDrawerView.swift
@@ -192,9 +192,8 @@ struct MenuDrawerView: View {
.background(MailResourcesAsset.backgroundSecondaryColor.swiftUIColor.ignoresSafeArea())
.environment(\.folderCellType, .link)
.sheet(isPresented: $viewModel.isShowingHelp) {
- SheetView {
- HelpView()
- }
+ HelpView()
+ .sheetViewStyle()
}
.sheet(isPresented: $viewModel.isShowingBugTracker) {
BugTrackerView(isPresented: $viewModel.isShowingBugTracker)
diff --git a/Mail/Views/Menu Drawer/MenuHeaderView.swift b/Mail/Views/Menu Drawer/MenuHeaderView.swift
index bd141013bb..96ae784bae 100644
--- a/Mail/Views/Menu Drawer/MenuHeaderView.swift
+++ b/Mail/Views/Menu Drawer/MenuHeaderView.swift
@@ -53,9 +53,8 @@ struct MenuHeaderView: View {
.clipped()
.shadow(color: MailResourcesAsset.menuDrawerShadowColor.swiftUIColor, radius: 1, x: 0, y: 2)
.sheet(isPresented: $isShowingSettings) {
- SheetView {
- SettingsView()
- }
+ SettingsView()
+ .sheetViewStyle()
}
}
}
diff --git a/Mail/Views/SheetView.swift b/Mail/Views/SheetView.swift
deleted file mode 100644
index 912970b673..0000000000
--- a/Mail/Views/SheetView.swift
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- Infomaniak Mail - iOS App
- Copyright (C) 2022 Infomaniak Network SA
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
- */
-
-import MailCore
-import MailResources
-import SwiftUI
-
-struct SheetView: View where Content: View {
- @Environment(\.dismiss) private var dismiss
-
- @ViewBuilder let content: Content
-
- var body: some View {
- NavigationView {
- content
- .navigationBarItems(leading: Button {
- dismiss()
- } label: {
- Label(MailResourcesStrings.Localizable.buttonClose, systemImage: "xmark")
- })
- }
- .onReceive(NotificationCenter.default.publisher(for: Constants.dismissMoveSheetNotificationName)) { _ in
- dismiss()
- }
- }
-}
-
-struct SheetView_Previews: PreviewProvider {
- static var previews: some View {
- SheetView {
- EmptyView()
- }
- }
-}
diff --git a/Mail/Views/SheetViewModifier.swift b/Mail/Views/SheetViewModifier.swift
new file mode 100644
index 0000000000..b2c1bc5943
--- /dev/null
+++ b/Mail/Views/SheetViewModifier.swift
@@ -0,0 +1,67 @@
+/*
+ Infomaniak Mail - iOS App
+ Copyright (C) 2022 Infomaniak Network SA
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+
+import MailCore
+import MailResources
+import SwiftUI
+
+typealias DismissModalAction = () -> Void
+
+struct DismissModalKey: EnvironmentKey {
+ static let defaultValue: DismissModalAction = {/* dismiss nothing by default */}
+}
+
+extension EnvironmentValues {
+ var dismissModal: DismissModalAction {
+ get {
+ return self[DismissModalKey.self]
+ }
+ set {
+ self[DismissModalKey.self] = newValue
+ }
+ }
+}
+
+extension View {
+ func sheetViewStyle() -> some View {
+ modifier(SheetViewModifier())
+ }
+}
+
+struct SheetViewModifier: ViewModifier {
+ @Environment(\.dismiss) private var dismiss
+
+ func body(content: Content) -> some View {
+ NavigationView {
+ content
+ .environment(\.dismissModal) {
+ dismiss()
+ }
+ .toolbar {
+ ToolbarItem(placement: .cancellationAction) {
+ Button {
+ dismiss()
+ } label: {
+ Label(MailResourcesStrings.Localizable.buttonClose, systemImage: "xmark")
+ }
+ }
+ }
+ }
+ .navigationViewStyle(.stack)
+ }
+}
diff --git a/Mail/Views/Thread List/ThreadListSwipeAction.swift b/Mail/Views/Thread List/ThreadListSwipeAction.swift
index 4f74d93fe6..cdab919a14 100644
--- a/Mail/Views/Thread List/ThreadListSwipeAction.swift
+++ b/Mail/Views/Thread List/ThreadListSwipeAction.swift
@@ -125,7 +125,8 @@ struct ThreadListSwipeActions: ViewModifier {
}
.actionsPanel(actionsTarget: $actionsTarget)
.sheet(item: $moveAction) { moveAction in
- MoveEmailView.sheetView(moveAction: moveAction)
+ MoveEmailView(moveAction: moveAction)
+ .sheetViewStyle()
}
}
}
diff --git a/Mail/Views/Thread/MoveEmailView.swift b/Mail/Views/Thread/MoveEmailView.swift
index b51d97630b..f2ca618317 100644
--- a/Mail/Views/Thread/MoveEmailView.swift
+++ b/Mail/Views/Thread/MoveEmailView.swift
@@ -36,6 +36,8 @@ struct MoveAction: Identifiable {
struct MoveEmailView: View {
@LazyInjectService private var matomo: MatomoUtils
+ @Environment(\.dismissModal) var dismissModal
+
@EnvironmentObject private var mailboxManager: MailboxManager
typealias MoveHandler = (Folder) -> Void
@@ -107,20 +109,12 @@ struct MoveEmailView: View {
Task {
try await move(to: folder)
}
- NotificationCenter.default.post(Notification(name: Constants.dismissMoveSheetNotificationName))
+ dismissModal()
}
}
}
}
-extension MoveEmailView {
- static func sheetView(moveAction: MoveAction) -> some View {
- SheetView {
- MoveEmailView(moveAction: moveAction)
- }
- }
-}
-
struct MoveMessageView_Previews: PreviewProvider {
static var previews: some View {
MoveEmailView(moveAction: MoveAction(fromFolderId: PreviewHelper.sampleFolder.id,