Files
letro-ios/ElementX/Sources/Other/SwiftUI/Views/EditRoomAddressListRow.swift
Mauro 56eec826df Fix A11y tests (#5104)
* replace NavigationStack with ElementNavigationStack to allow the content to be rendered without a NavigationStack in a11y tests

* fix a11y tests

* update xcodeproject

* swiftformat fix

* use iOS 26.1 for CI

* use a wrapper to solve the issue for a11y tests

* ElementNavigationStack only uses the trick in DEBUG mode, and added a swiftlint rule to prevent the usage of NavigationStack
2026-02-13 16:45:58 +01:00

86 lines
2.7 KiB
Swift

//
// Copyright 2025 Element Creations Ltd.
// Copyright 2024-2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE in the repository root for full details.
//
import Compound
import SwiftUI
struct EditRoomAddressListRow: View {
@Binding var aliasLocalPart: String
var serverName: String
var shouldDisplayError: Bool
private var fullAddress: String {
"#\(aliasLocalPart):\(serverName)"
}
var body: some View {
ListRow(kind: .custom {
HStack(spacing: 0) {
Text("#")
.font(.compound.bodyLG)
.foregroundStyle(.compound.textSecondary)
.accessibilityHidden(true)
TextField("", text: $aliasLocalPart)
.textInputAutocapitalization(.never)
.autocorrectionDisabled()
.textContentType(.URL)
.tint(.compound.iconAccentTertiary)
.font(.compound.bodyLG)
.foregroundStyle(.compound.textPrimary)
.padding(.horizontal, 8)
.accessibilityLabel(L10n.a11yAddress)
.accessibilityHint(L10n.a11yEditRoomAddressHint(fullAddress))
Text(":\(serverName)")
.font(.compound.bodyLG)
.foregroundStyle(.compound.textSecondary)
.accessibilityHidden(true)
}
.padding(ListRowPadding.textFieldInsets)
.environment(\.layoutDirection, .leftToRight)
.errorBackground(shouldDisplayError)
})
}
}
private extension View {
@ViewBuilder
private var shape: some View {
if #available(iOS 26, *) {
Capsule()
.inset(by: 1)
.fill(.compound.bgCriticalSubtleHovered)
.stroke(Color.compound.borderCriticalPrimary)
} else {
RoundedRectangle(cornerRadius: 10)
.inset(by: 1)
.fill(.compound.bgCriticalSubtleHovered)
.stroke(Color.compound.borderCriticalPrimary)
}
}
func errorBackground(_ shouldDisplay: Bool) -> some View {
listRowBackground(shouldDisplay ? AnyView(shape) : AnyView(Color.compound.bgCanvasDefaultLevel1))
}
}
enum EditRoomAddressErrorState {
case alreadyExists
case invalidSymbols
}
extension Set<EditRoomAddressErrorState> {
var errorDescription: String? {
if contains(.alreadyExists) {
return L10n.errorRoomAddressAlreadyExists
} else if contains(.invalidSymbols) {
return L10n.errorRoomAddressInvalidSymbols
}
return nil
}
}