diff --git a/Sources/FaceLiveness/ThemeManager.swift b/Sources/FaceLiveness/ThemeManager.swift new file mode 100644 index 00000000..630debc1 --- /dev/null +++ b/Sources/FaceLiveness/ThemeManager.swift @@ -0,0 +1,99 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// +import SwiftUI + +public class ThemeManager { + public static var shared = ThemeManager() + + // Public properties with default values + public var livenessPrimaryBackground = Color.dynamicColors( + light: .hex("#047D95"), + dark: .hex("#7DD6E8") + ) + + public var livenessPrimaryLabel = Color.dynamicColors( + light: .white, + dark: .hex("#0D1926") + ) + + public var livenessBackground = Color.dynamicColors( + light: .white, + dark: .hex("#0D1926") + ) + + public var livenessLabel = Color.dynamicColors( + light: .black, + dark: .white + ) + + public var livenessErrorBackground = Color.dynamicColors( + light: .hex("#950404"), + dark: .hex("#EF8F8F") + ) + + public var livenessErrorLabel = Color.dynamicColors( + light: .white, + dark: .black + ) + + public var livenessWarningBackground = Color.dynamicColors( + light: .hex("#B8CEF9"), + dark: .hex("#663300") + ) + + public var livenessWarningLabel = Color.dynamicColors( + light: .hex("#002266"), + dark: .hex("#EFBF8F") + ) + + public var livenessPreviewBorder = Color.dynamicColors( + light: .hex("#AEB3B7"), + dark: .white + ) +} + + +extension ThemeManager { + + // Public functions to modify the colors + public func setLivenessPrimaryBackground(light: Color, dark: Color) { + livenessPrimaryBackground = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessPrimaryLabel(light: Color, dark: Color) { + livenessPrimaryLabel = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessBackground(light: Color, dark: Color) { + livenessBackground = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessLabel(light: Color, dark: Color) { + livenessLabel = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessErrorBackground(light: Color, dark: Color) { + livenessErrorBackground = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessErrorLabel(light: Color, dark: Color) { + livenessErrorLabel = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessWarningBackground(light: Color, dark: Color) { + livenessWarningBackground = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessWarningLabel(light: Color, dark: Color) { + livenessWarningLabel = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessPreviewBorder(light: Color, dark: Color) { + livenessPreviewBorder = Color.dynamicColors(light: light, dark: dark) + } + // Add similar functions for other colors as needed... +} diff --git a/Sources/FaceLiveness/Utilities/Color+DynamicColors.swift b/Sources/FaceLiveness/Utilities/Color+DynamicColors.swift index 63896981..1818c80d 100644 --- a/Sources/FaceLiveness/Utilities/Color+DynamicColors.swift +++ b/Sources/FaceLiveness/Utilities/Color+DynamicColors.swift @@ -9,13 +9,13 @@ import UIKit import SwiftUI extension Color { - static func dynamicColors(light: UIColor, dark: UIColor) -> Color { + static func dynamicColors(light: Color, dark: Color) -> Color { Color( UIColor( dynamicProvider: { traitCollection in switch traitCollection.userInterfaceStyle { - case .dark: return dark - default: return light + case .dark: return UIColor(dark) + default: return UIColor(light) } } ) diff --git a/Sources/FaceLiveness/Utilities/Color+Liveness.swift b/Sources/FaceLiveness/Utilities/Color+Liveness.swift index 6d998b58..e54b4817 100644 --- a/Sources/FaceLiveness/Utilities/Color+Liveness.swift +++ b/Sources/FaceLiveness/Utilities/Color+Liveness.swift @@ -5,51 +5,56 @@ // SPDX-License-Identifier: Apache-2.0 // +// sample Usage +// import AmplifyUILiveness + +// Modify colors in the client app +// ThemeManager.shared.setLivenessPrimaryBackground( +// light: .red, // Example light color +// dark: .blue // Example dark color +// ) + +// Access modified color +// let modifiedColor = Color.livenessPrimaryBackground + + import SwiftUI extension Color { - static let livenessPrimaryBackground = Color.dynamicColors( - light: .hex("#047D95"), - dark: .hex("#7DD6E8") - ) - - static let livenessPrimaryLabel = Color.dynamicColors( - light: .white, - dark: .hex("#0D1926") - ) - - static let livenessBackground = Color.dynamicColors( - light: .white, - dark: .hex("#0D1926") - ) - - static let livenessLabel = Color.dynamicColors( - light: .black, - dark: .white - ) - - static let livenessErrorBackground = Color.dynamicColors( - light: .hex("#950404"), - dark: .hex("#EF8F8F") - ) - - static let livenessErrorLabel = Color.dynamicColors( - light: .white, - dark: .black - ) - - static let livenessWarningBackground = Color.dynamicColors( - light: .hex("#B8CEF9"), - dark: .hex("#663300") - ) - - static let livenessWarningLabel = Color.dynamicColors( - light: .hex("#002266"), - dark: .hex("#EFBF8F") - ) - - static let livenessPreviewBorder = Color.dynamicColors( - light: .hex("#AEB3B7"), - dark: .white - ) + public static var livenessPrimaryBackground: Color { + return ThemeManager.shared.livenessPrimaryBackground + } + + public static var livenessPrimaryLabel: Color { + return ThemeManager.shared.livenessPrimaryLabel + } + + public static var livenessBackground: Color { + return ThemeManager.shared.livenessBackground + } + + public static var livenessLabel: Color { + return ThemeManager.shared.livenessLabel + } + + public static var livenessErrorBackground: Color { + return ThemeManager.shared.livenessErrorBackground + } + + public static var livenessErrorLabel: Color { + return ThemeManager.shared.livenessErrorLabel + } + + public static var livenessWarningBackground: Color { + return ThemeManager.shared.livenessWarningBackground + } + + public static var livenessWarningLabel: Color { + return ThemeManager.shared.livenessWarningLabel + } + + public static var livenessPreviewBorder: Color { + return ThemeManager.shared.livenessPreviewBorder + } } + diff --git a/Sources/FaceLiveness/Views/Instruction/InstructionView.swift b/Sources/FaceLiveness/Views/Instruction/InstructionView.swift index 5311387b..1799b07b 100644 --- a/Sources/FaceLiveness/Views/Instruction/InstructionView.swift +++ b/Sources/FaceLiveness/Views/Instruction/InstructionView.swift @@ -10,7 +10,7 @@ import SwiftUI struct InstructionView: View { let text: String let backgroundColor: Color - var textColor: Color = .livenessLabel + var textColor: Color = Color.livenessLabel var font: Font = .body var body: some View {