From 35a2e91fb813b1f07824eec37b11cd6dd0d28306 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 8 Feb 2023 18:50:58 +0800 Subject: [PATCH] Fix label color foreground color --- apple/OmnivoreKit/Sources/Utils/ColorUtils.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Utils/ColorUtils.swift b/apple/OmnivoreKit/Sources/Utils/ColorUtils.swift index fa61a9664..bedf74d1a 100644 --- a/apple/OmnivoreKit/Sources/Utils/ColorUtils.swift +++ b/apple/OmnivoreKit/Sources/Utils/ColorUtils.swift @@ -87,13 +87,19 @@ public extension Color { } #endif - let colorR = Double(Int(components[0] * 255)) * 0.2126 - let colorG = Double(Int(components[1] * 255)) * 0.7152 - let colorB = Double(Int(components[2] * 255)) * 0.0722 + let colorR = channelColor(components[0]) * 0.2126 + let colorG = channelColor(components[1]) * 0.7152 + let colorB = channelColor(components[2]) * 0.0722 return Float(colorR + colorG + colorB) } + private func channelColor(_ channel: CGFloat) -> Double { + channel <= 0.03928 + ? channel / 12.92 + : pow((channel + 0.055) / 1.055, 2.4) + } + static var isDarkMode: Bool { #if os(iOS) UITraitCollection.current.userInterfaceStyle == .dark