From b1ecc168d96ccc9214656cfe204379e385172f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charle=CC=80ne=20Hoareau?= Date: Tue, 7 May 2024 08:18:25 +0200 Subject: [PATCH] chore: Adapt HelpView --- Mail/Views/Menu Drawer/Actions/HelpView.swift | 19 ++++++---- Mail/Views/Thread List/ThreadListView.swift | 9 +++-- .../Thread List/UpdateVersionAlertView.swift | 9 +++-- .../Views/Thread List/UpdateVersionView.swift | 38 +++++++++---------- .../Models/Settings/DefaultPreferences.swift | 2 +- .../Utils/MailUserDefaults+Extension.swift | 2 +- .../Components/InformationBlockView.swift | 20 ++-------- .../Utils/IconAndMultilineTextAlignment.swift | 31 +++++++++++++++ 8 files changed, 76 insertions(+), 54 deletions(-) create mode 100644 MailCoreUI/Utils/IconAndMultilineTextAlignment.swift diff --git a/Mail/Views/Menu Drawer/Actions/HelpView.swift b/Mail/Views/Menu Drawer/Actions/HelpView.swift index 6aba070227..14ecde19dd 100644 --- a/Mail/Views/Menu Drawer/Actions/HelpView.swift +++ b/Mail/Views/Menu Drawer/Actions/HelpView.swift @@ -23,7 +23,11 @@ import SwiftModalPresentation import SwiftUI struct HelpView: View { - private struct HelpAction: Hashable { + private struct HelpAction: Identifiable, Equatable { + var id: String { + return destination.absoluteString + } + let title: String let destination: URL let openUpdateVersionAlert: Bool @@ -34,25 +38,26 @@ struct HelpView: View { openUpdateVersionAlert: false ) static let chatbot = HelpAction( - title: MailResourcesStrings.Localizable.helpChatbot, destination: URLConstants.chatbot.url, + title: MailResourcesStrings.Localizable.helpChatbot, + destination: URLConstants.chatbot.url, openUpdateVersionAlert: true ) } @Environment(\.openURL) private var openURL - @ModalState(context: ContextKeys.help) private var isShowingUpdateVersionAlert = false + @ModalState(wrappedValue: nil, context: ContextKeys.help) private var updateVersionAlert: HelpAction? private let actions: [HelpAction] = [.faq, .chatbot] var body: some View { List { Section { - ForEach(actions, id: \.self) { action in + ForEach(actions) { action in VStack(alignment: .leading, spacing: 0) { Button { if action.openUpdateVersionAlert && Constants.canOSBeUpdated { - isShowingUpdateVersionAlert = true + updateVersionAlert = action } else { openURL(action.destination) } @@ -81,9 +86,9 @@ struct HelpView: View { .listStyle(.plain) .background(MailResourcesAsset.backgroundColor.swiftUIColor) .navigationBarTitle(MailResourcesStrings.Localizable.buttonHelp, displayMode: .inline) - .customAlert(isPresented: $isShowingUpdateVersionAlert) { + .customAlert(item: $updateVersionAlert) { action in UpdateVersionAlertView { - openURL(HelpAction.chatbot.destination) + openURL(action.destination) } } } diff --git a/Mail/Views/Thread List/ThreadListView.swift b/Mail/Views/Thread List/ThreadListView.swift index c293a3b6a5..e88feb9f0a 100644 --- a/Mail/Views/Thread List/ThreadListView.swift +++ b/Mail/Views/Thread List/ThreadListView.swift @@ -35,8 +35,9 @@ struct ThreadListView: View { @AppStorage(UserDefaults.shared.key(.threadDensity)) private var threadDensity = DefaultPreferences.threadDensity @AppStorage(UserDefaults.shared.key(.accentColor)) private var accentColor = DefaultPreferences.accentColor - @AppStorage(UserDefaults.shared.key(.updateVersionViewDismissed)) private var updateVersionViewDismissed = DefaultPreferences - .updateVersionViewDismissed + @AppStorage(UserDefaults.shared.key(.hasDismissedUpdateVersionView)) private var hasDismissedUpdateVersionView = + DefaultPreferences + .hasDismissedUpdateVersionView @State private var fetchingTask: Task? @State private var isRefreshing = false @@ -100,7 +101,7 @@ struct ThreadListView: View { ListVerticalInsetView(height: UIPadding.verySmall) } - if Constants.canOSBeUpdated && !updateVersionViewDismissed { + if Constants.canOSBeUpdated && !hasDismissedUpdateVersionView && viewModel.frozenFolder.role == .inbox { UpdateVersionView(isShowingUpdateAlert: $isShowingUpdateAlert) .threadListCellAppearance() } @@ -200,7 +201,7 @@ struct ThreadListView: View { FlushFolderAlertView(flushAlert: item, folder: viewModel.frozenFolder) } .customAlert(isPresented: $isShowingUpdateAlert) { - UpdateVersionAlertView {} + UpdateVersionAlertView() } .matomoView(view: [MatomoUtils.View.threadListView.displayName, "Main"]) } diff --git a/Mail/Views/Thread List/UpdateVersionAlertView.swift b/Mail/Views/Thread List/UpdateVersionAlertView.swift index 4c2c801b91..7e93f8a353 100644 --- a/Mail/Views/Thread List/UpdateVersionAlertView.swift +++ b/Mail/Views/Thread List/UpdateVersionAlertView.swift @@ -27,8 +27,9 @@ struct UpdateVersionAlertView: View { @Environment(\.openURL) private var openURL - @AppStorage(UserDefaults.shared.key(.updateVersionViewDismissed)) private var updateVersionViewDismissed = DefaultPreferences - .updateVersionViewDismissed + @AppStorage(UserDefaults.shared.key(.hasDismissedUpdateVersionView)) private var hasDismissedUpdateVersionView = + DefaultPreferences + .hasDismissedUpdateVersionView var onLaterPressed: (() -> Void)? @@ -56,11 +57,11 @@ struct UpdateVersionAlertView: View { matomo.track(eventWithCategory: .updateVersion, name: "later") onLaterPressed?() withAnimation { - updateVersionViewDismissed = true + hasDismissedUpdateVersionView = true } } } #Preview { - UpdateVersionAlertView {} + UpdateVersionAlertView() } diff --git a/Mail/Views/Thread List/UpdateVersionView.swift b/Mail/Views/Thread List/UpdateVersionView.swift index d5a9f0379e..cb6dd06bf5 100644 --- a/Mail/Views/Thread List/UpdateVersionView.swift +++ b/Mail/Views/Thread List/UpdateVersionView.swift @@ -28,38 +28,34 @@ struct UpdateVersionView: View { @Binding var isShowingUpdateAlert: Bool var body: some View { - VStack(alignment: .leading, spacing: UIPadding.small) { - HStack(alignment: .blockAlignment, spacing: UIPadding.small) { + VStack(alignment: .leading, spacing: 0) { + HStack(alignment: .iconAndMultilineTextAlignment, spacing: UIPadding.small) { IKIcon(MailResourcesAsset.warning) .foregroundStyle(MailResourcesAsset.orangeColor) - .alignmentGuide(.blockAlignment) { d in + .alignmentGuide(.iconAndMultilineTextAlignment) { d in d[VerticalAlignment.center] } - VStack(alignment: .leading, spacing: UIPadding.small) { - Text(MailResourcesStrings.Localizable.updateVersionTitle) - .textStyle(.bodySmall) - .alignmentGuide(.blockAlignment) { d in - (d.height - (d[.lastTextBaseline] - d[.firstTextBaseline])) / 2 - } - - Button { - matomo.track(eventWithCategory: .updateVersion, name: "moreInfo") - isShowingUpdateAlert = true - } label: { - HStack(spacing: UIPadding.small) { - Text(MailResourcesStrings.Localizable.moreInfo) - .textStyle(.bodySmallAccent) - } - .buttonStyle(.ikLink(isInlined: false)) + Text(MailResourcesStrings.Localizable.updateVersionTitle) + .textStyle(.bodySmall) + .alignmentGuide(.iconAndMultilineTextAlignment) { d in + (d.height - (d[.lastTextBaseline] - d[.firstTextBaseline])) / 2 } - } - .frame(maxWidth: .infinity, alignment: .leading) } .padding(.top, value: .regular) .padding(.horizontal, value: .regular) .frame(maxWidth: .infinity, alignment: .leading) + Button { + matomo.track(eventWithCategory: .updateVersion, name: "moreInfo") + isShowingUpdateAlert = true + } label: { + Text(MailResourcesStrings.Localizable.moreInfo) + .textStyle(.bodySmallAccent) + } + .buttonStyle(.ikLink()) + .padding(.leading, value: .regular) + IKDivider(type: .full) } .frame(maxWidth: .infinity, alignment: .leading) diff --git a/MailCore/Models/Settings/DefaultPreferences.swift b/MailCore/Models/Settings/DefaultPreferences.swift index b40449c8cc..05961ee16c 100644 --- a/MailCore/Models/Settings/DefaultPreferences.swift +++ b/MailCore/Models/Settings/DefaultPreferences.swift @@ -40,7 +40,7 @@ public enum DefaultPreferences { public static let aiEngine = AIEngine.falcon public static let autoAdvance = UIDevice.current.userInterfaceIdiom == .pad ? AutoAdvance.followingThread : AutoAdvance .listOfThread - public static let updateVersionViewDismissed = false + public static let hasDismissedUpdateVersionView = false public static let matomoAuthorized = true public static let sentryAuthorized = true } diff --git a/MailCore/Utils/MailUserDefaults+Extension.swift b/MailCore/Utils/MailUserDefaults+Extension.swift index e023e5216f..6dcebca510 100644 --- a/MailCore/Utils/MailUserDefaults+Extension.swift +++ b/MailCore/Utils/MailUserDefaults+Extension.swift @@ -50,7 +50,7 @@ public extension UserDefaults.Keys { static let shouldPresentSetAsDefaultDiscovery = UserDefaults.Keys(rawValue: "shouldPresentSetAsDefaultDiscovery") static let aiEngine = UserDefaults.Keys(rawValue: "aiEngine") static let autoAdvance = UserDefaults.Keys(rawValue: "autoAdvance") - static let updateVersionViewDismissed = UserDefaults.Keys(rawValue: "updateVersionViewDismissed") + static let hasDismissedUpdateVersionView = UserDefaults.Keys(rawValue: "hasDismissedUpdateVersionView") static let matomoAuthorized = UserDefaults.Keys(rawValue: "matomoAuthorized") static let sentryAuthorized = UserDefaults.Keys(rawValue: "sentryAuthorized") } diff --git a/MailCoreUI/Components/InformationBlockView.swift b/MailCoreUI/Components/InformationBlockView.swift index 47548357ac..2604cc0e57 100644 --- a/MailCoreUI/Components/InformationBlockView.swift +++ b/MailCoreUI/Components/InformationBlockView.swift @@ -20,18 +20,6 @@ import MailCore import MailResources import SwiftUI -public extension VerticalAlignment { - /// Alignment ID used for the icon and the text - /// The icon must be vertically centered with the first line of the text - enum InformationBlockAlignment: AlignmentID { - public static func defaultValue(in context: ViewDimensions) -> CGFloat { - return context[.top] - } - } - - static let blockAlignment = VerticalAlignment(InformationBlockAlignment.self) -} - public struct InformationBlockView: View { let icon: Image let message: String @@ -46,13 +34,13 @@ public struct InformationBlockView: View { } public var body: some View { - HStack(alignment: .blockAlignment, spacing: UIPadding.intermediate) { + HStack(alignment: .iconAndMultilineTextAlignment, spacing: UIPadding.intermediate) { icon .resizable() .scaledToFit() .frame(width: 16, height: 16) .foregroundStyle(iconColor ?? .clear) - .alignmentGuide(.blockAlignment) { d in + .alignmentGuide(.iconAndMultilineTextAlignment) { d in // Center of the view is on the informationBlockAlignment guide d[VerticalAlignment.center] } @@ -60,7 +48,7 @@ public struct InformationBlockView: View { Text(message) .textStyle(.body) .frame(maxWidth: .infinity, alignment: .leading) - .alignmentGuide(.blockAlignment) { d in + .alignmentGuide(.iconAndMultilineTextAlignment) { d in // Center of the first line is on the informationBlockAlignment guide (d.height - (d[.lastTextBaseline] - d[.firstTextBaseline])) / 2 } @@ -68,7 +56,7 @@ public struct InformationBlockView: View { if let dismissHandler { CloseButton(size: .regular, dismissHandler: dismissHandler) .tint(MailResourcesAsset.textSecondaryColor.swiftUIColor) - .alignmentGuide(.blockAlignment) { d in + .alignmentGuide(.iconAndMultilineTextAlignment) { d in d[VerticalAlignment.center] } } diff --git a/MailCoreUI/Utils/IconAndMultilineTextAlignment.swift b/MailCoreUI/Utils/IconAndMultilineTextAlignment.swift new file mode 100644 index 0000000000..66f508205d --- /dev/null +++ b/MailCoreUI/Utils/IconAndMultilineTextAlignment.swift @@ -0,0 +1,31 @@ +/* + 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 SwiftUI + +public extension VerticalAlignment { + /// Alignment ID used for the icon and the text + /// The icon must be vertically centered with the first line of the text + enum IconAndMultilineTextAlignment: AlignmentID { + public static func defaultValue(in context: ViewDimensions) -> CGFloat { + return context[.top] + } + } + + static let iconAndMultilineTextAlignment = VerticalAlignment(IconAndMultilineTextAlignment.self) +}