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

Fix dark mode issues with new color system #2105

Merged
merged 1 commit into from
Nov 8, 2024
Merged
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
24 changes: 24 additions & 0 deletions Sources/FluentUI_iOS/Core/Extensions/Color+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,34 @@ extension Color {
darkElevated: Color? = nil) {

let dynamicColor = DynamicColor(light: light, dark: dark, darkElevated: darkElevated)
self.init(dynamicColor: dynamicColor)
}

/// Creates a custom `Color` from a prebuilt `DynamicColor` structure.
///
/// - Parameter dynamicColor: A dynmic color structure that describes the `Color` to be created.
init(dynamicColor: DynamicColor) {
if #available(iOS 17, *) {
self.init(dynamicColor)
} else {
self.init(uiColor: UIColor(dynamicColor: dynamicColor))
}
}

var dynamicColor: DynamicColor {
if #available(iOS 17, *) {
var lightEnvironment = EnvironmentValues.init()
lightEnvironment.colorScheme = .light

var darkEnvironment = EnvironmentValues.init()
darkEnvironment.colorScheme = .dark

return DynamicColor(light: Color(self.resolve(in: lightEnvironment)),
dark: Color(self.resolve(in: darkEnvironment)))
} else {
let uiColor = UIColor(self)
return DynamicColor(light: Color(uiColor.light),
dark: Color(uiColor.dark))
}
}
}
Loading
Loading