From ca7d2edceee613e47b7857029fc82de633460e6f Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 5 Sep 2022 14:26:20 +0700 Subject: [PATCH] Fix "complementaryColor" color isn't changed after updating the application theme (#496) --- .../Internal/Models/SkeletonLayer.swift | 4 ++-- .../UIKitExtensions/CALayer+Extensions.swift | 20 +++++++++++++------ .../UIKitExtensions/UIColor+Skeleton.swift | 8 +++++++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/SkeletonViewCore/Sources/Internal/Models/SkeletonLayer.swift b/SkeletonViewCore/Sources/Internal/Models/SkeletonLayer.swift index f45ad763..e5c5b146 100755 --- a/SkeletonViewCore/Sources/Internal/Models/SkeletonLayer.swift +++ b/SkeletonViewCore/Sources/Internal/Models/SkeletonLayer.swift @@ -28,12 +28,12 @@ struct SkeletonLayer { self.maskLayer.bounds = holder.definedMaxBounds self.maskLayer.cornerRadius = CGFloat(holder.skeletonCornerRadius) addTextLinesIfNeeded() - self.maskLayer.tint(withColors: colors) + self.maskLayer.tint(withColors: colors, traitCollection: holder.traitCollection) } func update(usingColors colors: [UIColor]) { layoutIfNeeded() - maskLayer.tint(withColors: colors) + maskLayer.tint(withColors: colors, traitCollection: holder?.traitCollection) } func layoutIfNeeded() { diff --git a/SkeletonViewCore/Sources/Internal/UIKitExtensions/CALayer+Extensions.swift b/SkeletonViewCore/Sources/Internal/UIKitExtensions/CALayer+Extensions.swift index d29bdd26..fc4bc637 100644 --- a/SkeletonViewCore/Sources/Internal/UIKitExtensions/CALayer+Extensions.swift +++ b/SkeletonViewCore/Sources/Internal/UIKitExtensions/CALayer+Extensions.swift @@ -15,11 +15,15 @@ import UIKit extension CAGradientLayer { - override func tint(withColors colors: [UIColor]) { + override func tint(withColors colors: [UIColor], traitCollection: UITraitCollection?) { skeletonSublayers.recursiveSearch(leafBlock: { - self.colors = colors.map { $0.cgColor } + if #available(iOS 13.0, tvOS 13, *), let traitCollection = traitCollection { + self.colors = colors.map { $0.resolvedColor(with: traitCollection).cgColor } + } else { + self.colors = colors.map { $0.cgColor } + } }) { - $0.tint(withColors: colors) + $0.tint(withColors: colors, traitCollection: traitCollection) } } @@ -35,11 +39,15 @@ extension CALayer { return sublayers?.filter { $0.name == Constants.skeletonSubLayersName } ?? [CALayer]() } - @objc func tint(withColors colors: [UIColor]) { + @objc func tint(withColors colors: [UIColor], traitCollection: UITraitCollection?) { skeletonSublayers.recursiveSearch(leafBlock: { - backgroundColor = colors.first?.cgColor + if #available(iOS 13.0, tvOS 13, *), let traitCollection = traitCollection { + backgroundColor = colors.first?.resolvedColor(with: traitCollection).cgColor + } else { + backgroundColor = colors.first?.cgColor + } }) { - $0.tint(withColors: colors) + $0.tint(withColors: colors, traitCollection: traitCollection) } } diff --git a/SkeletonViewCore/Sources/Internal/UIKitExtensions/UIColor+Skeleton.swift b/SkeletonViewCore/Sources/Internal/UIKitExtensions/UIColor+Skeleton.swift index a219dc65..a222daca 100644 --- a/SkeletonViewCore/Sources/Internal/UIKitExtensions/UIColor+Skeleton.swift +++ b/SkeletonViewCore/Sources/Internal/UIKitExtensions/UIColor+Skeleton.swift @@ -43,7 +43,13 @@ public extension UIColor { } var complementaryColor: UIColor { - isLight ? darker : lighter + if #available(iOS 13, tvOS 13, *) { + return UIColor { _ in + self.isLight ? self.darker : self.lighter + } + } else { + return isLight ? darker : lighter + } } var lighter: UIColor {