Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Vault/Sources/VaultFeed/Models/VaultItemColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ struct HOTPCodePreviewView<ButtonView: View>: 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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct TOTPCodePreviewView<TimerBar: View>: View {
case .visible, .locked:
timerView
case .finished, .notReady, .obfuscated:
Color.gray
Color(.quaternarySystemFill)
.redacted(reason: .placeholder)
case .error:
Color.red
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct OTPWidgetAccessoryRectangularView: View {
)
.progressViewStyle(.linear)
case .hotp, .unavailable, .placeholder:
Color.gray.opacity(0.3).clipShape(Capsule())
Color(.quaternarySystemFill).clipShape(Capsule())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct OTPWidgetSmallView: View {
.progressViewStyle(.linear)
.tint(.accentColor)
case .hotp, .unavailable, .placeholder:
Color.gray.opacity(0.3)
Color(.quaternarySystemFill)
}
}

Expand Down
59 changes: 59 additions & 0 deletions Vault/Tests/VaultFeedTests/Models/VaultItemColorTests.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"colors" : [
{
"color" : {
"platform" : "universal",
"reference" : "systemBlueColor"
},
"idiom" : "universal"
}
],
Expand Down

This file was deleted.