From d5343225e808ff72f257a9072ddcd3b32921d437 Mon Sep 17 00:00:00 2001 From: hunble Date: Thu, 7 Nov 2024 15:00:06 +0500 Subject: [PATCH] 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) } } )