Skip to content

Commit

Permalink
Make skeleton colors dynamic
Browse files Browse the repository at this point in the history
If on iOS 13 or higher, returns a UIColor using the
`init(dynamicProvider:)` initializer so it automatically adjusts to
dark mode. Also switches out the `clouds` default color with the
dynamic `skeletonDefault` color.
  • Loading branch information
WilsonGramer committed Oct 14, 2019
1 parent e097385 commit 8095440
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Sources/Appearance/SkeletonAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public enum SkeletonAppearance {
class SkeletonViewAppearance: Appearance {
static var shared = SkeletonViewAppearance()

var tintColor: UIColor = .clouds
var tintColor: UIColor = .skeletonDefault

var gradient: SkeletonGradient = SkeletonGradient(baseColor: .clouds)
var gradient: SkeletonGradient = SkeletonGradient(baseColor: .skeletonDefault)

var multilineHeight: CGFloat = 15

Expand Down
22 changes: 21 additions & 1 deletion Sources/Extensions/UIColor+Skeleton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ extension UIColor {
}

public var complementaryColor: UIColor {
return isLight() ? darker : lighter
if #available(iOS 13, *) {
return UIColor { traitCollection in
return self.isLight() ? self.darker : self.lighter
}
} else {
return isLight() ? darker : lighter
}
}

public var lighter: UIColor {
Expand Down Expand Up @@ -58,11 +64,25 @@ public extension UIColor {
static var carrot = UIColor(0xe67e22)
static var alizarin = UIColor(0xe74c3c)
static var clouds = UIColor(0xecf0f1)
static var darkClouds = UIColor(0x1c2325)
static var concrete = UIColor(0x95a5a6)
static var flatOrange = UIColor(0xf39c12)
static var pumpkin = UIColor(0xd35400)
static var pomegranate = UIColor(0xc0392b)
static var silver = UIColor(0xbdc3c7)
static var asbestos = UIColor(0x7f8c8d)

static var skeletonDefault: UIColor {
if #available(iOS 13, *) {
return UIColor { traitCollection in
switch traitCollection.userInterfaceStyle {
case .dark: return .darkClouds
default: return .clouds
}
}
} else {
return .clouds
}
}
}
// codebeat:enable[TOO_MANY_IVARS]

0 comments on commit 8095440

Please sign in to comment.