From 831223a78c85b775d7ce6d36d17bfb7972622238 Mon Sep 17 00:00:00 2001 From: hunble Date: Thu, 7 Nov 2024 15:00:06 +0500 Subject: [PATCH 1/2] Expose configurable theme colors through ThemeManager for client customization - Added ThemeManager class with functions to customize theme colors such as primary background, label, error background, and more. - Updated Color extension to pull dynamic color values from ThemeManager. - Allow client apps to modify theme colors by calling functions like `setLivenessPrimaryBackground()`, `setLivenessPrimaryLabel()`, etc. - Provides flexibility for client apps to modify color schemes based on their requirements. --- Sources/FaceLiveness/ThemeManager.swift | 99 +++++++++++++++++++ .../Utilities/Color+Liveness.swift | 93 ++++++++--------- .../Views/Instruction/InstructionView.swift | 2 +- 3 files changed, 149 insertions(+), 45 deletions(-) create mode 100644 Sources/FaceLiveness/ThemeManager.swift diff --git a/Sources/FaceLiveness/ThemeManager.swift b/Sources/FaceLiveness/ThemeManager.swift new file mode 100644 index 00000000..4176613f --- /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: UIColor, dark: UIColor) { + livenessPrimaryBackground = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessPrimaryLabel(light: UIColor, dark: UIColor) { + livenessPrimaryLabel = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessBackground(light: UIColor, dark: UIColor) { + livenessBackground = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessLabel(light: UIColor, dark: UIColor) { + livenessLabel = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessErrorBackground(light: UIColor, dark: UIColor) { + livenessErrorBackground = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessErrorLabel(light: UIColor, dark: UIColor) { + livenessErrorLabel = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessWarningBackground(light: UIColor, dark: UIColor) { + livenessWarningBackground = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessWarningLabel(light: UIColor, dark: UIColor) { + livenessWarningLabel = Color.dynamicColors(light: light, dark: dark) + } + + public func setLivenessPreviewBorder(light: UIColor, dark: UIColor) { + livenessPreviewBorder = Color.dynamicColors(light: light, dark: dark) + } + // Add similar functions for other colors as needed... +} 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 { From d5343225e808ff72f257a9072ddcd3b32921d437 Mon Sep 17 00:00:00 2001 From: hunble Date: Thu, 7 Nov 2024 15:00:06 +0500 Subject: [PATCH 2/2] Expose configurable theme colors through ThemeManager for client customization - Added ThemeManager class with functions to customize theme colors such as primary background, label, error background, and more. - Updated Color extension to pull dynamic color values from ThemeManager. - Allow client apps to modify theme colors by calling functions like `setLivenessPrimaryBackground()`, `setLivenessPrimaryLabel()`, etc. - Provides flexibility for client apps to modify color schemes based on their requirements. --- Sources/FaceLiveness/ThemeManager.swift | 18 +++++++++--------- .../Utilities/Color+DynamicColors.swift | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/FaceLiveness/ThemeManager.swift b/Sources/FaceLiveness/ThemeManager.swift index 4176613f..630debc1 100644 --- a/Sources/FaceLiveness/ThemeManager.swift +++ b/Sources/FaceLiveness/ThemeManager.swift @@ -60,39 +60,39 @@ public class ThemeManager { extension ThemeManager { // Public functions to modify the colors - public func setLivenessPrimaryBackground(light: UIColor, dark: UIColor) { + public func setLivenessPrimaryBackground(light: Color, dark: Color) { livenessPrimaryBackground = Color.dynamicColors(light: light, dark: dark) } - public func setLivenessPrimaryLabel(light: UIColor, dark: UIColor) { + public func setLivenessPrimaryLabel(light: Color, dark: Color) { livenessPrimaryLabel = Color.dynamicColors(light: light, dark: dark) } - public func setLivenessBackground(light: UIColor, dark: UIColor) { + public func setLivenessBackground(light: Color, dark: Color) { livenessBackground = Color.dynamicColors(light: light, dark: dark) } - public func setLivenessLabel(light: UIColor, dark: UIColor) { + public func setLivenessLabel(light: Color, dark: Color) { livenessLabel = Color.dynamicColors(light: light, dark: dark) } - public func setLivenessErrorBackground(light: UIColor, dark: UIColor) { + public func setLivenessErrorBackground(light: Color, dark: Color) { livenessErrorBackground = Color.dynamicColors(light: light, dark: dark) } - public func setLivenessErrorLabel(light: UIColor, dark: UIColor) { + public func setLivenessErrorLabel(light: Color, dark: Color) { livenessErrorLabel = Color.dynamicColors(light: light, dark: dark) } - public func setLivenessWarningBackground(light: UIColor, dark: UIColor) { + public func setLivenessWarningBackground(light: Color, dark: Color) { livenessWarningBackground = Color.dynamicColors(light: light, dark: dark) } - public func setLivenessWarningLabel(light: UIColor, dark: UIColor) { + public func setLivenessWarningLabel(light: Color, dark: Color) { livenessWarningLabel = Color.dynamicColors(light: light, dark: dark) } - public func setLivenessPreviewBorder(light: UIColor, dark: UIColor) { + 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) } } )