Skip to content

Commit

Permalink
chore: Adapt HelpView
Browse files Browse the repository at this point in the history
  • Loading branch information
charlella committed May 7, 2024
1 parent b808546 commit b1ecc16
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 54 deletions.
19 changes: 12 additions & 7 deletions Mail/Views/Menu Drawer/Actions/HelpView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions Mail/Views/Thread List/ThreadListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void, Never>?
@State private var isRefreshing = false
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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"])
}
Expand Down
9 changes: 5 additions & 4 deletions Mail/Views/Thread List/UpdateVersionAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)?

Expand Down Expand Up @@ -56,11 +57,11 @@ struct UpdateVersionAlertView: View {
matomo.track(eventWithCategory: .updateVersion, name: "later")
onLaterPressed?()
withAnimation {
updateVersionViewDismissed = true
hasDismissedUpdateVersionView = true
}
}
}

#Preview {
UpdateVersionAlertView {}
UpdateVersionAlertView()
}
38 changes: 17 additions & 21 deletions Mail/Views/Thread List/UpdateVersionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion MailCore/Models/Settings/DefaultPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion MailCore/Utils/MailUserDefaults+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
20 changes: 4 additions & 16 deletions MailCoreUI/Components/InformationBlockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,29 +34,29 @@ 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]
}

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
}

if let dismissHandler {
CloseButton(size: .regular, dismissHandler: dismissHandler)
.tint(MailResourcesAsset.textSecondaryColor.swiftUIColor)
.alignmentGuide(.blockAlignment) { d in
.alignmentGuide(.iconAndMultilineTextAlignment) { d in
d[VerticalAlignment.center]
}
}
Expand Down
31 changes: 31 additions & 0 deletions MailCoreUI/Utils/IconAndMultilineTextAlignment.swift
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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)
}

0 comments on commit b1ecc16

Please sign in to comment.