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)
.frame(maxWidth: .infinity, alignment: .leading)
.padding([.leading, .top])
.padding(.leading )
.padding(.leading)
}
}
}

View File

@@ -1,4 +1,4 @@
//
//
// Copyright 2024 New Vector Ltd
//
// 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]()
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.
@@ -47,16 +47,17 @@ public class CompoundColors {
self.tokens = tokens
decorativeColors = [
.init(background: tokens.bgDecorative1, text: tokens.textDecorative1),
.init(background: tokens.bgDecorative2, text: tokens.textDecorative2),
.init(background: tokens.bgDecorative3, text: tokens.textDecorative3),
.init(background: tokens.bgDecorative4, text: tokens.textDecorative4),
.init(background: tokens.bgDecorative5, text: tokens.textDecorative5),
.init(background: tokens.bgDecorative6, text: tokens.textDecorative6),
]
.init(background: tokens.bgDecorative1, text: tokens.textDecorative1),
.init(background: tokens.bgDecorative2, text: tokens.textDecorative2),
.init(background: tokens.bgDecorative3, text: tokens.textDecorative3),
.init(background: tokens.bgDecorative4, text: tokens.textDecorative4),
.init(background: tokens.bgDecorative5, text: tokens.textDecorative5),
.init(background: tokens.bgDecorative6, text: tokens.textDecorative6)
]
}
// MARK: - Decorative Colors
// Used to determine the background and text colors of avatars, usernames etc.
let decorativeColors: [DecorativeColor]
@@ -67,6 +68,7 @@ public class CompoundColors {
// MARK: - Awaiting Semantic Tokens
// swiftformat:disable numberFormatting
/// This token is a placeholder and hasn't been finalised.
@available(iOS, deprecated: 100000.0, message: "This token should be generated by now.")
public let _borderTextFieldFocused = coreTokens.gray500
@@ -91,6 +93,7 @@ public class CompoundColors {
/// This token is a placeholder and hasn't been finalised.
@available(iOS, deprecated: 100000.0, message: "This token should be generated by now.")
public let _bgEmptyItemAlpha = coreTokens.alphaGray500
// swiftformat:enable numberFormatting
}
private extension UITraitCollection {
@@ -107,9 +110,9 @@ private extension String {
/// 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
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)
}
return (characterCodeSum % Color.compound.decorativeColors.count)
return characterCodeSum % Color.compound.decorativeColors.count
}
}

View File

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

View File

@@ -28,7 +28,7 @@ public class CompoundUIColors {
private var overrides = [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.
@@ -39,12 +39,14 @@ public class CompoundUIColors {
// MARK: - Awaiting Semantic Tokens
// swiftformat:disable numberFormatting
/// This token is a placeholder and hasn't been finalised.
@available(iOS, deprecated: 100000.0, message: "This token should be generated by now.")
public let _bgCodeBlock = coreTokens.gray100
/// This token is a placeholder and hasn't been finalised.
@available(iOS, deprecated: 100000.0, message: "This token should be generated by now.")
public let _bgSubtleSecondaryAlpha = coreTokens.alphaGray300
// swiftformat:enable numberFormatting
}
private extension UITraitCollection {

View File

@@ -52,8 +52,8 @@ public struct CompoundIcon: View {
/// - icon: The icon to show.
public init(_ icon: KeyPath<CompoundIcons, Image>) {
image = .compound[keyPath: icon]
self.size = .medium
self.font = .compound.bodyLG
size = .medium
font = .compound.bodyLG
}
/// 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.
public init(customImage: Image) {
image = customImage
self.size = .medium
self.font = .compound.bodyLG
size = .medium
font = .compound.bodyLG
}
/// 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 {
Grid(alignment: .leading) {
ForEach(DynamicTypeSize.allCases, id: \.self) {

View File

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

View File

@@ -18,13 +18,13 @@ struct ListInlinePicker<SelectedValue: Hashable>: View {
ListRow(label: .plain(title: item.title),
details: isWaiting ? .isWaiting(selection == item.tag) : nil,
kind: .selection(isSelected: !isWaiting ? selection == item.tag : false) {
var transaction = Transaction()
transaction.disablesAnimations = true
var transaction = Transaction()
transaction.disablesAnimations = true
withTransaction(transaction) {
selection = item.tag
}
})
withTransaction(transaction) {
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.
public extension ListRow where Icon == EmptyView, DetailsIcon == EmptyView {
init(kind: Kind<CustomContent, SelectionValue>) {
self.label = ListRowLabel()
self.details = nil
label = ListRowLabel()
details = nil
self.kind = kind
}
init(kind: Kind<CustomContent, SelectionValue>) where SelectionValue == String {
self.label = ListRowLabel()
self.details = nil
label = ListRowLabel()
details = nil
self.kind = kind
}
}
@@ -249,6 +249,7 @@ private extension Button {
// MARK: - Previews
// swiftlint:disable print_deprecation
public struct ListRow_Previews: PreviewProvider, TestablePreview {
public static var previews: some View {
Form {
@@ -348,14 +349,14 @@ public struct ListRow_Previews: PreviewProvider, TestablePreview {
systemIcon: .squareDashed),
details: .title("Content"),
kind: .selection(isSelected: true) {
print("I was tapped!")
})
print("I was tapped!")
})
ListRow(label: .default(title: "Title",
systemIcon: .squareDashed),
details: .title("Content"),
kind: .selection(isSelected: true) {
print("I was tapped!")
})
print("I was tapped!")
})
ListRow(label: .plain(title: "Title"),
kind: .inlinePicker(selection: .constant("Item 1"),
@@ -375,7 +376,7 @@ public struct ListRow_Previews: PreviewProvider, TestablePreview {
ListRow(label: .action(title: "Title",
systemIcon: .squareDashed),
kind: .button { print("I was tapped!") })
.disabled(true)
.disabled(true)
}
static var plainButton: some View {
@@ -401,7 +402,7 @@ public struct ListRow_Previews: PreviewProvider, TestablePreview {
ListRow(label: .centeredAction(title: "Title",
systemIcon: .squareDashed),
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"),
kind: .textField(text: .constant("This is a disabled text field")))
.disabled(true)
.disabled(true)
ListRow(label: .plain(title: "Placeholder"),
kind: .textField(text: .constant(""), axis: .vertical))
.lineLimit(4...)
.lineLimit(4...)
ListRow(label: .plain(title: "Password"),
kind: .secureField(text: .constant("p4ssw0rd")))
}
@@ -474,3 +475,5 @@ struct ListRowLoadingSelection_Previews: PreviewProvider, TestablePreview {
.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.
public static var navigationLink: Self {
Self.init(kind: .navigationLink)
Self(kind: .navigationLink)
}
/// A checkmark (or reserved space) to indicate that the row is selected.
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.
public static func multiSelection(_ isSelected: Bool) -> Self {
Self.init(kind: isSelected ? .multiSelected : .multiUnselected)
Self(kind: isSelected ? .multiSelected : .multiUnselected)
}
let kind: Kind

View File

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

View File

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

View File

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

View File

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

View File

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