tombstoned and upgraded rooms implementation
added tests tombstoned room avatar
This commit is contained in:
35
ElementX/Sources/Other/SwiftUI/Views/Highlight.swift
Normal file
35
ElementX/Sources/Other/SwiftUI/Views/Highlight.swift
Normal file
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// 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 Highlight: ViewModifier {
|
||||
let borderColor: Color
|
||||
let primaryColor: Color
|
||||
let secondaryColor: Color
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
ZStack(alignment: .top) {
|
||||
VStack(spacing: 0) {
|
||||
borderColor
|
||||
.frame(height: 1)
|
||||
LinearGradient(colors: [primaryColor, secondaryColor],
|
||||
startPoint: .top,
|
||||
endPoint: .bottom)
|
||||
}
|
||||
content
|
||||
.layoutPriority(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func highlight(borderColor: Color, primaryColor: Color, secondaryColor: Color) -> some View {
|
||||
modifier(Highlight(borderColor: borderColor, primaryColor: primaryColor, secondaryColor: secondaryColor))
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ 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 {
|
||||
@@ -22,7 +23,9 @@ struct PlaceholderAvatarImage: View {
|
||||
// This text's frame doesn't look right when redacted
|
||||
if redactionReasons != .placeholder {
|
||||
Text(textForImage)
|
||||
.foregroundColor(avatarColor?.text ?? .white)
|
||||
.foregroundColor(avatarColor?.text ??
|
||||
// tombstoned room foreground
|
||||
.compound.iconTertiary)
|
||||
.font(.system(size: geometry.size.width * 0.5625, weight: .semibold))
|
||||
.minimumScaleFactor(0.001)
|
||||
.frame(alignment: .center)
|
||||
@@ -43,7 +46,9 @@ struct PlaceholderAvatarImage: View {
|
||||
return Color(.systemGray4) // matches the default text redaction
|
||||
}
|
||||
|
||||
return avatarColor?.background ?? .compound.iconPrimary
|
||||
return avatarColor?.background ??
|
||||
// tombstoned room background
|
||||
.compound.bgSubtlePrimary
|
||||
}
|
||||
|
||||
private var avatarColor: DecorativeColor? {
|
||||
@@ -70,6 +75,10 @@ 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)
|
||||
|
||||
@@ -13,13 +13,17 @@ enum RoomAvatar: Equatable {
|
||||
case room(id: String, name: String?, avatarURL: URL?)
|
||||
/// An avatar generated from the room's heroes.
|
||||
case heroes([UserProfileProxy])
|
||||
/// A static avatar for a tombstoned room.
|
||||
case tombstoned
|
||||
|
||||
var removingAvatar: RoomAvatar {
|
||||
switch self {
|
||||
case let .room(id, name, _):
|
||||
return .room(id: id, name: name, avatarURL: nil)
|
||||
.room(id: id, name: name, avatarURL: nil)
|
||||
case let .heroes(users):
|
||||
return .heroes(users.map { .init(userID: $0.userID, displayName: $0.displayName, avatarURL: nil) })
|
||||
.heroes(users.map { .init(userID: $0.userID, displayName: $0.displayName, avatarURL: nil) })
|
||||
case .tombstoned:
|
||||
.tombstoned
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,6 +95,12 @@ struct RoomAvatarImage: View {
|
||||
mediaProvider: mediaProvider,
|
||||
onTap: onAvatarTap)
|
||||
}
|
||||
case .tombstoned:
|
||||
LoadableAvatarImage(url: nil,
|
||||
name: "!",
|
||||
contentID: nil, avatarSize: avatarSize,
|
||||
mediaProvider: mediaProvider,
|
||||
onTap: onAvatarTap)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,6 +136,8 @@ struct RoomAvatarImage_Previews: PreviewProvider, TestablePreview {
|
||||
.init(userID: "@bob:server.net", displayName: "Bob", avatarURL: nil)]),
|
||||
avatarSize: .room(on: .home),
|
||||
mediaProvider: MediaProviderMock(configuration: .init()))
|
||||
|
||||
RoomAvatarImage(avatar: .tombstoned, avatarSize: .room(on: .home), mediaProvider: MediaProviderMock(configuration: .init()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user