Run SwiftFormat and fix SwiftLint.

This commit is contained in:
Doug
2025-09-28 15:25:05 +01:00
committed by Doug
parent aeaac90239
commit 6bec5f794a
15 changed files with 54 additions and 46 deletions

View File

@@ -306,7 +306,7 @@ public struct CompoundButtonStyle_Previews: PreviewProvider, TestablePreview {
.foregroundStyle(.compound.textSecondary) .foregroundStyle(.compound.textSecondary)
.frame(maxWidth: .infinity, alignment: .leading) .frame(maxWidth: .infinity, alignment: .leading)
.padding([.leading, .top]) .padding([.leading, .top])
.padding(.leading ) .padding(.leading)
} }
} }
} }

View File

@@ -1,4 +1,4 @@
// //
// Copyright 2024 New Vector Ltd // Copyright 2024 New Vector Ltd
// //
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial

View File

@@ -33,7 +33,7 @@ public class CompoundColors {
private var overrides = [KeyPath<CompoundColorTokens, Color>: Color]() private var overrides = [KeyPath<CompoundColorTokens, Color>: Color]()
public subscript(dynamicMember keyPath: KeyPath<CompoundColorTokens, Color>) -> Color { public subscript(dynamicMember keyPath: KeyPath<CompoundColorTokens, Color>) -> Color {
return overrides[keyPath] ?? tokens[keyPath: keyPath] overrides[keyPath] ?? tokens[keyPath: keyPath]
} }
/// Customise the colour at the specified key path with the supplied colour. /// Customise the colour at the specified key path with the supplied colour.
@@ -47,16 +47,17 @@ public class CompoundColors {
self.tokens = tokens self.tokens = tokens
decorativeColors = [ decorativeColors = [
.init(background: tokens.bgDecorative1, text: tokens.textDecorative1), .init(background: tokens.bgDecorative1, text: tokens.textDecorative1),
.init(background: tokens.bgDecorative2, text: tokens.textDecorative2), .init(background: tokens.bgDecorative2, text: tokens.textDecorative2),
.init(background: tokens.bgDecorative3, text: tokens.textDecorative3), .init(background: tokens.bgDecorative3, text: tokens.textDecorative3),
.init(background: tokens.bgDecorative4, text: tokens.textDecorative4), .init(background: tokens.bgDecorative4, text: tokens.textDecorative4),
.init(background: tokens.bgDecorative5, text: tokens.textDecorative5), .init(background: tokens.bgDecorative5, text: tokens.textDecorative5),
.init(background: tokens.bgDecorative6, text: tokens.textDecorative6), .init(background: tokens.bgDecorative6, text: tokens.textDecorative6)
] ]
} }
// MARK: - Decorative Colors // MARK: - Decorative Colors
// Used to determine the background and text colors of avatars, usernames etc. // Used to determine the background and text colors of avatars, usernames etc.
let decorativeColors: [DecorativeColor] let decorativeColors: [DecorativeColor]
@@ -67,6 +68,7 @@ public class CompoundColors {
// MARK: - Awaiting Semantic Tokens // MARK: - Awaiting Semantic Tokens
// swiftformat:disable numberFormatting
/// This token is a placeholder and hasn't been finalised. /// This token is a placeholder and hasn't been finalised.
@available(iOS, deprecated: 100000.0, message: "This token should be generated by now.") @available(iOS, deprecated: 100000.0, message: "This token should be generated by now.")
public let _borderTextFieldFocused = coreTokens.gray500 public let _borderTextFieldFocused = coreTokens.gray500
@@ -91,6 +93,7 @@ public class CompoundColors {
/// This token is a placeholder and hasn't been finalised. /// This token is a placeholder and hasn't been finalised.
@available(iOS, deprecated: 100000.0, message: "This token should be generated by now.") @available(iOS, deprecated: 100000.0, message: "This token should be generated by now.")
public let _bgEmptyItemAlpha = coreTokens.alphaGray500 public let _bgEmptyItemAlpha = coreTokens.alphaGray500
// swiftformat:enable numberFormatting
} }
private extension UITraitCollection { private extension UITraitCollection {
@@ -107,9 +110,9 @@ private extension String {
/// Calculates a numeric hash same as Element Web /// Calculates a numeric hash same as Element Web
/// See original function here https://github.com/matrix-org/matrix-react-sdk/blob/321dd49db4fbe360fc2ff109ac117305c955b061/src/utils/FormattingUtils.js#L47 /// See original function here https://github.com/matrix-org/matrix-react-sdk/blob/321dd49db4fbe360fc2ff109ac117305c955b061/src/utils/FormattingUtils.js#L47
var hashCode: Int { var hashCode: Int {
let characterCodeSum = self.reduce(0) { sum, character in let characterCodeSum = reduce(0) { sum, character in
sum + Int(character.unicodeScalars.first?.value ?? 0) sum + Int(character.unicodeScalars.first?.value ?? 0)
} }
return (characterCodeSum % Color.compound.decorativeColors.count) return characterCodeSum % Color.compound.decorativeColors.count
} }
} }

View File

@@ -1,4 +1,4 @@
// //
// Copyright 2025 New Vector Ltd // Copyright 2025 New Vector Ltd
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only

View File

@@ -28,7 +28,7 @@ public class CompoundUIColors {
private var overrides = [KeyPath<CompoundUIColorTokens, UIColor>: UIColor]() private var overrides = [KeyPath<CompoundUIColorTokens, UIColor>: UIColor]()
public subscript(dynamicMember keyPath: KeyPath<CompoundUIColorTokens, UIColor>) -> UIColor { public subscript(dynamicMember keyPath: KeyPath<CompoundUIColorTokens, UIColor>) -> UIColor {
return overrides[keyPath] ?? tokens[keyPath: keyPath] overrides[keyPath] ?? tokens[keyPath: keyPath]
} }
/// Customise the colour at the specified key path with the supplied colour. /// Customise the colour at the specified key path with the supplied colour.
@@ -39,12 +39,14 @@ public class CompoundUIColors {
// MARK: - Awaiting Semantic Tokens // MARK: - Awaiting Semantic Tokens
// swiftformat:disable numberFormatting
/// This token is a placeholder and hasn't been finalised. /// This token is a placeholder and hasn't been finalised.
@available(iOS, deprecated: 100000.0, message: "This token should be generated by now.") @available(iOS, deprecated: 100000.0, message: "This token should be generated by now.")
public let _bgCodeBlock = coreTokens.gray100 public let _bgCodeBlock = coreTokens.gray100
/// This token is a placeholder and hasn't been finalised. /// This token is a placeholder and hasn't been finalised.
@available(iOS, deprecated: 100000.0, message: "This token should be generated by now.") @available(iOS, deprecated: 100000.0, message: "This token should be generated by now.")
public let _bgSubtleSecondaryAlpha = coreTokens.alphaGray300 public let _bgSubtleSecondaryAlpha = coreTokens.alphaGray300
// swiftformat:enable numberFormatting
} }
private extension UITraitCollection { private extension UITraitCollection {

View File

@@ -52,8 +52,8 @@ public struct CompoundIcon: View {
/// - icon: The icon to show. /// - icon: The icon to show.
public init(_ icon: KeyPath<CompoundIcons, Image>) { public init(_ icon: KeyPath<CompoundIcons, Image>) {
image = .compound[keyPath: icon] image = .compound[keyPath: icon]
self.size = .medium size = .medium
self.font = .compound.bodyLG font = .compound.bodyLG
} }
/// Creates an icon using a key path from the Compound tokens. /// Creates an icon using a key path from the Compound tokens.
@@ -78,8 +78,8 @@ public struct CompoundIcon: View {
/// ** Note:** The image should have a square frame or it may end up distorted. /// ** Note:** The image should have a square frame or it may end up distorted.
public init(customImage: Image) { public init(customImage: Image) {
image = customImage image = customImage
self.size = .medium size = .medium
self.font = .compound.bodyLG font = .compound.bodyLG
} }
/// Creates an icon using a custom image to allow assets from outside /// Creates an icon using a custom image to allow assets from outside
@@ -180,7 +180,6 @@ struct CompoundIcon_Previews: PreviewProvider, TestablePreview {
} }
} }
static var accessibilityLabels: some View { static var accessibilityLabels: some View {
Grid(alignment: .leading) { Grid(alignment: .leading) {
ForEach(DynamicTypeSize.allCases, id: \.self) { ForEach(DynamicTypeSize.allCases, id: \.self) {

View File

@@ -28,7 +28,6 @@ private struct ScaledOffsetModifier: ViewModifier {
} }
} }
// MARK: - Previews // MARK: - Previews
struct ScaledOffsetModifier_Previews: PreviewProvider, TestablePreview { struct ScaledOffsetModifier_Previews: PreviewProvider, TestablePreview {

View File

@@ -18,13 +18,13 @@ struct ListInlinePicker<SelectedValue: Hashable>: View {
ListRow(label: .plain(title: item.title), ListRow(label: .plain(title: item.title),
details: isWaiting ? .isWaiting(selection == item.tag) : nil, details: isWaiting ? .isWaiting(selection == item.tag) : nil,
kind: .selection(isSelected: !isWaiting ? selection == item.tag : false) { kind: .selection(isSelected: !isWaiting ? selection == item.tag : false) {
var transaction = Transaction() var transaction = Transaction()
transaction.disablesAnimations = true transaction.disablesAnimations = true
withTransaction(transaction) { withTransaction(transaction) {
selection = item.tag selection = item.tag
} }
}) })
} }
} }
} }

View File

@@ -184,14 +184,14 @@ public extension ListRow where DetailsIcon == EmptyView, CustomContent == EmptyV
// Custom row without a label or details label. // Custom row without a label or details label.
public extension ListRow where Icon == EmptyView, DetailsIcon == EmptyView { public extension ListRow where Icon == EmptyView, DetailsIcon == EmptyView {
init(kind: Kind<CustomContent, SelectionValue>) { init(kind: Kind<CustomContent, SelectionValue>) {
self.label = ListRowLabel() label = ListRowLabel()
self.details = nil details = nil
self.kind = kind self.kind = kind
} }
init(kind: Kind<CustomContent, SelectionValue>) where SelectionValue == String { init(kind: Kind<CustomContent, SelectionValue>) where SelectionValue == String {
self.label = ListRowLabel() label = ListRowLabel()
self.details = nil details = nil
self.kind = kind self.kind = kind
} }
} }
@@ -249,6 +249,7 @@ private extension Button {
// MARK: - Previews // MARK: - Previews
// swiftlint:disable print_deprecation
public struct ListRow_Previews: PreviewProvider, TestablePreview { public struct ListRow_Previews: PreviewProvider, TestablePreview {
public static var previews: some View { public static var previews: some View {
Form { Form {
@@ -348,14 +349,14 @@ public struct ListRow_Previews: PreviewProvider, TestablePreview {
systemIcon: .squareDashed), systemIcon: .squareDashed),
details: .title("Content"), details: .title("Content"),
kind: .selection(isSelected: true) { kind: .selection(isSelected: true) {
print("I was tapped!") print("I was tapped!")
}) })
ListRow(label: .default(title: "Title", ListRow(label: .default(title: "Title",
systemIcon: .squareDashed), systemIcon: .squareDashed),
details: .title("Content"), details: .title("Content"),
kind: .selection(isSelected: true) { kind: .selection(isSelected: true) {
print("I was tapped!") print("I was tapped!")
}) })
ListRow(label: .plain(title: "Title"), ListRow(label: .plain(title: "Title"),
kind: .inlinePicker(selection: .constant("Item 1"), kind: .inlinePicker(selection: .constant("Item 1"),
@@ -375,7 +376,7 @@ public struct ListRow_Previews: PreviewProvider, TestablePreview {
ListRow(label: .action(title: "Title", ListRow(label: .action(title: "Title",
systemIcon: .squareDashed), systemIcon: .squareDashed),
kind: .button { print("I was tapped!") }) kind: .button { print("I was tapped!") })
.disabled(true) .disabled(true)
} }
static var plainButton: some View { static var plainButton: some View {
@@ -401,7 +402,7 @@ public struct ListRow_Previews: PreviewProvider, TestablePreview {
ListRow(label: .centeredAction(title: "Title", ListRow(label: .centeredAction(title: "Title",
systemIcon: .squareDashed), systemIcon: .squareDashed),
kind: .button { print("I was tapped!") }) kind: .button { print("I was tapped!") })
.disabled(true) .disabled(true)
} }
} }
@@ -445,10 +446,10 @@ public struct ListRow_Previews: PreviewProvider, TestablePreview {
}) })
ListRow(label: .plain(title: "Placeholder"), ListRow(label: .plain(title: "Placeholder"),
kind: .textField(text: .constant("This is a disabled text field"))) kind: .textField(text: .constant("This is a disabled text field")))
.disabled(true) .disabled(true)
ListRow(label: .plain(title: "Placeholder"), ListRow(label: .plain(title: "Placeholder"),
kind: .textField(text: .constant(""), axis: .vertical)) kind: .textField(text: .constant(""), axis: .vertical))
.lineLimit(4...) .lineLimit(4...)
ListRow(label: .plain(title: "Password"), ListRow(label: .plain(title: "Password"),
kind: .secureField(text: .constant("p4ssw0rd"))) kind: .secureField(text: .constant("p4ssw0rd")))
} }
@@ -474,3 +475,5 @@ struct ListRowLoadingSelection_Previews: PreviewProvider, TestablePreview {
.compoundList() .compoundList()
} }
} }
// swiftlint:enable print_deprecation

