added a TombstonedAvatarImage view to be used for the .tombstoned case

This commit is contained in:
Mauro Romito
2025-06-05 17:53:27 +02:00
committed by Mauro
parent 975d3c995a
commit 186501a848
13 changed files with 72 additions and 24 deletions

View File

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

View File

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

View File

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

View File

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

View File

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