generated from element-hq/.github
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
267 additions
and
36 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
ElementX/Sources/Screens/KnockRequestsListScreen/View/KnockRequestCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
// | ||
// Copyright 2024 New Vector Ltd. | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Please see LICENSE in the repository root for full details. | ||
// | ||
|
||
// | ||
// Copyright 2022-2024 New Vector Ltd. | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Please see LICENSE in the repository root for full details. | ||
// | ||
|
||
import Compound | ||
import SwiftUI | ||
|
||
struct KnockRequestCellInfo { | ||
let userID: String | ||
let displayName: String? | ||
let avatarUrl: URL? | ||
let timestamp: String? | ||
let reason: String? | ||
} | ||
|
||
struct KnockRequestCell: View { | ||
let cellInfo: KnockRequestCellInfo | ||
let onAccept: (String) -> Void | ||
let onDecline: (String) -> Void | ||
let onDeclineAndBan: (String) -> Void | ||
var mediaProvider: MediaProviderProtocol? | ||
|
||
var body: some View { | ||
VStack(spacing: 0) { | ||
HStack(alignment: .top, spacing: 16) { | ||
LoadableAvatarImage(url: cellInfo.avatarUrl, | ||
name: cellInfo.displayName, | ||
contentID: cellInfo.userID, | ||
avatarSize: .user(on: .knockingUserList), | ||
mediaProvider: mediaProvider) | ||
VStack(alignment: .leading, spacing: 12) { | ||
VStack(alignment: .leading, spacing: 0) { | ||
HStack(alignment: .top, spacing: 0) { | ||
Text(cellInfo.displayName ?? cellInfo.userID) | ||
.font(.compound.bodyLGSemibold) | ||
.foregroundStyle(.compound.textPrimary) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
if let timestamp = cellInfo.timestamp { | ||
Text(timestamp) | ||
.font(.compound.bodySM) | ||
.foregroundStyle(.compound.textSecondary) | ||
} | ||
} | ||
if cellInfo.displayName != nil { | ||
Text(cellInfo.userID) | ||
.font(.compound.bodyMD) | ||
.foregroundStyle(.compound.textSecondary) | ||
} | ||
} | ||
if let reason = cellInfo.reason { | ||
DisclosableText(text: reason) | ||
} | ||
actions | ||
} | ||
} | ||
.padding(16) | ||
Divider() | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
private var actions: some View { | ||
HStack(spacing: 16) { | ||
Button(L10n.actionDecline) { | ||
onDecline(cellInfo.userID) | ||
} | ||
.buttonStyle(.compound(.secondary)) | ||
Button(L10n.actionAccept) { | ||
onAccept(cellInfo.userID) | ||
} | ||
.buttonStyle(.compound(.primary)) | ||
} | ||
Button(L10n.screenKnockRequestsListDeclineAndBanActionTitle, role: .destructive) { | ||
onDeclineAndBan(cellInfo.userID) | ||
} | ||
.buttonStyle(.compound(.plain)) | ||
.frame(maxWidth: .infinity) | ||
.padding(.top, 12) | ||
.padding(.bottom, 4) | ||
} | ||
} | ||
|
||
private struct DisclosableText: View { | ||
let text: String | ||
@State private var collapsedHeight = CGFloat.zero | ||
@State private var expandedHeight = CGFloat.zero | ||
@State private var isExpanded = false | ||
|
||
var body: some View { | ||
HStack(alignment: .top, spacing: 4) { | ||
Text(text) | ||
.multilineTextAlignment(.leading) | ||
.lineLimit(isExpanded ? nil : 3) | ||
.font(.compound.bodyMD) | ||
.foregroundStyle(.compound.textPrimary) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
.onGeometryChange(for: CGFloat.self) { geometry in | ||
geometry.size.height | ||
} action: { newValue in | ||
if !isExpanded { | ||
collapsedHeight = newValue | ||
} | ||
} | ||
.background { | ||
Text(text) | ||
.multilineTextAlignment(.leading) | ||
.font(.compound.bodyMD) | ||
.foregroundStyle(.compound.textPrimary) | ||
.fixedSize(horizontal: false, vertical: true) | ||
.onGeometryChange(for: CGFloat.self) { geometry in | ||
geometry.size.height | ||
} action: { newValue in | ||
expandedHeight = newValue | ||
} | ||
.hidden() | ||
} | ||
Button { | ||
withAnimation { | ||
isExpanded.toggle() | ||
} | ||
} label: { | ||
CompoundIcon(\.chevronDown, size: .medium, relativeTo: .compound.bodyMD) | ||
} | ||
.rotationEffect(.degrees(isExpanded ? 180 : 0)) | ||
.foregroundStyle(.compound.iconTertiary) | ||
.opacity(collapsedHeight < expandedHeight ? 1 : 0) | ||
.disabled(collapsedHeight >= expandedHeight) | ||
} | ||
} | ||
} | ||
|
||
struct KnockRequestCell_Previews: PreviewProvider, TestablePreview { | ||
// swiftlint:disable:next line_length | ||
static let aliceWithLongReason = KnockRequestCellInfo(userID: "@alice:matrix.org", displayName: "Alice", avatarUrl: nil, timestamp: "20 Nov 2024", reason: "Hello would like to join this room, also this is a very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long reason") | ||
|
||
static let aliceWithShortReason = KnockRequestCellInfo(userID: "@alice:matrix.org", displayName: "Alice", avatarUrl: nil, timestamp: "20 Nov 2024", reason: "Hello, I am Alice and would like to join this room, please") | ||
|
||
static let aliceWithNoReason = KnockRequestCellInfo(userID: "@alice:matrix.org", displayName: "Alice", avatarUrl: nil, timestamp: "20 Nov 2024", reason: nil) | ||
|
||
static let aliceWithNoName = KnockRequestCellInfo(userID: "@alice:matrix.org", displayName: nil, avatarUrl: nil, timestamp: "20 Nov 2024", reason: nil) | ||
|
||
static var previews: some View { | ||
KnockRequestCell(cellInfo: aliceWithLongReason, onAccept: { _ in }, onDecline: { _ in }, onDeclineAndBan: { _ in }) | ||
.previewDisplayName("Long reason") | ||
KnockRequestCell(cellInfo: aliceWithShortReason, onAccept: { _ in }, onDecline: { _ in }, onDeclineAndBan: { _ in }) | ||
.previewDisplayName("Short reason") | ||
KnockRequestCell(cellInfo: aliceWithNoReason, onAccept: { _ in }, onDecline: { _ in }, onDeclineAndBan: { _ in }) | ||
.previewDisplayName("No reason") | ||
KnockRequestCell(cellInfo: aliceWithNoName, onAccept: { _ in }, onDecline: { _ in }, onDeclineAndBan: { _ in }) | ||
.previewDisplayName("No name") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...ces/__Snapshots__/PreviewTests/test_knockRequestCell-iPad-en-GB.Long-reason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...Sources/__Snapshots__/PreviewTests/test_knockRequestCell-iPad-en-GB.No-name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...urces/__Snapshots__/PreviewTests/test_knockRequestCell-iPad-en-GB.No-reason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...es/__Snapshots__/PreviewTests/test_knockRequestCell-iPad-en-GB.Short-reason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...es/__Snapshots__/PreviewTests/test_knockRequestCell-iPad-pseudo.Long-reason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ources/__Snapshots__/PreviewTests/test_knockRequestCell-iPad-pseudo.No-name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...rces/__Snapshots__/PreviewTests/test_knockRequestCell-iPad-pseudo.No-reason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...s/__Snapshots__/PreviewTests/test_knockRequestCell-iPad-pseudo.Short-reason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
..._Snapshots__/PreviewTests/test_knockRequestCell-iPhone-16-en-GB.Long-reason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...es/__Snapshots__/PreviewTests/test_knockRequestCell-iPhone-16-en-GB.No-name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
.../__Snapshots__/PreviewTests/test_knockRequestCell-iPhone-16-en-GB.No-reason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...Snapshots__/PreviewTests/test_knockRequestCell-iPhone-16-en-GB.Short-reason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...Snapshots__/PreviewTests/test_knockRequestCell-iPhone-16-pseudo.Long-reason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...s/__Snapshots__/PreviewTests/test_knockRequestCell-iPhone-16-pseudo.No-name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...__Snapshots__/PreviewTests/test_knockRequestCell-iPhone-16-pseudo.No-reason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...napshots__/PreviewTests/test_knockRequestCell-iPhone-16-pseudo.Short-reason.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.