View File

@@ -26,17 +26,17 @@ public struct ListRowAccessory: View {
/// A chevron to indicate that the button pushes another screen. /// A chevron to indicate that the button pushes another screen.
public static var navigationLink: Self { public static var navigationLink: Self {
Self.init(kind: .navigationLink) Self(kind: .navigationLink)
} }
/// A checkmark (or reserved space) to indicate that the row is selected. /// A checkmark (or reserved space) to indicate that the row is selected.
public static func selection(_ isSelected: Bool) -> Self { public static func selection(_ isSelected: Bool) -> Self {
Self.init(kind: isSelected ? .selected : .unselected) Self(kind: isSelected ? .selected : .unselected)
} }
/// A circular checkmark (or empty circle) to indicate that the row is one of multiple selected. /// A circular checkmark (or empty circle) to indicate that the row is one of multiple selected.
public static func multiSelection(_ isSelected: Bool) -> Self { public static func multiSelection(_ isSelected: Bool) -> Self {
Self.init(kind: isSelected ? .multiSelected : .multiUnselected) Self(kind: isSelected ? .multiSelected : .multiUnselected)
} }
let kind: Kind let kind: Kind

View File

@@ -61,7 +61,7 @@ public struct ListRowDetails<Icon: View> {
public static func icon(_ icon: KeyPath<CompoundIcons, Image>, public static func icon(_ icon: KeyPath<CompoundIcons, Image>,
counter: Int? = nil, counter: Int? = nil,
isWaiting: Bool = false) -> Self where Icon == CompoundIcon { isWaiting: Bool = false) -> Self where Icon == CompoundIcon {
ListRowDetails(icon:CompoundIcon(icon), ListRowDetails(icon: CompoundIcon(icon),
counter: counter, counter: counter,
isWaiting: isWaiting) isWaiting: isWaiting)
} }

View File

@@ -68,7 +68,7 @@ public struct ListRowLabel<Icon: View>: View {
} }
var iconAlignment: VerticalAlignment = .center var iconAlignment: VerticalAlignment = .center
var hideIconBackground: Bool = false var hideIconBackground = false
enum Layout { case `default`, centered, avatar } enum Layout { case `default`, centered, avatar }
var layout: Layout = .default var layout: Layout = .default
@@ -77,6 +77,7 @@ public struct ListRowLabel<Icon: View>: View {
guard isEnabled else { return .compound.textDisabled } guard isEnabled else { return .compound.textDisabled }
return role == .destructive ? .compound.textCriticalPrimary : .compound.textPrimary return role == .destructive ? .compound.textCriticalPrimary : .compound.textPrimary
} }
var titleLineLimit: Int? { layout == .avatar ? 1 : lineLimit } var titleLineLimit: Int? { layout == .avatar ? 1 : lineLimit }
var statusColor: Color { var statusColor: Color {
@@ -86,6 +87,7 @@ public struct ListRowLabel<Icon: View>: View {
var descriptionColor: Color { var descriptionColor: Color {
isEnabled ? .compound.textSecondary : .compound.textDisabled isEnabled ? .compound.textSecondary : .compound.textDisabled
} }
var descriptionLineLimit: Int? { var descriptionLineLimit: Int? {
guard layout == .avatar else { return lineLimit } guard layout == .avatar else { return lineLimit }
return role != .error ? 1 : lineLimit return role != .error ? 1 : lineLimit

View File

@@ -1,4 +1,4 @@
// //
// Copyright 2025 New Vector Ltd // Copyright 2025 New Vector Ltd
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only

View File

@@ -1,4 +1,4 @@
// //
// Copyright 2025 New Vector Ltd // Copyright 2025 New Vector Ltd
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only

View File

@@ -1,4 +1,4 @@
// //
// Copyright 2025 New Vector Ltd // Copyright 2025 New Vector Ltd
// //
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only