Skip to content

Commit

Permalink
chore: Add close button to RestoreEmailsView (#1381)
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinperignon authored Apr 11, 2024
2 parents 18ec4d0 + 05bc0a7 commit 6009ba2
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 9 deletions.
1 change: 1 addition & 0 deletions Mail/Utils/AdaptivePanelViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct AdaptivePanelViewModifier<Item: Identifiable, PanelContent: View>: ViewMo

@Binding var item: Item?
@ViewBuilder var panelContent: (Item) -> PanelContent

func body(content: Content) -> some View {
content
.popover(item: $item) { item in
Expand Down
52 changes: 52 additions & 0 deletions Mail/Utils/SheetOrAlertPanel.swift
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

import MailCore
import SwiftUI
import SwiftUIBackports

extension View {
func sheetOrAlertPanel<ModalContent: View>(isPresented: Binding<Bool>,
@ViewBuilder modalContent: @escaping () -> ModalContent) -> some View {
modifier(SheetOrAlertPanel(isPresented: isPresented, modalContent: modalContent))
}
}

struct SheetOrAlertPanel<ModalContent: View>: 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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions Mail/Views/Bottom sheets/Actions/ReportJunkView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct ReportJunkView: View {
HeaderCloseButtonView(title: MailResourcesStrings.Localizable.actionReportJunk) {
dismiss()
}
.padding(.horizontal, value: .regular)
}

ForEach(actions) { action in
Expand Down
17 changes: 10 additions & 7 deletions Mail/Views/Bottom sheets/RestoreEmailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Mail/Views/Menu Drawer/Items/MenuDrawerItemsListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct MenuDrawerItemsAdvancedListView: View {
) {
isShowingRestoreMails = true
}
.floatingPanel(isPresented: $isShowingRestoreMails) {
.sheetOrAlertPanel(isPresented: $isShowingRestoreMails) {
RestoreEmailsView()
}
}
Expand Down

0 comments on commit 6009ba2

Please sign in to comment.