Skip to content

Commit

Permalink
Fix "complementaryColor" color isn't changed after updating the appli…
Browse files Browse the repository at this point in the history
…cation theme (#496)
  • Loading branch information
Dolphin54rus authored Sep 5, 2022
1 parent 3688549 commit ca7d2ed
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions SkeletonViewCore/Sources/Internal/Models/SkeletonLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ca7d2ed

Please sign in to comment.