From 9fb0e1112480150f65ea72f7d84b6aceb912a594 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Thu, 7 Apr 2022 13:30:18 -0700 Subject: [PATCH] udpate text chip colors --- apple/OmnivoreKit/Sources/Utils/ColorUtils.swift | 12 ++++++++++-- apple/OmnivoreKit/Sources/Views/TextChip.swift | 8 ++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Utils/ColorUtils.swift b/apple/OmnivoreKit/Sources/Utils/ColorUtils.swift index 7718fbf88..2c20306f6 100644 --- a/apple/OmnivoreKit/Sources/Utils/ColorUtils.swift +++ b/apple/OmnivoreKit/Sources/Utils/ColorUtils.swift @@ -45,8 +45,7 @@ public extension Color { } private func toHex() -> String? { - let uic = UIColor(self) - guard let components = uic.cgColor.components, components.count >= 3 else { + guard let components = UIColor(self).cgColor.components, components.count >= 3 else { return nil } let red = Float(components[0]) @@ -60,4 +59,13 @@ public extension Color { lroundf(blue * 255) ) } + + var isDark: Bool { + guard let components = UIColor(self).cgColor.components, components.count >= 3 else { + return false + } + + let lum = 0.2126 * Float(components[0]) + 0.7152 * Float(components[1]) + 0.0722 * Float(components[2]) + return lum < 0.50 + } } diff --git a/apple/OmnivoreKit/Sources/Views/TextChip.swift b/apple/OmnivoreKit/Sources/Views/TextChip.swift index b25bb7c94..cb55573e8 100644 --- a/apple/OmnivoreKit/Sources/Views/TextChip.swift +++ b/apple/OmnivoreKit/Sources/Views/TextChip.swift @@ -24,13 +24,9 @@ public struct TextChip: View { .padding(.horizontal, 10) .padding(.vertical, 5) .font(.appFootnote) - .foregroundColor(color) + .foregroundColor(color.isDark ? .white : .black) .lineLimit(1) - .background(color.opacity(0.1)) + .background(color) .cornerRadius(cornerRadius) - .overlay( - RoundedRectangle(cornerRadius: cornerRadius) - .stroke(color.opacity(0.3), lineWidth: 1) - ) } }