diff --git a/Vault/Sources/VaultFeed/Models/VaultItemColor.swift b/Vault/Sources/VaultFeed/Models/VaultItemColor.swift index cb9227680..7bf240f08 100644 --- a/Vault/Sources/VaultFeed/Models/VaultItemColor.swift +++ b/Vault/Sources/VaultFeed/Models/VaultItemColor.swift @@ -57,8 +57,8 @@ extension VaultItemColor { // Standard brightness components for each channel, based on the human eye. VaultItemColor( red: (red + amount * 0.299).clamped(to: 0 ... 1), - green: (blue + amount * 0.114).clamped(to: 0 ... 1), - blue: (green + amount * 0.587).clamped(to: 0 ... 1), + green: (green + amount * 0.587).clamped(to: 0 ... 1), + blue: (blue + amount * 0.114).clamped(to: 0 ... 1), ) } } diff --git a/Vault/Sources/VaultiOS/Views/Previews/OTP/HOTPCodePreviewView.swift b/Vault/Sources/VaultiOS/Views/Previews/OTP/HOTPCodePreviewView.swift index 9635b1fba..5466319eb 100644 --- a/Vault/Sources/VaultiOS/Views/Previews/OTP/HOTPCodePreviewView.swift +++ b/Vault/Sources/VaultiOS/Views/Previews/OTP/HOTPCodePreviewView.swift @@ -49,14 +49,14 @@ struct HOTPCodePreviewView: View { case .normal: switch previewViewModel.code { case .visible, .locked: - Color.blue + Color.accentColor case .notReady, .obfuscated: - Color.gray + Color(.quaternarySystemFill) case .error, .finished: Color.red } case .editingState: - Color.blue + Color.accentColor } } diff --git a/Vault/Sources/VaultiOS/Views/Previews/OTP/TOTPCodePreviewView.swift b/Vault/Sources/VaultiOS/Views/Previews/OTP/TOTPCodePreviewView.swift index 19f0d89a4..fd9094a9e 100644 --- a/Vault/Sources/VaultiOS/Views/Previews/OTP/TOTPCodePreviewView.swift +++ b/Vault/Sources/VaultiOS/Views/Previews/OTP/TOTPCodePreviewView.swift @@ -106,7 +106,7 @@ struct TOTPCodePreviewView: View { case .visible, .locked: timerView case .finished, .notReady, .obfuscated: - Color.gray + Color(.quaternarySystemFill) .redacted(reason: .placeholder) case .error: Color.red diff --git a/Vault/Sources/VaultiOSWidgets/Views/OTPWidgetAccessoryRectangularView.swift b/Vault/Sources/VaultiOSWidgets/Views/OTPWidgetAccessoryRectangularView.swift index 01781f299..223015720 100644 --- a/Vault/Sources/VaultiOSWidgets/Views/OTPWidgetAccessoryRectangularView.swift +++ b/Vault/Sources/VaultiOSWidgets/Views/OTPWidgetAccessoryRectangularView.swift @@ -39,7 +39,7 @@ struct OTPWidgetAccessoryRectangularView: View { ) .progressViewStyle(.linear) case .hotp, .unavailable, .placeholder: - Color.gray.opacity(0.3).clipShape(Capsule()) + Color(.quaternarySystemFill).clipShape(Capsule()) } } diff --git a/Vault/Sources/VaultiOSWidgets/Views/OTPWidgetSmallView.swift b/Vault/Sources/VaultiOSWidgets/Views/OTPWidgetSmallView.swift index 73ae90164..ae928b87e 100644 --- a/Vault/Sources/VaultiOSWidgets/Views/OTPWidgetSmallView.swift +++ b/Vault/Sources/VaultiOSWidgets/Views/OTPWidgetSmallView.swift @@ -77,7 +77,7 @@ struct OTPWidgetSmallView: View { .progressViewStyle(.linear) .tint(.accentColor) case .hotp, .unavailable, .placeholder: - Color.gray.opacity(0.3) + Color(.quaternarySystemFill) } } diff --git a/Vault/Tests/VaultFeedTests/Models/VaultItemColorTests.swift b/Vault/Tests/VaultFeedTests/Models/VaultItemColorTests.swift new file mode 100644 index 000000000..bb1387a15 --- /dev/null +++ b/Vault/Tests/VaultFeedTests/Models/VaultItemColorTests.swift @@ -0,0 +1,59 @@ +import Foundation +import Testing +@testable import VaultFeed + +struct VaultItemColorTests { + @Test + func brighten_appliesEachChannelsOwnLuminanceWeight() { + let color = VaultItemColor(red: 0.1, green: 0.2, blue: 0.3) + + let result = color.brighten(amount: 1) + + // Each channel is offset by its own coefficient, not another channel's. + #expect(abs(result.red - (0.1 + 0.299)) < 0.0001) + #expect(abs(result.green - (0.2 + 0.587)) < 0.0001) + #expect(abs(result.blue - (0.3 + 0.114)) < 0.0001) + } + + /// Regression cover for a channel swap: `green` was derived from `blue` and `blue` from + /// `green`, so brightening rotated the hue instead of lightening it. + @Test + func brighten_doesNotSwapGreenAndBlue() { + let color = VaultItemColor(red: 0, green: 1, blue: 0) + + let result = color.brighten(amount: 0) + + #expect(result == color) + } + + @Test + func brighten_isMonotonicPerChannel() { + let color = VaultItemColor(red: 0.4, green: 0.4, blue: 0.4) + + let brighter = color.brighten(amount: 0.5) + let darker = color.brighten(amount: -0.5) + + #expect(brighter.red > color.red) + #expect(brighter.green > color.green) + #expect(brighter.blue > color.blue) + #expect(darker.red < color.red) + #expect(darker.green < color.green) + #expect(darker.blue < color.blue) + } + + @Test + func brighten_clampsToUnitRange() { + let light = VaultItemColor(red: 0.95, green: 0.95, blue: 0.95) + let dark = VaultItemColor(red: 0.05, green: 0.05, blue: 0.05) + + let overBright = light.brighten(amount: 5) + let overDark = dark.brighten(amount: -5) + + #expect(overBright.red == 1) + #expect(overBright.green == 1) + #expect(overBright.blue == 1) + #expect(overDark.red == 0) + #expect(overDark.green == 0) + #expect(overDark.blue == 0) + } +} diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/HOTPCodePreviewViewSnapshotTests/layout_codeNotReady.1.png b/Vault/Tests/VaultiOSTests/__Snapshots__/HOTPCodePreviewViewSnapshotTests/layout_codeNotReady.1.png index c094ecc27..a192053cd 100644 Binary files a/Vault/Tests/VaultiOSTests/__Snapshots__/HOTPCodePreviewViewSnapshotTests/layout_codeNotReady.1.png and b/Vault/Tests/VaultiOSTests/__Snapshots__/HOTPCodePreviewViewSnapshotTests/layout_codeNotReady.1.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/TOTPCodePreviewViewSnapshotTests/layout_codeNotReady.1.png b/Vault/Tests/VaultiOSTests/__Snapshots__/TOTPCodePreviewViewSnapshotTests/layout_codeNotReady.1.png index a20ca5916..926723876 100644 Binary files a/Vault/Tests/VaultiOSTests/__Snapshots__/TOTPCodePreviewViewSnapshotTests/layout_codeNotReady.1.png and b/Vault/Tests/VaultiOSTests/__Snapshots__/TOTPCodePreviewViewSnapshotTests/layout_codeNotReady.1.png differ diff --git a/Vault/Tests/VaultiOSTests/__Snapshots__/TOTPCodePreviewViewSnapshotTests/layout_noMoreCodes.1.png b/Vault/Tests/VaultiOSTests/__Snapshots__/TOTPCodePreviewViewSnapshotTests/layout_noMoreCodes.1.png index a20ca5916..926723876 100644 Binary files a/Vault/Tests/VaultiOSTests/__Snapshots__/TOTPCodePreviewViewSnapshotTests/layout_noMoreCodes.1.png and b/Vault/Tests/VaultiOSTests/__Snapshots__/TOTPCodePreviewViewSnapshotTests/layout_noMoreCodes.1.png differ diff --git a/VaultApp/VaultWidgets/Assets.xcassets/AccentColor.colorset/Contents.json b/VaultApp/VaultWidgets/Assets.xcassets/AccentColor.colorset/Contents.json index eb8789700..611286920 100644 --- a/VaultApp/VaultWidgets/Assets.xcassets/AccentColor.colorset/Contents.json +++ b/VaultApp/VaultWidgets/Assets.xcassets/AccentColor.colorset/Contents.json @@ -1,6 +1,10 @@ { "colors" : [ { + "color" : { + "platform" : "universal", + "reference" : "systemBlueColor" + }, "idiom" : "universal" } ], diff --git a/VaultApp/VaultWidgets/Assets.xcassets/WidgetBackground.colorset/Contents.json b/VaultApp/VaultWidgets/Assets.xcassets/WidgetBackground.colorset/Contents.json deleted file mode 100644 index eb8789700..000000000 --- a/VaultApp/VaultWidgets/Assets.xcassets/WidgetBackground.colorset/Contents.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "colors" : [ - { - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -}