From 186501a848d5963055e6942e59822760ace16aba Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Thu, 5 Jun 2025 17:53:27 +0200 Subject: [PATCH] added a TombstonedAvatarImage view to be used for the .tombstoned case --- .../Mocks/Generated/GeneratedMocks.swift | 1 + .../Views/PlaceholderAvatarImage.swift | 13 +----- .../Other/SwiftUI/Views/RoomAvatarImage.swift | 6 +-- .../SwiftUI/Views/TombstonedAvatarImage.swift | 42 +++++++++++++++++++ .../Sources/GeneratedPreviewTests.swift | 6 +++ .../placeholderAvatarImage.iPad-en-GB-0.png | 4 +- .../placeholderAvatarImage.iPad-pseudo-0.png | 4 +- ...aceholderAvatarImage.iPhone-16-en-GB-0.png | 4 +- ...ceholderAvatarImage.iPhone-16-pseudo-0.png | 4 +- .../tombstonedAvatarImage.iPad-en-GB-0.png | 3 ++ .../tombstonedAvatarImage.iPad-pseudo-0.png | 3 ++ ...ombstonedAvatarImage.iPhone-16-en-GB-0.png | 3 ++ ...mbstonedAvatarImage.iPhone-16-pseudo-0.png | 3 ++ 13 files changed, 72 insertions(+), 24 deletions(-) create mode 100644 ElementX/Sources/Other/SwiftUI/Views/TombstonedAvatarImage.swift create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPad-en-GB-0.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPad-pseudo-0.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPhone-16-en-GB-0.png create mode 100644 PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPhone-16-pseudo-0.png diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index 1c04daed1..9ede20243 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -6485,6 +6485,7 @@ class JoinedRoomProxyMock: JoinedRoomProxyProtocol, @unchecked Sendable { } var underlyingTimeline: TimelineProxyProtocol! var predecessorRoom: PredecessorRoom? + var successorRoom: SuccessorRoom? var id: String { get { return underlyingId } set(value) { underlyingId = value } diff --git a/ElementX/Sources/Other/SwiftUI/Views/PlaceholderAvatarImage.swift b/ElementX/Sources/Other/SwiftUI/Views/PlaceholderAvatarImage.swift index 8816d05b2..9b6a9be13 100644 --- a/ElementX/Sources/Other/SwiftUI/Views/PlaceholderAvatarImage.swift +++ b/ElementX/Sources/Other/SwiftUI/Views/PlaceholderAvatarImage.swift @@ -12,7 +12,6 @@ struct PlaceholderAvatarImage: View { @Environment(\.redactionReasons) private var redactionReasons private let textForImage: String - /// When `nil` the tombstoned colors will be used private let contentID: String? var body: some View { @@ -23,9 +22,7 @@ struct PlaceholderAvatarImage: View { // This text's frame doesn't look right when redacted if redactionReasons != .placeholder { Text(textForImage) - .foregroundColor(avatarColor?.text ?? - // tombstoned room foreground - .compound.iconTertiary) + .foregroundColor(avatarColor?.text ?? .white) .font(.system(size: geometry.size.width * 0.5625, weight: .semibold)) .minimumScaleFactor(0.001) .frame(alignment: .center) @@ -46,9 +43,7 @@ struct PlaceholderAvatarImage: View { return Color(.systemGray4) // matches the default text redaction } - return avatarColor?.background ?? - // tombstoned room background - .compound.bgSubtlePrimary + return avatarColor?.background ?? .compound.iconPrimary } private var avatarColor: DecorativeColor? { @@ -75,10 +70,6 @@ struct PlaceholderAvatarImage_Previews: PreviewProvider, TestablePreview { .clipShape(Circle()) .frame(width: 150, height: 100) - PlaceholderAvatarImage(name: "!", contentID: nil) - .clipShape(Circle()) - .frame(width: 100, height: 100) - PlaceholderAvatarImage(name: nil, contentID: "@fooserid:matrix.org") .clipShape(Circle()) .frame(width: 30, height: 30) diff --git a/ElementX/Sources/Other/SwiftUI/Views/RoomAvatarImage.swift b/ElementX/Sources/Other/SwiftUI/Views/RoomAvatarImage.swift index d60308083..ef23fc68d 100644 --- a/ElementX/Sources/Other/SwiftUI/Views/RoomAvatarImage.swift +++ b/ElementX/Sources/Other/SwiftUI/Views/RoomAvatarImage.swift @@ -96,11 +96,7 @@ struct RoomAvatarImage: View { onTap: onAvatarTap) } case .tombstoned: - LoadableAvatarImage(url: nil, - name: "!", - contentID: nil, avatarSize: avatarSize, - mediaProvider: mediaProvider, - onTap: onAvatarTap) + TombstonedAvatarImage(avatarSize: avatarSize) } } } diff --git a/ElementX/Sources/Other/SwiftUI/Views/TombstonedAvatarImage.swift b/ElementX/Sources/Other/SwiftUI/Views/TombstonedAvatarImage.swift new file mode 100644 index 000000000..96ede63cb --- /dev/null +++ b/ElementX/Sources/Other/SwiftUI/Views/TombstonedAvatarImage.swift @@ -0,0 +1,42 @@ +// +// Copyright 2025 New Vector Ltd. +// +// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial +// Please see LICENSE files in the repository root for full details. +// + +import Compound +import SwiftUI + +struct TombstonedAvatarImage: View { + @ScaledMetric private var frameSize: CGFloat + + init(avatarSize: Avatars.Size) { + _frameSize = ScaledMetric(wrappedValue: avatarSize.value) + } + + var body: some View { + GeometryReader { geometry in + ZStack(alignment: .center) { + Color.compound.bgSubtlePrimary + + Text(verbatim: "!") + .foregroundColor(.compound.iconTertiary) + .font(.system(size: geometry.size.width * 0.5625, weight: .semibold)) + .minimumScaleFactor(0.001) + .frame(alignment: .center) + } + } + .aspectRatio(1, contentMode: .fill) + .frame(width: frameSize, height: frameSize) + .background(Color.compound.bgCanvasDefault) + .clipShape(Circle()) + } +} + +struct TombstonedAvatarImage_Previews: PreviewProvider, TestablePreview { + static var previews: some View { + TombstonedAvatarImage(avatarSize: .room(on: .home)) + .previewLayout(.sizeThatFits) + } +} diff --git a/PreviewTests/Sources/GeneratedPreviewTests.swift b/PreviewTests/Sources/GeneratedPreviewTests.swift index 0f3b43ce1..428caa210 100644 --- a/PreviewTests/Sources/GeneratedPreviewTests.swift +++ b/PreviewTests/Sources/GeneratedPreviewTests.swift @@ -1013,6 +1013,12 @@ extension PreviewTests { } } + func testTombstonedAvatarImage() async throws { + for (index, preview) in TombstonedAvatarImage_Previews._allPreviews.enumerated() { + try await assertSnapshots(matching: preview, step: index) + } + } + func testTypingIndicatorView() async throws { for (index, preview) in TypingIndicatorView_Previews._allPreviews.enumerated() { try await assertSnapshots(matching: preview, step: index) diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPad-en-GB-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPad-en-GB-0.png index 09dc28d86..6f56315b8 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPad-en-GB-0.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPad-en-GB-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:acc53e8fc7d224fc2ec0ce663efde39aaa625dcf11de3ca43f52704c814d0825 -size 101058 +oid sha256:eaa4236ec02b96b3883fccefc5e45b0b296448ab52ecc87201a837e5b1b23a83 +size 96810 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPad-pseudo-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPad-pseudo-0.png index 09dc28d86..6f56315b8 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPad-pseudo-0.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPad-pseudo-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:acc53e8fc7d224fc2ec0ce663efde39aaa625dcf11de3ca43f52704c814d0825 -size 101058 +oid sha256:eaa4236ec02b96b3883fccefc5e45b0b296448ab52ecc87201a837e5b1b23a83 +size 96810 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPhone-16-en-GB-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPhone-16-en-GB-0.png index fafe12fef..401d8ce2d 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPhone-16-en-GB-0.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPhone-16-en-GB-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ec055acc51709c62fe9d76a93db885da6de917eb014bde88c51307b9582e352e -size 59276 +oid sha256:21089ce2daaa37f7e86031e11eab89d2dd9e80bb319c004fb86a9fc0e83d84f1 +size 55228 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPhone-16-pseudo-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPhone-16-pseudo-0.png index fafe12fef..401d8ce2d 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPhone-16-pseudo-0.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/placeholderAvatarImage.iPhone-16-pseudo-0.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ec055acc51709c62fe9d76a93db885da6de917eb014bde88c51307b9582e352e -size 59276 +oid sha256:21089ce2daaa37f7e86031e11eab89d2dd9e80bb319c004fb86a9fc0e83d84f1 +size 55228 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPad-en-GB-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPad-en-GB-0.png new file mode 100644 index 000000000..3ae619153 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPad-en-GB-0.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da0585b2cb692b7a8560c0b7953bfe6c6a0c3c93b900ac0d22d0f2263fc01742 +size 6601 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPad-pseudo-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPad-pseudo-0.png new file mode 100644 index 000000000..3ae619153 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPad-pseudo-0.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da0585b2cb692b7a8560c0b7953bfe6c6a0c3c93b900ac0d22d0f2263fc01742 +size 6601 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPhone-16-en-GB-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPhone-16-en-GB-0.png new file mode 100644 index 000000000..a9ec85266 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPhone-16-en-GB-0.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d29a91cf15e22b917e43d2343dd092903144193687d4a6bb94c50254806919da +size 4044 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPhone-16-pseudo-0.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPhone-16-pseudo-0.png new file mode 100644 index 000000000..a9ec85266 --- /dev/null +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/tombstonedAvatarImage.iPhone-16-pseudo-0.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d29a91cf15e22b917e43d2343dd092903144193687d4a6bb94c50254806919da +size 4044