Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose configurable theme colors through ThemeManager for client cust… #181

Closed
wants to merge 3 commits into from
Closed
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
99 changes: 99 additions & 0 deletions Sources/FaceLiveness/ThemeManager.swift
Original file line number Diff line number Diff line change
@@ -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...
}
6 changes: 3 additions & 3 deletions Sources/FaceLiveness/Utilities/Color+DynamicColors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
)
Expand Down
93 changes: 49 additions & 44 deletions Sources/FaceLiveness/Utilities/Color+Liveness.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down