From 012ffe3b7c16a31731f33b9b2674e941548fe6af Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Tue, 21 Nov 2023 13:16:20 +0100 Subject: [PATCH 1/2] fix: Preview ThreadCell --- Mail/Components/ThreadCell.swift | 18 ++++++++++++++---- Mail/Helpers/PreviewHelper.swift | 21 ++++++++++++++++++++- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Mail/Components/ThreadCell.swift b/Mail/Components/ThreadCell.swift index 61d078a45..5c1760d66 100644 --- a/Mail/Components/ThreadCell.swift +++ b/Mail/Components/ThreadCell.swift @@ -209,14 +209,24 @@ struct ThreadCell: View { } } -struct ThreadCell_Previews: PreviewProvider { - static var previews: some View { +#Preview { + List { ThreadCell(thread: PreviewHelper.sampleThread, density: .large, accentColor: .blue, isMultipleSelectionEnabled: false, isSelected: false) - .previewLayout(.sizeThatFits) - .previewDevice("iPhone 13 Pro") + ThreadCell(thread: PreviewHelper.sampleThread, + density: .normal, + accentColor: .blue, + isMultipleSelectionEnabled: false, + isSelected: false) + ThreadCell(thread: PreviewHelper.sampleThread, + density: .compact, + accentColor: .blue, + isMultipleSelectionEnabled: false, + isSelected: false) } + .listStyle(.plain) + .environmentObject(PreviewHelper.sampleMailboxManager) } diff --git a/Mail/Helpers/PreviewHelper.swift b/Mail/Helpers/PreviewHelper.swift index e6442fed5..75e2ddaed 100644 --- a/Mail/Helpers/PreviewHelper.swift +++ b/Mail/Helpers/PreviewHelper.swift @@ -25,8 +25,27 @@ import RealmSwift import SwiftUI enum PreviewHelper { + private class PreviewHelperRefreshTokenDelegate: RefreshTokenDelegate { + func didUpdateToken(newToken: InfomaniakCore.ApiToken, oldToken: InfomaniakCore.ApiToken) { + // No implementation + } + + func didFailRefreshToken(_ token: InfomaniakCore.ApiToken) { + // No implementation + } + } + static var sampleMailboxManager: MailboxManager = { - let apiFetcher = MailApiFetcher() + let fakeToken = ApiToken( + accessToken: "", + expiresIn: 0, + refreshToken: "", + scope: "", + tokenType: "", + userId: 0, + expirationDate: Date(timeIntervalSinceNow: 1_000_000) + ) + let apiFetcher = MailApiFetcher(token: fakeToken, delegate: PreviewHelperRefreshTokenDelegate()) let contactManager = ContactManager(userId: 0, apiFetcher: apiFetcher) return MailboxManager(account: PreviewHelper.sampleAccount, mailbox: sampleMailbox, From e47f49852845536b9143702e49c57260231f8ba0 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Tue, 21 Nov 2023 13:38:11 +0100 Subject: [PATCH 2/2] fix(ThreadCell): Use frame instead of Spacer --- Mail/Components/ThreadCell.swift | 2 +- Mail/Components/ThreadCellHeaderView.swift | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Mail/Components/ThreadCell.swift b/Mail/Components/ThreadCell.swift index 5c1760d66..8a569dee0 100644 --- a/Mail/Components/ThreadCell.swift +++ b/Mail/Components/ThreadCell.swift @@ -178,7 +178,7 @@ struct ThreadCell: View { HStack(alignment: .top, spacing: UIPadding.verySmall) { ThreadCellInfoView(subject: dataHolder.subject, preview: dataHolder.preview, density: density) - Spacer() + .frame(maxWidth: .infinity, alignment: .leading) ThreadCellDetailsView(hasAttachments: thread.hasAttachments, isFlagged: thread.flagged) } } diff --git a/Mail/Components/ThreadCellHeaderView.swift b/Mail/Components/ThreadCellHeaderView.swift index d4b6b12d7..fc3925451 100644 --- a/Mail/Components/ThreadCellHeaderView.swift +++ b/Mail/Components/ThreadCellHeaderView.swift @@ -45,11 +45,10 @@ struct ThreadCellHeaderView: View, Equatable { .accessibilityHidden(true) } - Spacer() - Text(formattedDate) .textStyle(.bodySmallSecondary) .lineLimit(1) + .frame(maxWidth: .infinity, alignment: .trailing) .accessibilityHidden(true) } }