Skip to content

Commit ca7d2ed

Browse files
authored
Fix "complementaryColor" color isn't changed after updating the application theme (#496)
1 parent 3688549 commit ca7d2ed

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

SkeletonViewCore/Sources/Internal/Models/SkeletonLayer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ struct SkeletonLayer {
2828
self.maskLayer.bounds = holder.definedMaxBounds
2929
self.maskLayer.cornerRadius = CGFloat(holder.skeletonCornerRadius)
3030
addTextLinesIfNeeded()
31-
self.maskLayer.tint(withColors: colors)
31+
self.maskLayer.tint(withColors: colors, traitCollection: holder.traitCollection)
3232
}
3333

3434
func update(usingColors colors: [UIColor]) {
3535
layoutIfNeeded()
36-
maskLayer.tint(withColors: colors)
36+
maskLayer.tint(withColors: colors, traitCollection: holder?.traitCollection)
3737
}
3838

3939
func layoutIfNeeded() {

SkeletonViewCore/Sources/Internal/UIKitExtensions/CALayer+Extensions.swift

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ import UIKit
1515

1616
extension CAGradientLayer {
1717

18-
override func tint(withColors colors: [UIColor]) {
18+
override func tint(withColors colors: [UIColor], traitCollection: UITraitCollection?) {
1919
skeletonSublayers.recursiveSearch(leafBlock: {
20-
self.colors = colors.map { $0.cgColor }
20+
if #available(iOS 13.0, tvOS 13, *), let traitCollection = traitCollection {
21+
self.colors = colors.map { $0.resolvedColor(with: traitCollection).cgColor }
22+
} else {
23+
self.colors = colors.map { $0.cgColor }
24+
}
2125
}) {
22-
$0.tint(withColors: colors)
26+
$0.tint(withColors: colors, traitCollection: traitCollection)
2327
}
2428
}
2529

@@ -35,11 +39,15 @@ extension CALayer {
3539
return sublayers?.filter { $0.name == Constants.skeletonSubLayersName } ?? [CALayer]()
3640
}
3741

38-
@objc func tint(withColors colors: [UIColor]) {
42+
@objc func tint(withColors colors: [UIColor], traitCollection: UITraitCollection?) {
3943
skeletonSublayers.recursiveSearch(leafBlock: {
40-
backgroundColor = colors.first?.cgColor
44+
if #available(iOS 13.0, tvOS 13, *), let traitCollection = traitCollection {
45+
backgroundColor = colors.first?.resolvedColor(with: traitCollection).cgColor
46+
} else {
47+
backgroundColor = colors.first?.cgColor
48+
}
4149
}) {
42-
$0.tint(withColors: colors)
50+
$0.tint(withColors: colors, traitCollection: traitCollection)
4351
}
4452
}
4553

SkeletonViewCore/Sources/Internal/UIKitExtensions/UIColor+Skeleton.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ public extension UIColor {
4343
}
4444

4545
var complementaryColor: UIColor {
46-
isLight ? darker : lighter
46+
if #available(iOS 13, tvOS 13, *) {
47+
return UIColor { _ in
48+
self.isLight ? self.darker : self.lighter
49+
}
50+
} else {
51+
return isLight ? darker : lighter
52+
}
4753
}
4854

4955
var lighter: UIColor {

0 commit comments

Comments
 (0)