mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Rename screens (#826)
* Rename: AnalyticsPrompt -> AnalyticsPromptScreen * Rename: AnalyticsSettings -> AnalyticsSettingsScreen * Rename: Settings -> SettingsScreen * Rename: SessionVerification -> SessionVerificationScreen * Rename: BugReport -> BugReportScreen * Rename: FilePreview -> FilePreviewScreen * Rename: AnalyticsPrompt -> AnalyticsPromptScreen * Rename: Invites -> InvitesScreen * Rename: InviteUsers -> InviteUsersScreen * Rename: MediaPicker -> MediaPickerScreen * Delete unused UIActivityViewControllerWrapper * Rename: ReportContent -> ReportContentScreen * Rename: RoomDetails -> RoomDetailsScreen * Rename: RoomMemberDetails -> RoomMemberDetailsScreen * Rename: RoomMemberList -> RoomMemberListScreen * Rename: Cleanup * Renaming missed items * Low effort attempt at fixing the flakey unit tests
This commit is contained in:
@@ -0,0 +1,205 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
struct InvitesScreenCell: View {
|
||||
let invite: InvitesScreenRoomDetails
|
||||
let imageProvider: ImageProviderProtocol?
|
||||
let acceptAction: () -> Void
|
||||
let declineAction: () -> Void
|
||||
|
||||
private let verticalInsets = 16.0
|
||||
@ScaledMetric private var badgeSize = 12.0
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .top, spacing: 16) {
|
||||
LoadableAvatarImage(url: mainAvatarURL,
|
||||
name: title,
|
||||
contentID: invite.roomDetails.id,
|
||||
avatarSize: .custom(52),
|
||||
imageProvider: imageProvider)
|
||||
.accessibilityHidden(true)
|
||||
|
||||
mainContent
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.bottom, verticalInsets)
|
||||
.overlay(alignment: .bottom) {
|
||||
separator
|
||||
}
|
||||
}
|
||||
.padding(.top, verticalInsets)
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private var mainContent: some View {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 12) {
|
||||
textualContent
|
||||
|
||||
if invite.isUnread {
|
||||
badge
|
||||
}
|
||||
}
|
||||
|
||||
inviterView
|
||||
|
||||
buttons
|
||||
.padding(.trailing, 26)
|
||||
.padding(.top, 8)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var inviterView: some View {
|
||||
if let invitedText = attributedInviteText, let name = invite.inviter?.displayName {
|
||||
HStack {
|
||||
LoadableAvatarImage(url: invite.inviter?.avatarURL,
|
||||
name: name,
|
||||
contentID: name,
|
||||
avatarSize: .custom(16),
|
||||
imageProvider: imageProvider)
|
||||
|
||||
Text(invitedText)
|
||||
}
|
||||
.padding(.top, 4)
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var textualContent: some View {
|
||||
VStack(alignment: .leading) {
|
||||
Text(title)
|
||||
.font(.element.headline)
|
||||
.foregroundColor(.element.primaryContent)
|
||||
|
||||
if let subtitle {
|
||||
Text(subtitle)
|
||||
.font(.compound.bodyMD)
|
||||
.foregroundColor(.compound.textPlaceholder)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
private var buttons: some View {
|
||||
HStack(spacing: 12) {
|
||||
Button(L10n.actionDecline, action: declineAction)
|
||||
.buttonStyle(.elementCapsule)
|
||||
.accessibilityIdentifier(A11yIdentifiers.invitesScreen.decline)
|
||||
|
||||
Button(L10n.actionAccept, action: acceptAction)
|
||||
.buttonStyle(.elementCapsuleProminent)
|
||||
.accessibilityIdentifier(A11yIdentifiers.invitesScreen.accept)
|
||||
}
|
||||
}
|
||||
|
||||
private var separator: some View {
|
||||
Rectangle()
|
||||
.fill(Color.element.quinaryContent)
|
||||
.frame(height: 1 / UIScreen.main.scale)
|
||||
}
|
||||
|
||||
#warning("Return just `roomDetails.avatarURL` when this logic is implemented in the rust sdk")
|
||||
private var mainAvatarURL: URL? {
|
||||
invite.isDirect ? invite.inviter?.avatarURL : invite.roomDetails.avatarURL
|
||||
}
|
||||
|
||||
private var title: String {
|
||||
invite.roomDetails.name
|
||||
}
|
||||
|
||||
private var subtitle: String? {
|
||||
invite.isDirect ? invite.inviter?.userID : invite.roomDetails.canonicalAlias
|
||||
}
|
||||
|
||||
private var attributedInviteText: AttributedString? {
|
||||
guard invite.roomDetails.isDirect == false, let inviterName = invite.inviter?.displayName else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let text = L10n.screenInvitesInvitedYou(inviterName)
|
||||
var attributedString = AttributedString(text)
|
||||
attributedString.font = .compound.bodyMD
|
||||
attributedString.foregroundColor = .compound.textPlaceholder
|
||||
if let range = attributedString.range(of: inviterName) {
|
||||
attributedString[range].foregroundColor = .compound.textPrimary
|
||||
}
|
||||
return attributedString
|
||||
}
|
||||
|
||||
private var badge: some View {
|
||||
Circle()
|
||||
.frame(width: badgeSize, height: badgeSize)
|
||||
.foregroundColor(.element.brand)
|
||||
}
|
||||
}
|
||||
|
||||
struct InvitesScreenCell_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
InvitesScreenCell(invite: .dm, imageProvider: MockMediaProvider(), acceptAction: { }, declineAction: { })
|
||||
.previewDisplayName("Direct room")
|
||||
|
||||
InvitesScreenCell(invite: .room(alias: nil), imageProvider: MockMediaProvider(), acceptAction: { }, declineAction: { })
|
||||
.previewDisplayName("Default room")
|
||||
|
||||
InvitesScreenCell(invite: .room(alias: "#footest:somewhere.org"), imageProvider: MockMediaProvider(), acceptAction: { }, declineAction: { })
|
||||
.previewDisplayName("Aliased room")
|
||||
|
||||
InvitesScreenCell(invite: .room(alias: "#footest:somewhere.org"), imageProvider: MockMediaProvider(), acceptAction: { }, declineAction: { })
|
||||
.dynamicTypeSize(.accessibility1)
|
||||
.previewDisplayName("Aliased room (AX1)")
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private extension InvitesScreenRoomDetails {
|
||||
static var dm: InvitesScreenRoomDetails {
|
||||
let dmRoom = RoomSummaryDetails(id: "@someone:somewhere.com",
|
||||
name: "Some Guy",
|
||||
isDirect: true,
|
||||
avatarURL: nil,
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
unreadNotificationCount: 0,
|
||||
canonicalAlias: "#footest:somewhere.org")
|
||||
let inviter = RoomMemberProxyMock()
|
||||
inviter.displayName = "Jack"
|
||||
inviter.userID = "@jack:somewhere.com"
|
||||
|
||||
return .init(roomDetails: dmRoom, inviter: inviter, isUnread: false)
|
||||
}
|
||||
|
||||
static func room(alias: String?) -> InvitesScreenRoomDetails {
|
||||
let dmRoom = RoomSummaryDetails(id: "@someone:somewhere.com",
|
||||
name: "Awesome Room",
|
||||
isDirect: false,
|
||||
avatarURL: nil,
|
||||
lastMessage: nil,
|
||||
lastMessageFormattedTimestamp: nil,
|
||||
unreadNotificationCount: 0,
|
||||
canonicalAlias: alias)
|
||||
let inviter = RoomMemberProxyMock()
|
||||
inviter.displayName = "Luca"
|
||||
inviter.userID = "@jack:somewhere.com"
|
||||
inviter.avatarURL = nil
|
||||
|
||||
return .init(roomDetails: dmRoom, inviter: inviter, isUnread: true)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user