Skip to content

Commit

Permalink
refactor: Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinperignon committed Jun 6, 2023
1 parent a09af20 commit 5c43708
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 110 deletions.
1 change: 0 additions & 1 deletion Mail/Components/BottomBarView.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//
/*
Infomaniak Mail - iOS App
Copyright (C) 2022 Infomaniak Network SA
Expand Down
24 changes: 1 addition & 23 deletions Mail/Components/ToolbarButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,8 @@ import MailCore
import MailResources
import SwiftUI

// MARK: - Environment

struct SmallToolbarKey: EnvironmentKey {
static var defaultValue = false
}

extension EnvironmentValues {
var smallToolbar: Bool {
get { self[SmallToolbarKey.self] }
set { self[SmallToolbarKey.self] = newValue }
}
}

extension View {
func smallToolbar(_ isSmall: Bool) -> some View {
environment(\.smallToolbar, isSmall)
}
}

// MARK: - View

struct ToolbarButtonLabel: View {
@Environment(\.verticalSizeClass) private var sizeClass
@Environment(\.smallToolbar) private var smallToolbar

let text: String
let icon: Image
Expand All @@ -59,7 +37,7 @@ struct ToolbarButtonLabel: View {
.resizable()
.frame(width: 24, height: 24)
}
.dynamicLabelStyle(sizeClass: sizeClass ?? .regular, smallToolbar: smallToolbar)
.dynamicLabelStyle(sizeClass: sizeClass ?? .regular)
}
}

Expand Down
31 changes: 0 additions & 31 deletions Mail/Views/Thread List/ThreadListModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,37 +130,6 @@ struct ThreadListToolbar: ViewModifier {
.accessibilityLabel(MailResourcesStrings.Localizable.contentDescriptionUserAvatar)
}
}

/*ToolbarItemGroup(placement: .bottomBar) {
if multipleSelectionViewModel.isEnabled {
HStack(spacing: 0) {
ForEach(multipleSelectionViewModel.toolbarActions) { action in
ToolbarButton(
text: action.shortTitle ?? action.title,
icon: action.icon
) {
Task {
await tryOrDisplayError {
try await multipleSelectionViewModel.didTap(
action: action,
flushAlert: $flushAlert
)
}
}
}
.disabled(action == .archive && splitViewManager.selectedFolder?.role == .archive)
}
ToolbarButton(
text: MailResourcesStrings.Localizable.buttonMore,
icon: MailResourcesAsset.plusActions.swiftUIImage
) {
multipleSelectionActionsTarget = .threads(Array(multipleSelectionViewModel.selectedItems), true)
}
}
.disabled(multipleSelectionViewModel.selectedItems.isEmpty)
}
}*/
}
.bottomBar(isHidden: !multipleSelectionViewModel.isEnabled) {
HStack(spacing: 0) {
Expand Down
55 changes: 2 additions & 53 deletions Mail/Views/Thread/ThreadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ private struct ScrollOffsetPreferenceKey: PreferenceKey {
}
}

private struct ToolbarWidthPreferenceKey: PreferenceKey {
static var defaultValue: CGFloat = .zero

static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = nextValue()
}
}

struct ThreadView: View {
@LazyInjectService private var matomo: MatomoUtils

Expand All @@ -54,8 +46,6 @@ struct ThreadView: View {
@State private var displayNavigationTitle = false
@State private var replyOrReplyAllMessage: Message?

@State private var smallToolbar = true

@ObservedRealmObject var thread: Thread

private let toolbarActions: [Action] = [.reply, .forward, .archive, .delete]
Expand Down Expand Up @@ -85,20 +75,9 @@ struct ThreadView: View {
}
.background(MailResourcesAsset.backgroundColor.swiftUIColor)
.coordinateSpace(name: "scrollView")
.overlay {
GeometryReader { proxy in
Color.clear.preference(
key: ToolbarWidthPreferenceKey.self,
value: proxy.size.width
)
}
}
.onPreferenceChange(ScrollOffsetPreferenceKey.self) { offset in
displayNavigationTitle = offset.y < -85
}
.onPreferenceChange(ToolbarWidthPreferenceKey.self) { width in
smallToolbar = width < UIConstants.toolbarMinimumWidth
}
.task {
if thread.hasUnseenMessages {
try? await mailboxManager.toggleRead(threads: [thread])
Expand All @@ -121,36 +100,6 @@ struct ThreadView: View {
.foregroundColor(thread.flagged ? MailResourcesAsset.yellowColor.swiftUIColor : .accentColor)
}
}
/*ToolbarItemGroup(placement: .bottomBar) {
Group {
ForEach(toolbarActions) { action in
if action == .reply {
ToolbarButton(text: action.title, icon: action.icon) {
didTap(action: action)
}
.adaptivePanel(item: $replyOrReplyAllMessage) { message in
ReplyActionsView(
mailboxManager: mailboxManager,
message: message,
messageReply: $navigationStore.messageReply
)
}
} else {
ToolbarButton(text: action.title, icon: action.icon) {
didTap(action: action)
}
.disabled(action == .archive && thread.folder?.role == .archive)
}
Spacer()
}
ActionsPanelButton(threads: [thread]) {
ToolbarButtonLabel(text: MailResourcesStrings.Localizable.buttonMore,
icon: MailResourcesAsset.plusActions.swiftUIImage)
}
}
.smallToolbar(smallToolbar)
}
*/
}
.bottomBar {
ForEach(toolbarActions) { action in
Expand Down Expand Up @@ -246,8 +195,8 @@ extension LabelStyle where Self == VerticalLabelStyle {

extension Label {
@ViewBuilder
func dynamicLabelStyle(sizeClass: UserInterfaceSizeClass, smallToolbar: Bool = false) -> some View {
if sizeClass == .compact || smallToolbar {
func dynamicLabelStyle(sizeClass: UserInterfaceSizeClass) -> some View {
if sizeClass == .compact {
labelStyle(.iconOnly)
} else {
labelStyle(.vertical)
Expand Down
2 changes: 0 additions & 2 deletions MailCore/UI/UIConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ public enum UIConstants {

public static let chipInsets = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8)

public static let toolbarMinimumWidth: CGFloat = 328

public static func isCompact(horizontalSizeClass: UserInterfaceSizeClass?, verticalSizeClass: UserInterfaceSizeClass?) -> Bool {
return horizontalSizeClass == .compact || verticalSizeClass == .compact
}
Expand Down

0 comments on commit 5c43708

Please sign in to comment.