Skip to content

Commit

Permalink
Merge pull request #1254 from Infomaniak/fix-thread-cell
Browse files Browse the repository at this point in the history
fix(ThreadCell): Recipient names fill the available place
  • Loading branch information
PhilippeWeidmann committed Jan 31, 2024
2 parents 93cf0a6 + 4f6176a commit 6d8d9f4
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,29 +147,15 @@ struct ThreadCell: View {
.accessibilityLabel(additionalAccessibilityLabel)
.accessibilityHidden(additionalAccessibilityLabel.isEmpty)

Group {
if density == .large {
ZStack {
AvatarView(
mailboxManager: mailboxManager,
contactConfiguration: dataHolder.contactConfiguration(contextMailboxManager: mailboxManager),
size: 40
)
.opacity(isSelected ? 0 : 1)
.onTapGesture {
avatarTapped?()
}
CheckboxView(isSelected: isSelected, density: density, accentColor: accentColor)
.opacity(isSelected ? 1 : 0)
}
.accessibility(hidden: true)
.animation(nil, value: isSelected)
} else if isMultipleSelectionEnabled {
CheckboxView(isSelected: isSelected, density: density, accentColor: accentColor)
.opacity(shouldDisplayCheckbox ? 1 : 0)
.animation(.default.speed(1.5), value: shouldDisplayCheckbox)
}
}
ThreadCellAvatarCheckboxView(
accentColor: accentColor,
density: density,
isSelected: isSelected,
isMultipleSelectionEnabled: isMultipleSelectionEnabled,
shouldDisplayCheckbox: shouldDisplayCheckbox,
contactConfiguration: dataHolder.contactConfiguration(contextMailboxManager: mailboxManager),
avatarTapped: avatarTapped
)
.padding(.trailing, value: .verySmall)

VStack(alignment: .leading, spacing: UIPadding.verySmall) {
Expand Down Expand Up @@ -198,18 +184,20 @@ struct ThreadCell: View {
.padding(.vertical, density.cellVerticalPadding)
.clipped()
.accessibilityElement(children: .combine)
.onChange(of: isMultipleSelectionEnabled) { isEnabled in
guard density != .large else { return }

withAnimation {
if isEnabled {
// We should wait a bit before showing the checkbox
DispatchQueue.main.asyncAfter(deadline: .now() + UIConstants.checkboxAppearDelay) {
shouldDisplayCheckbox = true
}
} else {
shouldDisplayCheckbox = false
.onChange(of: isMultipleSelectionEnabled, perform: animateCheckbox)
}

private func animateCheckbox(_ isEnabled: Bool) {
guard density != .large else { return }

withAnimation {
if isEnabled {
// We should wait a bit before showing the checkbox
DispatchQueue.main.asyncAfter(deadline: .now() + UIConstants.checkboxAppearDelay) {
shouldDisplayCheckbox = true
}
} else {
shouldDisplayCheckbox = false
}
}
}
Expand Down
66 changes: 66 additions & 0 deletions Mail/Components/ThreadCell/ThreadCellAvatarCheckboxView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Infomaniak Mail - iOS App
Copyright (C) 2022 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

struct ThreadCellAvatarCheckboxView: View {
@EnvironmentObject private var mailboxManager: MailboxManager

let accentColor: AccentColor
let density: ThreadDensity
let isSelected: Bool
let isMultipleSelectionEnabled: Bool
let shouldDisplayCheckbox: Bool
let contactConfiguration: ContactConfiguration
let avatarTapped: (() -> Void)?

var body: some View {
Group {
if density == .large {
ZStack {
AvatarView(mailboxManager: mailboxManager, contactConfiguration: contactConfiguration, size: 40)
.opacity(isSelected ? 0 : 1)
.onTapGesture {
avatarTapped?()
}
CheckboxView(isSelected: isSelected, density: density, accentColor: accentColor)
.opacity(isSelected ? 1 : 0)
}
.accessibility(hidden: true)
.animation(nil, value: isSelected)
} else if isMultipleSelectionEnabled {
CheckboxView(isSelected: isSelected, density: density, accentColor: accentColor)
.opacity(shouldDisplayCheckbox ? 1 : 0)
.animation(.default.speed(1.5), value: shouldDisplayCheckbox)
}
}
}
}

#Preview {
ThreadCellAvatarCheckboxView(
accentColor: .pink,
density: .large,
isSelected: false,
isMultipleSelectionEnabled: false,
shouldDisplayCheckbox: true,
contactConfiguration: .emptyContact,
avatarTapped: nil
)
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,29 @@ struct ThreadCellHeaderView: View, Equatable {

var body: some View {
HStack(spacing: UIPadding.small) {
if showDraftPrefix {
Text("\(MailResourcesStrings.Localizable.draftPrefix)")
.textStyle(.bodyMediumError)
HStack(spacing: UIPadding.small) {
if showDraftPrefix {
Text("\(MailResourcesStrings.Localizable.draftPrefix)")
.textStyle(.bodyMediumError)
.lineLimit(1)
.layoutPriority(1)
}

Text(recipientsTitle)
.textStyle(.bodyMedium)
.lineLimit(1)
.layoutPriority(1)
}

Text(recipientsTitle)
.textStyle(.bodyMedium)
.lineLimit(1)

if messageCount > 1 {
ThreadCountIndicatorView(messagesCount: messageCount, hasUnseenMessages: prominentMessageCount)
.accessibilityHidden(true)
if messageCount > 1 {
ThreadCountIndicatorView(messagesCount: messageCount, hasUnseenMessages: prominentMessageCount)
.accessibilityHidden(true)
}
}
.frame(maxWidth: .infinity, alignment: .leading)

Text(formattedDate)
.textStyle(.bodySmallSecondary)
.lineLimit(1)
.frame(maxWidth: .infinity, alignment: .trailing)
.layoutPriority(1)
.accessibilityHidden(true)
}
}
Expand Down
File renamed without changes.

0 comments on commit 6d8d9f4

Please sign in to comment.