Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Cleanup color constant usage (#1340)

Leendert de Borst6f89be6980b6
diff --git a/apps/mobile-app/ios/VaultUI/Auth/PinNumpadView.swift b/apps/mobile-app/ios/VaultUI/Auth/PinNumpadView.swift
index 23ee6f7f8..d2ee8e8d7 100644
--- a/apps/mobile-app/ios/VaultUI/Auth/PinNumpadView.swift
+++ b/apps/mobile-app/ios/VaultUI/Auth/PinNumpadView.swift
@@ -2,16 +2,16 @@ import SwiftUI
/// Reusable numpad view component for PIN entry
public struct PinNumpadView: View {
- let theme: Theme
+ let colorScheme: ColorScheme
let onDigit: (String) -> Void
let onBackspace: () -> Void
public init(
- theme: Theme,
+ colorScheme: ColorScheme,
onDigit: @escaping (String) -> Void,
onBackspace: @escaping () -> Void
) {
- self.theme = theme
+ self.colorScheme = colorScheme
self.onDigit = onDigit
self.onBackspace = onBackspace
}
@@ -21,7 +21,7 @@ public struct PinNumpadView: View {
// Row 1: 1-3
HStack(spacing: 12) {
ForEach(1...3, id: \.self) { num in
- NumpadButton(value: "\(num)", theme: theme) {
+ NumpadButton(value: "\(num)", colorScheme: colorScheme) {
onDigit("\(num)")
}
}
@@ -30,7 +30,7 @@ public struct PinNumpadView: View {
// Row 2: 4-6
HStack(spacing: 12) {
ForEach(4...6, id: \.self) { num in
- NumpadButton(value: "\(num)", theme: theme) {
+ NumpadButton(value: "\(num)", colorScheme: colorScheme) {
onDigit("\(num)")
}
}
@@ -39,7 +39,7 @@ public struct PinNumpadView: View {
// Row 3: 7-9
HStack(spacing: 12) {
ForEach(7...9, id: \.self) { num in
- NumpadButton(value: "\(num)", theme: theme) {
+ NumpadButton(value: "\(num)", colorScheme: colorScheme) {
onDigit("\(num)")
}
}
@@ -52,12 +52,12 @@ public struct PinNumpadView: View {
.frame(height: 60)
// 0 button
- NumpadButton(value: "0", theme: theme) {
+ NumpadButton(value: "0", colorScheme: colorScheme) {
onDigit("0")
}
// Backspace button
- NumpadButton(icon: "delete.left", theme: theme) {
+ NumpadButton(icon: "delete.left", colorScheme: colorScheme) {
onBackspace()
}
}
diff --git a/apps/mobile-app/ios/VaultUI/Auth/PinSetupView.swift b/apps/mobile-app/ios/VaultUI/Auth/PinSetupView.swift
index 8793d029c..4047a5bd9 100644
--- a/apps/mobile-app/ios/VaultUI/Auth/PinSetupView.swift
+++ b/apps/mobile-app/ios/VaultUI/Auth/PinSetupView.swift
@@ -13,6 +13,10 @@ public struct PinSetupView: View {
self._viewModel = ObservedObject(wrappedValue: viewModel)
}
+ private var colors: ColorConstants.Colors.Type {
+ ColorConstants.colors(for: colorScheme)
+ }
+
public var body: some View {
GeometryReader { geometry in
ZStack {
@@ -24,7 +28,7 @@ public struct PinSetupView: View {
viewModel.cancel()
}) {
Text(String(localized: "cancel", bundle: locBundle))
- .foregroundColor(theme.primary)
+ .foregroundColor(colors.primary)
}
.padding(.trailing, 20)
}
@@ -43,13 +47,13 @@ public struct PinSetupView: View {
// Title
Text(viewModel.configuration.title)
.font(.system(size: 24, weight: .semibold))
- .foregroundColor(theme.text)
+ .foregroundColor(colors.text)
.padding(.bottom, 8)
// Subtitle
Text(viewModel.configuration.subtitle)
.font(.system(size: 16))
- .foregroundColor(theme.text.opacity(0.7))
+ .foregroundColor(colors.text.opacity(0.7))
.multilineTextAlignment(.center)
.padding(.horizontal, 40)
.padding(.bottom, 32)
@@ -61,12 +65,12 @@ public struct PinSetupView: View {
ForEach(0..<pinLength, id: \.self) { index in
Circle()
.strokeBorder(
- index < viewModel.pin.count ? theme.primary : theme.accentBorder,
+ index < viewModel.pin.count ? colors.primary : colors.accentBorder,
lineWidth: 2
)
.background(
Circle()
- .fill(index < viewModel.pin.count ? theme.primary : Color.clear)
+ .fill(index < viewModel.pin.count ? colors.primary : Color.clear)
)
.frame(width: 16, height: 16)
}
@@ -76,7 +80,7 @@ public struct PinSetupView: View {
// Enter new step: show bullet points for variable length
Text(viewModel.pin.isEmpty ? "----" : String(repeating: "•", count: viewModel.pin.count))
.font(.system(size: 42, weight: .semibold))
- .foregroundColor(theme.text)
+ .foregroundColor(colors.text)
.kerning(8)
.frame(minHeight: 48)
.padding(.bottom, 24)
@@ -86,7 +90,7 @@ public struct PinSetupView: View {
if let error = viewModel.error {
Text(error)
.font(.system(size: 14))
- .foregroundColor(theme.errorBorder)
+ .foregroundColor(.red)
.multilineTextAlignment(.center)
.padding(.horizontal, 40)
.padding(.bottom, 12)
@@ -102,12 +106,12 @@ public struct PinSetupView: View {
}) {
Text(String(localized: "pin_next", bundle: locBundle))
.font(.system(size: 16, weight: .semibold))
- .foregroundColor(theme.primarySurfaceText)
+ .foregroundColor(.white)
.frame(maxWidth: .infinity)
.frame(height: 50)
.background(
RoundedRectangle(cornerRadius: 8)
- .fill(viewModel.canSubmit ? theme.primary : theme.primary.opacity(0.5))
+ .fill(viewModel.canSubmit ? colors.primary : colors.primary.opacity(0.5))
)
}
.disabled(!viewModel.canSubmit)
@@ -119,7 +123,7 @@ public struct PinSetupView: View {
// Numpad
PinNumpadView(
- theme: theme,
+ colorScheme: colorScheme,
onDigit: { digit in
viewModel.addDigit(digit)
},
@@ -129,7 +133,7 @@ public struct PinSetupView: View {
)
}
.frame(width: geometry.size.width, height: geometry.size.height)
- .background(theme.background)
+ .background(colors.background)
.blur(radius: viewModel.isProcessing ? 2 : 0)
.disabled(viewModel.isProcessing)
@@ -140,12 +144,12 @@ public struct PinSetupView: View {
.ignoresSafeArea()
ProgressView()
- .progressViewStyle(CircularProgressViewStyle(tint: theme.primary))
+ .progressViewStyle(CircularProgressViewStyle(tint: colors.primary))
.scaleEffect(1.5)
.padding(24)
.background(
RoundedRectangle(cornerRadius: 16)
- .fill(theme.accentBackground)
+ .fill(colors.accentBackground)
)
.shadow(color: Color.black.opacity(0.2), radius: 10, x: 0, y: 4)
}
@@ -154,8 +158,4 @@ public struct PinSetupView: View {
}
}
}
-
- private var theme: Theme {
- colorScheme == .dark ? Theme.dark : Theme.light
- }
}
diff --git a/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift b/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift
index 5ecf39d75..9fb4ad986 100644
--- a/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift
+++ b/apps/mobile-app/ios/VaultUI/Auth/PinUnlockView.swift
@@ -14,6 +14,10 @@ public struct PinUnlockView: View {
self._viewModel = ObservedObject(wrappedValue: viewModel)
}
+ private var colors: ColorConstants.Colors.Type {
+ ColorConstants.colors(for: colorScheme)
+ }
+
public var body: some View {
GeometryReader { geometry in
ZStack {
@@ -25,7 +29,7 @@ public struct PinUnlockView: View {
viewModel.cancel()
}) {
Text(String(localized: "cancel", bundle: locBundle))
- .foregroundColor(theme.primary)
+ .foregroundColor(colors.primary)
}
.padding(.trailing, 20)
}
@@ -44,13 +48,13 @@ public struct PinUnlockView: View {
// Title
Text(String(localized: "unlock_vault", bundle: locBundle))
.font(.system(size: 24, weight: .semibold))
- .foregroundColor(theme.text)
+ .foregroundColor(colors.text)
.padding(.bottom, 8)
// Subtitle
Text(String(format: String(localized: "enter_pin_to_unlock_vault", bundle: locBundle)))
.font(.system(size: 16))
- .foregroundColor(theme.text.opacity(0.7))
+ .foregroundColor(colors.text.opacity(0.7))
.multilineTextAlignment(.center)
.padding(.horizontal, 40)
.padding(.bottom, 32)
@@ -61,12 +65,12 @@ public struct PinUnlockView: View {
ForEach(0..<pinLength, id: \.self) { index in
Circle()
.strokeBorder(
- index < viewModel.pin.count ? theme.primary : theme.accentBorder,
+ index < viewModel.pin.count ? colors.primary : colors.accentBorder,
lineWidth: 2
)
.background(
Circle()
- .fill(index < viewModel.pin.count ? theme.primary : Color.clear)
+ .fill(index < viewModel.pin.count ? colors.primary : Color.clear)
)
.frame(width: 16, height: 16)
}
@@ -76,7 +80,7 @@ public struct PinUnlockView: View {
// For variable length, show bullet points
Text(viewModel.pin.isEmpty ? "----" : String(repeating: "•", count: viewModel.pin.count))
.font(.system(size: 42, weight: .semibold))
- .foregroundColor(theme.text)
+ .foregroundColor(colors.text)
.kerning(8)
.frame(minHeight: 48)
.padding(.bottom, 24)
@@ -86,7 +90,7 @@ public struct PinUnlockView: View {
if let error = viewModel.error {
Text(error)
.font(.system(size: 14))
- .foregroundColor(theme.errorBorder)
+ .foregroundColor(.red)
.multilineTextAlignment(.center)
.padding(.horizontal, 40)
.padding(.bottom, 12)
@@ -97,7 +101,7 @@ public struct PinUnlockView: View {
// Numpad
PinNumpadView(
- theme: theme,
+ colorScheme: colorScheme,
onDigit: { digit in
viewModel.addDigit(digit)
},
@@ -107,7 +111,7 @@ public struct PinUnlockView: View {
)
}
.frame(width: geometry.size.width, height: geometry.size.height)
- .background(theme.background)
+ .background(colors.background)
.blur(radius: viewModel.isUnlocking ? 2 : 0)
.disabled(viewModel.isUnlocking)
@@ -118,12 +122,12 @@ public struct PinUnlockView: View {
.ignoresSafeArea()
ProgressView()
- .progressViewStyle(CircularProgressViewStyle(tint: theme.primary))
+ .progressViewStyle(CircularProgressViewStyle(tint: colors.primary))
.scaleEffect(1.5)
.padding(24)
.background(
RoundedRectangle(cornerRadius: 16)
- .fill(theme.accentBackground)
+ .fill(colors.accentBackground)
)
.shadow(color: Color.black.opacity(0.2), radius: 10, x: 0, y: 4)
}
@@ -132,57 +136,57 @@ public struct PinUnlockView: View {
}
}
}
-
- private var theme: Theme {
- colorScheme == .dark ? Theme.dark : Theme.light
- }
}
/// Numpad button component
struct NumpadButton: View {
let value: String?
let icon: String?
- let theme: Theme
+ let colorScheme: ColorScheme
let action: () -> Void
@State private var isPressed = false
- init(value: String, theme: Theme, action: @escaping () -> Void) {
+ init(value: String, colorScheme: ColorScheme, action: @escaping () -> Void) {
self.value = value
self.icon = nil
- self.theme = theme
+ self.colorScheme = colorScheme
self.action = action
}
- init(icon: String, theme: Theme, action: @escaping () -> Void) {
+ init(icon: String, colorScheme: ColorScheme, action: @escaping () -> Void) {
self.value = nil
self.icon = icon
- self.theme = theme
+ self.colorScheme = colorScheme
self.action = action
}
+ private var colors: ColorConstants.Colors.Type {
+ ColorConstants.colors(for: colorScheme)
+ }
+
var body: some View {
Button(action: {
action()
}) {
ZStack {
RoundedRectangle(cornerRadius: 12)
- .fill(theme.accentBackground)
+ .fill(colors.accentBackground)
// Highlight overlay when pressed
if isPressed {
RoundedRectangle(cornerRadius: 12)
- .fill(theme.primary.opacity(0.2))
+ .fill(colors.primary.opacity(0.2))
}
if let value = value {
Text(value)
.font(.system(size: 24, weight: .semibold))
- .foregroundColor(theme.text)
+ .foregroundColor(colors.text)
} else if let icon = icon {
Image(systemName: icon)
.font(.system(size: 24))
- .foregroundColor(theme.text)
+ .foregroundColor(colors.text)
}
}
.frame(height: 60)
@@ -205,39 +209,6 @@ struct NumpadButtonStyle: ButtonStyle {
}
}
-// MARK: - Theme
-
-/// Theme colors matching the React Native app
-public struct Theme {
- let background: Color
- let text: Color
- let primary: Color
- let primarySurfaceText: Color
- let accentBackground: Color
- let accentBorder: Color
- let errorBorder: Color
-
- static let light = Theme(
- background: Color(UIColor.systemBackground),
- text: Color(UIColor.label),
- primary: ColorConstants.Light.primary,
- primarySurfaceText: Color.white,
- accentBackground: Color(UIColor.secondarySystemBackground),
- accentBorder: Color(UIColor.separator),
- errorBorder: Color.red
- )
-
- static let dark = Theme(
- background: Color(UIColor.systemBackground),
- text: Color(UIColor.label),
- primary: ColorConstants.Dark.primary,
- primarySurfaceText: Color.white,
- accentBackground: Color(UIColor.secondarySystemBackground),
- accentBorder: Color(UIColor.separator),
- errorBorder: Color.red
- )
-}
-
// MARK: - ViewModel
/// ViewModel for PIN unlock
diff --git a/apps/mobile-app/ios/VaultUI/ColorConstants.swift b/apps/mobile-app/ios/VaultUI/ColorConstants.swift
index 9198b1a29..dd5643c20 100644
--- a/apps/mobile-app/ios/VaultUI/ColorConstants.swift
+++ b/apps/mobile-app/ios/VaultUI/ColorConstants.swift
@@ -4,31 +4,55 @@ import SwiftUI
public struct ColorConstants {
/// Light mode colors
public struct Light {
- static let text = SwiftUI.Color(hex: "#11181C")
- static let textMuted = SwiftUI.Color(hex: "#4b5563")
- static let background = SwiftUI.Color(hex: "#f3f4f6")
- static let accentBackground = SwiftUI.Color(hex: "#ffffff")
- static let accentBorder = SwiftUI.Color(hex: "#d1d5db")
- static let primary = SwiftUI.Color(hex: "#f49541")
- static let secondary = SwiftUI.Color(hex: "#6b7280")
- static let tertiary = SwiftUI.Color(hex: "#eabf69")
- static let icon = SwiftUI.Color(hex: "#687076")
+ public static let text = SwiftUI.Color(hex: "#11181C")
+ public static let textMuted = SwiftUI.Color(hex: "#4b5563")
+ public static let background = SwiftUI.Color(hex: "#f3f4f6")
+ public static let accentBackground = SwiftUI.Color(hex: "#ffffff")
+ public static let accentBorder = SwiftUI.Color(hex: "#d1d5db")
+ public static let primary = SwiftUI.Color(hex: "#f49541")
+ public static let secondary = SwiftUI.Color(hex: "#6b7280")
+ public static let tertiary = SwiftUI.Color(hex: "#eabf69")
+ public static let icon = SwiftUI.Color(hex: "#687076")
}
/// Dark mode colors
public struct Dark {
- static let text = SwiftUI.Color(hex: "#ECEDEE")
- static let textMuted = SwiftUI.Color(hex: "#9BA1A6")
- static let background = SwiftUI.Color(hex: "#000000")
- static let accentBackground = SwiftUI.Color(hex: "#202020")
- static let accentBorder = SwiftUI.Color(hex: "#444444")
- static let primary = SwiftUI.Color(hex: "#f49541")
- static let secondary = SwiftUI.Color(hex: "#6b7280")
- static let tertiary = SwiftUI.Color(hex: "#eabf69")
- static let icon = SwiftUI.Color(hex: "#9BA1A6")
+ public static let text = SwiftUI.Color(hex: "#ECEDEE")
+ public static let textMuted = SwiftUI.Color(hex: "#9BA1A6")
+ public static let background = SwiftUI.Color(hex: "#000000")
+ public static let accentBackground = SwiftUI.Color(hex: "#202020")
+ public static let accentBorder = SwiftUI.Color(hex: "#444444")
+ public static let primary = SwiftUI.Color(hex: "#f49541")
+ public static let secondary = SwiftUI.Color(hex: "#6b7280")
+ public static let tertiary = SwiftUI.Color(hex: "#eabf69")
+ public static let icon = SwiftUI.Color(hex: "#9BA1A6")
+ }
+
+ /// Get colors for the specified color scheme
+ /// - Parameter colorScheme: The current color scheme
+ /// - Returns: The appropriate color constants (Light or Dark)
+ public static func colors(for colorScheme: ColorScheme) -> Colors.Type {
+ colorScheme == .dark ? Dark.self : Light.self
+ }
+
+ /// Protocol to enable generic access to color properties
+ public protocol Colors {
+ static var text: Color { get }
+ static var textMuted: Color { get }
+ static var background: Color { get }
+ static var accentBackground: Color { get }
+ static var accentBorder: Color { get }
+ static var primary: Color { get }
+ static var secondary: Color { get }
+ static var tertiary: Color { get }
+ static var icon: Color { get }
}
}
+// Conform Light and Dark to the Colors protocol
+extension ColorConstants.Light: ColorConstants.Colors {}
+extension ColorConstants.Dark: ColorConstants.Colors {}
+
// Add Color extension for hex support
extension SwiftUI.Color {
init(hex: String) {