Skip to content

Commit

Permalink
Fix dark mode issues with new color system
Browse files Browse the repository at this point in the history
  • Loading branch information
mischreiber committed Nov 8, 2024
1 parent a4abfdb commit 85da707
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 203 deletions.
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

0 comments on commit 85da707

Please sign in to comment.