Skip to content

Commit

Permalink
refactor(SheetView): This is now a SheetViewModifier
Browse files Browse the repository at this point in the history
(Is there something left that I didn't refactor? :pls:)
  • Loading branch information
PhilippeWeidmann committed May 3, 2023
1 parent fe3a2e3 commit 1287d77
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ struct MailboxesManagementView: View {
}
}
.sheet(isPresented: $isShowingSwitchAccount) {
SheetView {
AccountListView()
}
AccountListView()
.sheetViewStyle()
}
.sheet(isPresented: $isShowingManageAccount) {
AccountView(mailboxes: mailboxes)
Expand Down
5 changes: 2 additions & 3 deletions Mail/Views/Menu Drawer/MenuDrawerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions Mail/Views/Menu Drawer/MenuHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
Expand Down
49 changes: 0 additions & 49 deletions Mail/Views/SheetView.swift

This file was deleted.

67 changes: 67 additions & 0 deletions Mail/Views/SheetViewModifier.swift
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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)
}
}
3 changes: 2 additions & 1 deletion Mail/Views/Thread List/ThreadListSwipeAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ struct ThreadListSwipeActions: ViewModifier {
}
.actionsPanel(actionsTarget: $actionsTarget)
.sheet(item: $moveAction) { moveAction in
MoveEmailView.sheetView(moveAction: moveAction)
MoveEmailView(moveAction: moveAction)
.sheetViewStyle()
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions Mail/Views/Thread/MoveEmailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1287d77

Please sign in to comment.