From ae5640bd7a6201307d5680e5cd6724a10eedfb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charle=CC=80ne=20Hoareau?= Date: Fri, 5 Apr 2024 09:50:08 +0200 Subject: [PATCH 1/6] chore: Add close button to RestoreEmailsView --- .../Bottom sheets/RestoreEmailsView.swift | 73 +++++++++++-------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/Mail/Views/Bottom sheets/RestoreEmailsView.swift b/Mail/Views/Bottom sheets/RestoreEmailsView.swift index b7a226ec0..193985dce 100644 --- a/Mail/Views/Bottom sheets/RestoreEmailsView.swift +++ b/Mail/Views/Bottom sheets/RestoreEmailsView.swift @@ -26,49 +26,62 @@ import SwiftUI struct RestoreEmailsView: View { @EnvironmentObject var mailboxManager: MailboxManager + @Environment(\.dismiss) private var dismiss + @State private var selectedDate = "" @State private var availableDates = [String]() @State private var pickerNoSelectionText = MailResourcesStrings.Localizable.loadingText @LazyInjectService private var matomo: MatomoUtils @LazyInjectService private var snackbarPresenter: SnackBarPresentable + @LazyInjectService private var platformDetector: PlatformDetectable var body: some View { - VStack(alignment: .leading) { - Text(MailResourcesStrings.Localizable.restoreEmailsTitle) - .textStyle(.bodyMedium) - .padding(.bottom, 16) - - Text(MailResourcesStrings.Localizable.restoreEmailsText) - .textStyle(.bodySecondary) - .padding(.bottom, 10) - - LargePicker(title: MailResourcesStrings.Localizable.restoreEmailsBackupDate, - noSelectionText: pickerNoSelectionText, - selection: $selectedDate, - items: availableDates.map(mapDates)) - .padding(.bottom, 24) - .onChange(of: selectedDate) { _ in - matomo.track(eventWithCategory: .restoreEmailsBottomSheet, action: .input, name: "selectDate") + VStack(alignment: .leading, spacing: 0) { + if platformDetector.isMac || UIDevice.current.systemName == "iPadOS" { + HeaderCloseButtonView(title: MailResourcesStrings.Localizable.restoreEmailsTitle) { + dismiss() } + .padding(.horizontal, UIPadding.small) + } else { + Text(MailResourcesStrings.Localizable.restoreEmailsTitle) + .textStyle(.bodyMedium) + .padding(.bottom, 16) + .padding(.horizontal, UIPadding.bottomSheetHorizontal) + } - ModalButtonsView(primaryButtonTitle: MailResourcesStrings.Localizable.buttonConfirmRestoreEmails, - secondaryButtonTitle: nil, - primaryButtonEnabled: !availableDates.isEmpty, - primaryButtonAction: restoreEmails) - } - .padding(.horizontal, UIPadding.bottomSheetHorizontal) - .task { - await tryOrDisplayError { - let backupsList = try await mailboxManager.apiFetcher.listBackups(mailbox: mailboxManager.mailbox).backups - withAnimation { - availableDates = backupsList - selectedDate = backupsList.last ?? "" - pickerNoSelectionText = MailResourcesStrings.Localizable.pickerNoSelection + VStack(alignment: .leading, spacing: 0) { + Text(MailResourcesStrings.Localizable.restoreEmailsText) + .textStyle(.bodySecondary) + .padding(.bottom, 10) + + LargePicker(title: MailResourcesStrings.Localizable.restoreEmailsBackupDate, + noSelectionText: pickerNoSelectionText, + selection: $selectedDate, + items: availableDates.map(mapDates)) + .padding(.bottom, 24) + .onChange(of: selectedDate) { _ in + matomo.track(eventWithCategory: .restoreEmailsBottomSheet, action: .input, name: "selectDate") + } + + ModalButtonsView(primaryButtonTitle: MailResourcesStrings.Localizable.buttonConfirmRestoreEmails, + secondaryButtonTitle: nil, + primaryButtonEnabled: !availableDates.isEmpty, + primaryButtonAction: restoreEmails) + } + .padding(.horizontal, UIPadding.bottomSheetHorizontal) + .task { + await tryOrDisplayError { + let backupsList = try await mailboxManager.apiFetcher.listBackups(mailbox: mailboxManager.mailbox).backups + withAnimation { + availableDates = backupsList + selectedDate = backupsList.last ?? "" + pickerNoSelectionText = MailResourcesStrings.Localizable.pickerNoSelection + } } } + .matomoView(view: [MatomoUtils.View.bottomSheet.displayName, "RestoreEmailsView"]) } - .matomoView(view: [MatomoUtils.View.bottomSheet.displayName, "RestoreEmailsView"]) } private func restoreEmails() async { From 6f35fe23052707a327f490576496a79d7ec4ab68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charle=CC=80ne=20Hoareau?= Date: Wed, 10 Apr 2024 10:06:58 +0200 Subject: [PATCH 2/6] feat: Add AdaptivePanelViewIsPresentedModifier --- Mail/Utils/AdaptivePanelViewModifier.swift | 55 ++++++++++++++----- .../Bottom sheets/RestoreEmailsView.swift | 15 ++--- .../Items/MenuDrawerItemsListView.swift | 2 +- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/Mail/Utils/AdaptivePanelViewModifier.swift b/Mail/Utils/AdaptivePanelViewModifier.swift index 55ac8187d..1c11e2fd4 100644 --- a/Mail/Utils/AdaptivePanelViewModifier.swift +++ b/Mail/Utils/AdaptivePanelViewModifier.swift @@ -21,29 +21,58 @@ import SwiftUI extension View { func adaptivePanel(item: Binding, @ViewBuilder content: @escaping (Item) -> Content) -> some View { - return modifier(AdaptivePanelViewModifier(item: item, panelContent: content)) + return modifier(AdaptivePanelViewItemModifier(item: item, panelContent: content)) } -} -struct AdaptivePanelViewModifier: ViewModifier { - @Environment(\.isCompactWindow) private var isCompactWindow + func adaptivePanel(isPresented: Binding, + @ViewBuilder content: @escaping () -> + Content) -> some View { + return modifier(AdaptivePanelViewIsPresentedModifier(isPresented: isPresented, panelContent: content)) + } +} +struct AdaptivePanelViewItemModifier: ViewModifier { @Binding var item: Item? @ViewBuilder var panelContent: (Item) -> PanelContent func body(content: Content) -> some View { content .popover(item: $item) { item in - if isCompactWindow { - if #available(iOS 16.0, *) { - panelContent(item).modifier(SelfSizingPanelViewModifier()) - } else { - panelContent(item).modifier(SelfSizingPanelBackportViewModifier()) - } - } else { + AdaptativeView { panelContent(item) - .padding() - .frame(idealWidth: 400) } } } } + +struct AdaptivePanelViewIsPresentedModifier: ViewModifier { + @Binding var isPresented: Bool + @ViewBuilder var panelContent: PanelContent + + func body(content: Content) -> some View { + content + .popover(isPresented: $isPresented) { + AdaptativeView { + panelContent + } + } + } +} + +struct AdaptativeView: View { + @Environment(\.isCompactWindow) private var isCompactWindow + @ViewBuilder var panelContent: Content + + var body: some View { + if isCompactWindow { + if #available(iOS 16.0, *) { + panelContent.modifier(SelfSizingPanelViewModifier()) + } else { + panelContent.modifier(SelfSizingPanelBackportViewModifier()) + } + } else { + panelContent + .padding() + .frame(idealWidth: 400) + } + } +} diff --git a/Mail/Views/Bottom sheets/RestoreEmailsView.swift b/Mail/Views/Bottom sheets/RestoreEmailsView.swift index 193985dce..000d4118c 100644 --- a/Mail/Views/Bottom sheets/RestoreEmailsView.swift +++ b/Mail/Views/Bottom sheets/RestoreEmailsView.swift @@ -38,17 +38,10 @@ struct RestoreEmailsView: View { var body: some View { VStack(alignment: .leading, spacing: 0) { - if platformDetector.isMac || UIDevice.current.systemName == "iPadOS" { - HeaderCloseButtonView(title: MailResourcesStrings.Localizable.restoreEmailsTitle) { - dismiss() - } - .padding(.horizontal, UIPadding.small) - } else { - Text(MailResourcesStrings.Localizable.restoreEmailsTitle) - .textStyle(.bodyMedium) - .padding(.bottom, 16) - .padding(.horizontal, UIPadding.bottomSheetHorizontal) - } + Text(MailResourcesStrings.Localizable.restoreEmailsTitle) + .textStyle(.bodyMedium) + .padding(.bottom, 16) + .padding(.horizontal, UIPadding.bottomSheetHorizontal) VStack(alignment: .leading, spacing: 0) { Text(MailResourcesStrings.Localizable.restoreEmailsText) diff --git a/Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift b/Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift index 45214f2e8..fafcdf7fc 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) { + .adaptivePanel(isPresented: $isShowingRestoreMails) { RestoreEmailsView() } } From f21c634ca7b36f9303066ffb324a1f9cf1760d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charle=CC=80ne=20Hoareau?= Date: Wed, 10 Apr 2024 11:21:58 +0200 Subject: [PATCH 3/6] fix: Remove useless Vstack --- .../Bottom sheets/RestoreEmailsView.swift | 60 +++++++++---------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/Mail/Views/Bottom sheets/RestoreEmailsView.swift b/Mail/Views/Bottom sheets/RestoreEmailsView.swift index 000d4118c..53f98e585 100644 --- a/Mail/Views/Bottom sheets/RestoreEmailsView.swift +++ b/Mail/Views/Bottom sheets/RestoreEmailsView.swift @@ -26,55 +26,49 @@ import SwiftUI struct RestoreEmailsView: View { @EnvironmentObject var mailboxManager: MailboxManager - @Environment(\.dismiss) private var dismiss - @State private var selectedDate = "" @State private var availableDates = [String]() @State private var pickerNoSelectionText = MailResourcesStrings.Localizable.loadingText @LazyInjectService private var matomo: MatomoUtils @LazyInjectService private var snackbarPresenter: SnackBarPresentable - @LazyInjectService private var platformDetector: PlatformDetectable var body: some View { VStack(alignment: .leading, spacing: 0) { Text(MailResourcesStrings.Localizable.restoreEmailsTitle) .textStyle(.bodyMedium) .padding(.bottom, 16) - .padding(.horizontal, UIPadding.bottomSheetHorizontal) - - VStack(alignment: .leading, spacing: 0) { - Text(MailResourcesStrings.Localizable.restoreEmailsText) - .textStyle(.bodySecondary) - .padding(.bottom, 10) - - LargePicker(title: MailResourcesStrings.Localizable.restoreEmailsBackupDate, - noSelectionText: pickerNoSelectionText, - selection: $selectedDate, - items: availableDates.map(mapDates)) - .padding(.bottom, 24) - .onChange(of: selectedDate) { _ in - matomo.track(eventWithCategory: .restoreEmailsBottomSheet, action: .input, name: "selectDate") - } - ModalButtonsView(primaryButtonTitle: MailResourcesStrings.Localizable.buttonConfirmRestoreEmails, - secondaryButtonTitle: nil, - primaryButtonEnabled: !availableDates.isEmpty, - primaryButtonAction: restoreEmails) - } - .padding(.horizontal, UIPadding.bottomSheetHorizontal) - .task { - await tryOrDisplayError { - let backupsList = try await mailboxManager.apiFetcher.listBackups(mailbox: mailboxManager.mailbox).backups - withAnimation { - availableDates = backupsList - selectedDate = backupsList.last ?? "" - pickerNoSelectionText = MailResourcesStrings.Localizable.pickerNoSelection + Text(MailResourcesStrings.Localizable.restoreEmailsText) + .textStyle(.bodySecondary) + .padding(.bottom, 10) + + LargePicker(title: MailResourcesStrings.Localizable.restoreEmailsBackupDate, + noSelectionText: pickerNoSelectionText, + selection: $selectedDate, + items: availableDates.map(mapDates)) + .padding(.bottom, 24) + .onChange(of: selectedDate) { _ in + matomo.track(eventWithCategory: .restoreEmailsBottomSheet, action: .input, name: "selectDate") + } + + ModalButtonsView(primaryButtonTitle: MailResourcesStrings.Localizable.buttonConfirmRestoreEmails, + secondaryButtonTitle: nil, + primaryButtonEnabled: !availableDates.isEmpty, + primaryButtonAction: restoreEmails) + .task { + await tryOrDisplayError { + let backupsList = try await mailboxManager.apiFetcher.listBackups(mailbox: mailboxManager.mailbox).backups + withAnimation { + availableDates = backupsList + selectedDate = backupsList.last ?? "" + pickerNoSelectionText = MailResourcesStrings.Localizable.pickerNoSelection + } } } - } - .matomoView(view: [MatomoUtils.View.bottomSheet.displayName, "RestoreEmailsView"]) + .matomoView(view: [MatomoUtils.View.bottomSheet.displayName, "RestoreEmailsView"]) } + .padding(.horizontal, UIPadding.bottomSheetHorizontal) } private func restoreEmails() async { From 2ede727763ccad5619c6f1af1a0d12e0937fcec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charle=CC=80ne=20Hoareau?= Date: Wed, 10 Apr 2024 14:02:52 +0200 Subject: [PATCH 4/6] chore: Move task and Matomo --- .../Bottom sheets/RestoreEmailsView.swift | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Mail/Views/Bottom sheets/RestoreEmailsView.swift b/Mail/Views/Bottom sheets/RestoreEmailsView.swift index 53f98e585..a499db776 100644 --- a/Mail/Views/Bottom sheets/RestoreEmailsView.swift +++ b/Mail/Views/Bottom sheets/RestoreEmailsView.swift @@ -56,19 +56,19 @@ struct RestoreEmailsView: View { secondaryButtonTitle: nil, primaryButtonEnabled: !availableDates.isEmpty, primaryButtonAction: restoreEmails) - .task { - await tryOrDisplayError { - let backupsList = try await mailboxManager.apiFetcher.listBackups(mailbox: mailboxManager.mailbox).backups - withAnimation { - availableDates = backupsList - selectedDate = backupsList.last ?? "" - pickerNoSelectionText = MailResourcesStrings.Localizable.pickerNoSelection - } - } - } - .matomoView(view: [MatomoUtils.View.bottomSheet.displayName, "RestoreEmailsView"]) } .padding(.horizontal, UIPadding.bottomSheetHorizontal) + .task { + await tryOrDisplayError { + let backupsList = try await mailboxManager.apiFetcher.listBackups(mailbox: mailboxManager.mailbox).backups + withAnimation { + availableDates = backupsList + selectedDate = backupsList.last ?? "" + pickerNoSelectionText = MailResourcesStrings.Localizable.pickerNoSelection + } + } + } + .matomoView(view: [MatomoUtils.View.bottomSheet.displayName, "RestoreEmailsView"]) } private func restoreEmails() async { From f94b31036b7b51081941d09da1a4d13a71d25a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charle=CC=80ne=20Hoareau?= Date: Wed, 10 Apr 2024 16:40:19 +0200 Subject: [PATCH 5/6] feat: Add sheetOrAlertPanel --- Mail/Utils/AdaptivePanelViewModifier.swift | 56 ++++----------- Mail/Utils/SheetOrAlertPanel.swift | 52 ++++++++++++++ .../Actions/HeaderCloseButtonView.swift | 1 - .../Actions/ReportJunkView.swift | 1 + .../Bottom sheets/RestoreEmailsView.swift | 70 +++++++++++-------- .../Items/MenuDrawerItemsListView.swift | 2 +- 6 files changed, 109 insertions(+), 73 deletions(-) create mode 100644 Mail/Utils/SheetOrAlertPanel.swift diff --git a/Mail/Utils/AdaptivePanelViewModifier.swift b/Mail/Utils/AdaptivePanelViewModifier.swift index 1c11e2fd4..e6e87432f 100644 --- a/Mail/Utils/AdaptivePanelViewModifier.swift +++ b/Mail/Utils/AdaptivePanelViewModifier.swift @@ -21,58 +21,30 @@ import SwiftUI extension View { func adaptivePanel(item: Binding, @ViewBuilder content: @escaping (Item) -> Content) -> some View { - return modifier(AdaptivePanelViewItemModifier(item: item, panelContent: content)) - } - - func adaptivePanel(isPresented: Binding, - @ViewBuilder content: @escaping () -> - Content) -> some View { - return modifier(AdaptivePanelViewIsPresentedModifier(isPresented: isPresented, panelContent: content)) + return modifier(AdaptivePanelViewModifier(item: item, panelContent: content)) } } -struct AdaptivePanelViewItemModifier: ViewModifier { +struct AdaptivePanelViewModifier: ViewModifier { + @Environment(\.isCompactWindow) private var isCompactWindow + @Binding var item: Item? @ViewBuilder var panelContent: (Item) -> PanelContent + func body(content: Content) -> some View { content .popover(item: $item) { item in - AdaptativeView { + if isCompactWindow { + if #available(iOS 16.0, *) { + panelContent(item).modifier(SelfSizingPanelViewModifier()) + } else { + panelContent(item).modifier(SelfSizingPanelBackportViewModifier()) + } + } else { panelContent(item) + .padding() + .frame(idealWidth: 400) } } } } - -struct AdaptivePanelViewIsPresentedModifier: ViewModifier { - @Binding var isPresented: Bool - @ViewBuilder var panelContent: PanelContent - - func body(content: Content) -> some View { - content - .popover(isPresented: $isPresented) { - AdaptativeView { - panelContent - } - } - } -} - -struct AdaptativeView: View { - @Environment(\.isCompactWindow) private var isCompactWindow - @ViewBuilder var panelContent: Content - - var body: some View { - if isCompactWindow { - if #available(iOS 16.0, *) { - panelContent.modifier(SelfSizingPanelViewModifier()) - } else { - panelContent.modifier(SelfSizingPanelBackportViewModifier()) - } - } else { - panelContent - .padding() - .frame(idealWidth: 400) - } - } -} 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 a499db776..ed298e132 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 @@ -35,40 +38,49 @@ struct RestoreEmailsView: View { var body: some View { VStack(alignment: .leading, spacing: 0) { - Text(MailResourcesStrings.Localizable.restoreEmailsTitle) - .textStyle(.bodyMedium) - .padding(.bottom, 16) - - Text(MailResourcesStrings.Localizable.restoreEmailsText) - .textStyle(.bodySecondary) - .padding(.bottom, 10) - - LargePicker(title: MailResourcesStrings.Localizable.restoreEmailsBackupDate, - noSelectionText: pickerNoSelectionText, - selection: $selectedDate, - items: availableDates.map(mapDates)) - .padding(.bottom, 24) - .onChange(of: selectedDate) { _ in - matomo.track(eventWithCategory: .restoreEmailsBottomSheet, action: .input, name: "selectDate") + if !isCompactWindow { + HeaderCloseButtonView(title: MailResourcesStrings.Localizable.restoreEmailsTitle) { + dismiss() } + } else { + Text(MailResourcesStrings.Localizable.restoreEmailsTitle) + .textStyle(.bodyMedium) + .padding(.bottom, 16) + .padding(.horizontal, UIPadding.bottomSheetHorizontal) + } - ModalButtonsView(primaryButtonTitle: MailResourcesStrings.Localizable.buttonConfirmRestoreEmails, - secondaryButtonTitle: nil, - primaryButtonEnabled: !availableDates.isEmpty, - primaryButtonAction: restoreEmails) - } - .padding(.horizontal, UIPadding.bottomSheetHorizontal) - .task { - await tryOrDisplayError { - let backupsList = try await mailboxManager.apiFetcher.listBackups(mailbox: mailboxManager.mailbox).backups - withAnimation { - availableDates = backupsList - selectedDate = backupsList.last ?? "" - pickerNoSelectionText = MailResourcesStrings.Localizable.pickerNoSelection + VStack(alignment: .leading, spacing: 0) { + Text(MailResourcesStrings.Localizable.restoreEmailsText) + .textStyle(.bodySecondary) + .padding(.bottom, 10) + + LargePicker(title: MailResourcesStrings.Localizable.restoreEmailsBackupDate, + noSelectionText: pickerNoSelectionText, + selection: $selectedDate, + items: availableDates.map(mapDates)) + .padding(.bottom, 24) + .onChange(of: selectedDate) { _ in + matomo.track(eventWithCategory: .restoreEmailsBottomSheet, action: .input, name: "selectDate") + } + + ModalButtonsView(primaryButtonTitle: MailResourcesStrings.Localizable.buttonConfirmRestoreEmails, + secondaryButtonTitle: nil, + primaryButtonEnabled: !availableDates.isEmpty, + primaryButtonAction: restoreEmails) + } + .padding(.horizontal, isCompactWindow ? UIPadding.bottomSheetHorizontal : 0) + .task { + await tryOrDisplayError { + let backupsList = try await mailboxManager.apiFetcher.listBackups(mailbox: mailboxManager.mailbox).backups + withAnimation { + availableDates = backupsList + selectedDate = backupsList.last ?? "" + pickerNoSelectionText = MailResourcesStrings.Localizable.pickerNoSelection + } } } + .matomoView(view: [MatomoUtils.View.bottomSheet.displayName, "RestoreEmailsView"]) } - .matomoView(view: [MatomoUtils.View.bottomSheet.displayName, "RestoreEmailsView"]) } private func restoreEmails() async { diff --git a/Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift b/Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift index fafcdf7fc..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 } - .adaptivePanel(isPresented: $isShowingRestoreMails) { + .sheetOrAlertPanel(isPresented: $isShowingRestoreMails) { RestoreEmailsView() } } From 05bc0a7c6094236b97ec3e94c60a8409adefe8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charle=CC=80ne=20Hoareau?= Date: Thu, 11 Apr 2024 09:34:14 +0200 Subject: [PATCH 6/6] chore: Remove header and add cancel button --- .../Bottom sheets/RestoreEmailsView.swift | 67 ++++++++----------- 1 file changed, 29 insertions(+), 38 deletions(-) diff --git a/Mail/Views/Bottom sheets/RestoreEmailsView.swift b/Mail/Views/Bottom sheets/RestoreEmailsView.swift index ed298e132..660c30fa6 100644 --- a/Mail/Views/Bottom sheets/RestoreEmailsView.swift +++ b/Mail/Views/Bottom sheets/RestoreEmailsView.swift @@ -38,49 +38,40 @@ struct RestoreEmailsView: View { var body: some View { VStack(alignment: .leading, spacing: 0) { - if !isCompactWindow { - HeaderCloseButtonView(title: MailResourcesStrings.Localizable.restoreEmailsTitle) { - dismiss() + Text(MailResourcesStrings.Localizable.restoreEmailsTitle) + .textStyle(.bodyMedium) + .padding(.bottom, value: .regular) + + Text(MailResourcesStrings.Localizable.restoreEmailsText) + .textStyle(.bodySecondary) + .padding(.bottom, value: .small) + + LargePicker(title: MailResourcesStrings.Localizable.restoreEmailsBackupDate, + noSelectionText: pickerNoSelectionText, + selection: $selectedDate, + items: availableDates.map(mapDates)) + .padding(.bottom, value: .medium) + .onChange(of: selectedDate) { _ in + matomo.track(eventWithCategory: .restoreEmailsBottomSheet, action: .input, name: "selectDate") } - } else { - Text(MailResourcesStrings.Localizable.restoreEmailsTitle) - .textStyle(.bodyMedium) - .padding(.bottom, 16) - .padding(.horizontal, UIPadding.bottomSheetHorizontal) - } - VStack(alignment: .leading, spacing: 0) { - Text(MailResourcesStrings.Localizable.restoreEmailsText) - .textStyle(.bodySecondary) - .padding(.bottom, 10) - - LargePicker(title: MailResourcesStrings.Localizable.restoreEmailsBackupDate, - noSelectionText: pickerNoSelectionText, - selection: $selectedDate, - items: availableDates.map(mapDates)) - .padding(.bottom, 24) - .onChange(of: selectedDate) { _ in - matomo.track(eventWithCategory: .restoreEmailsBottomSheet, action: .input, name: "selectDate") - } - - ModalButtonsView(primaryButtonTitle: MailResourcesStrings.Localizable.buttonConfirmRestoreEmails, - secondaryButtonTitle: nil, - primaryButtonEnabled: !availableDates.isEmpty, - primaryButtonAction: restoreEmails) - } - .padding(.horizontal, isCompactWindow ? UIPadding.bottomSheetHorizontal : 0) - .task { - await tryOrDisplayError { - let backupsList = try await mailboxManager.apiFetcher.listBackups(mailbox: mailboxManager.mailbox).backups - withAnimation { - availableDates = backupsList - selectedDate = backupsList.last ?? "" - pickerNoSelectionText = MailResourcesStrings.Localizable.pickerNoSelection - } + ModalButtonsView(primaryButtonTitle: MailResourcesStrings.Localizable.buttonConfirmRestoreEmails, + primaryButtonEnabled: !availableDates.isEmpty, + primaryButtonAction: restoreEmails, + secondaryButtonAction: dismiss.callAsFunction) + } + .padding(.horizontal, isCompactWindow ? UIPadding.bottomSheetHorizontal : 0) + .task { + await tryOrDisplayError { + let backupsList = try await mailboxManager.apiFetcher.listBackups(mailbox: mailboxManager.mailbox).backups + withAnimation { + availableDates = backupsList + selectedDate = backupsList.last ?? "" + pickerNoSelectionText = MailResourcesStrings.Localizable.pickerNoSelection } } - .matomoView(view: [MatomoUtils.View.bottomSheet.displayName, "RestoreEmailsView"]) } + .matomoView(view: [MatomoUtils.View.bottomSheet.displayName, "RestoreEmailsView"]) } private func restoreEmails() async {