diff --git a/Mail/Utils/AdaptivePanelViewModifier.swift b/Mail/Utils/AdaptivePanelViewModifier.swift index 55ac8187d..e6e87432f 100644 --- a/Mail/Utils/AdaptivePanelViewModifier.swift +++ b/Mail/Utils/AdaptivePanelViewModifier.swift @@ -30,6 +30,7 @@ struct AdaptivePanelViewModifier: ViewMo @Binding var item: Item? @ViewBuilder var panelContent: (Item) -> PanelContent + func body(content: Content) -> some View { content .popover(item: $item) { item in diff --git a/Mail/Utils/SheetOrAlertPanel.swift b/Mail/Utils/SheetOrAlertPanel.swift new file mode 100644 index 000000000..7342ab0b7 --- /dev/null +++ b/Mail/Utils/SheetOrAlertPanel.swift @@ -0,0 +1,52 @@ +/* + Infomaniak Mail - iOS App + Copyright (C) 2024 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 SwiftUI +import SwiftUIBackports + +extension View { + func sheetOrAlertPanel(isPresented: Binding, + @ViewBuilder modalContent: @escaping () -> ModalContent) -> some View { + modifier(SheetOrAlertPanel(isPresented: isPresented, modalContent: modalContent)) + } +} + +struct SheetOrAlertPanel: ViewModifier { + @Environment(\.isCompactWindow) private var isCompactWindow + + @Binding var isPresented: Bool + + @ViewBuilder let modalContent: () -> ModalContent + + func body(content: Content) -> some View { + content + .sheet(isPresented: Binding(get: { isCompactWindow && isPresented }, set: { isPresented = $0 })) { + if #available(iOS 16.0, *) { + modalContent() + .modifier(SelfSizingPanelViewModifier()) + } else { + modalContent() + .modifier(SelfSizingPanelBackportViewModifier()) + } + } + .customAlert(isPresented: Binding(get: { !isCompactWindow && isPresented }, set: { isPresented = $0 })) { + modalContent() + } + } +} diff --git a/Mail/Views/Bottom sheets/Actions/HeaderCloseButtonView.swift b/Mail/Views/Bottom sheets/Actions/HeaderCloseButtonView.swift index 261bd5599..8515e8f86 100644 --- a/Mail/Views/Bottom sheets/Actions/HeaderCloseButtonView.swift +++ b/Mail/Views/Bottom sheets/Actions/HeaderCloseButtonView.swift @@ -32,7 +32,6 @@ struct HeaderCloseButtonView: View { .foregroundStyle(MailTextStyle.header2.color) .frame(maxWidth: .infinity) } - .padding(.horizontal, value: .regular) .padding(.trailing, IKIcon.Size.small.rawValue) .padding(.bottom, value: .regular) } diff --git a/Mail/Views/Bottom sheets/Actions/ReportJunkView.swift b/Mail/Views/Bottom sheets/Actions/ReportJunkView.swift index f98c9d7c0..74b1cee00 100644 --- a/Mail/Views/Bottom sheets/Actions/ReportJunkView.swift +++ b/Mail/Views/Bottom sheets/Actions/ReportJunkView.swift @@ -38,6 +38,7 @@ struct ReportJunkView: View { HeaderCloseButtonView(title: MailResourcesStrings.Localizable.actionReportJunk) { dismiss() } + .padding(.horizontal, value: .regular) } ForEach(actions) { action in diff --git a/Mail/Views/Bottom sheets/RestoreEmailsView.swift b/Mail/Views/Bottom sheets/RestoreEmailsView.swift index b7a226ec0..660c30fa6 100644 --- a/Mail/Views/Bottom sheets/RestoreEmailsView.swift +++ b/Mail/Views/Bottom sheets/RestoreEmailsView.swift @@ -26,6 +26,9 @@ import SwiftUI struct RestoreEmailsView: View { @EnvironmentObject var mailboxManager: MailboxManager + @Environment(\.dismiss) private var dismiss + @Environment(\.isCompactWindow) private var isCompactWindow + @State private var selectedDate = "" @State private var availableDates = [String]() @State private var pickerNoSelectionText = MailResourcesStrings.Localizable.loadingText @@ -34,30 +37,30 @@ struct RestoreEmailsView: View { @LazyInjectService private var snackbarPresenter: SnackBarPresentable var body: some View { - VStack(alignment: .leading) { + VStack(alignment: .leading, spacing: 0) { Text(MailResourcesStrings.Localizable.restoreEmailsTitle) .textStyle(.bodyMedium) - .padding(.bottom, 16) + .padding(.bottom, value: .regular) Text(MailResourcesStrings.Localizable.restoreEmailsText) .textStyle(.bodySecondary) - .padding(.bottom, 10) + .padding(.bottom, value: .small) LargePicker(title: MailResourcesStrings.Localizable.restoreEmailsBackupDate, noSelectionText: pickerNoSelectionText, selection: $selectedDate, items: availableDates.map(mapDates)) - .padding(.bottom, 24) + .padding(.bottom, value: .medium) .onChange(of: selectedDate) { _ in matomo.track(eventWithCategory: .restoreEmailsBottomSheet, action: .input, name: "selectDate") } ModalButtonsView(primaryButtonTitle: MailResourcesStrings.Localizable.buttonConfirmRestoreEmails, - secondaryButtonTitle: nil, primaryButtonEnabled: !availableDates.isEmpty, - primaryButtonAction: restoreEmails) + primaryButtonAction: restoreEmails, + secondaryButtonAction: dismiss.callAsFunction) } - .padding(.horizontal, UIPadding.bottomSheetHorizontal) + .padding(.horizontal, isCompactWindow ? UIPadding.bottomSheetHorizontal : 0) .task { await tryOrDisplayError { let backupsList = try await mailboxManager.apiFetcher.listBackups(mailbox: mailboxManager.mailbox).backups diff --git a/Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift b/Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift index 45214f2e8..9a3df7d23 100644 --- a/Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift +++ b/Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift @@ -59,7 +59,7 @@ struct MenuDrawerItemsAdvancedListView: View { ) { isShowingRestoreMails = true } - .floatingPanel(isPresented: $isShowingRestoreMails) { + .sheetOrAlertPanel(isPresented: $isShowingRestoreMails) { RestoreEmailsView() } }