Skip to content

Commit

Permalink
Merge pull request #17 from andreyoshev/master
Browse files Browse the repository at this point in the history
Hard support for old iOS versions
  • Loading branch information
subdan authored Aug 20, 2020
2 parents 900db38 + 3720d50 commit cd3c47b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions Sources/XcodeExport/XcodeColorExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,16 @@ final public class XcodeColorExporter {
if let darkComponents = colorPair.dark?.toRgbComponents() {
contents.append("""
static var \(colorPair.light.name): UIColor {
UIColor { traitCollection -> UIColor in
if traitCollection.userInterfaceStyle == .dark {
return UIColor(red: \(darkComponents.red), green: \(darkComponents.green), blue: \(darkComponents.blue), alpha: \(darkComponents.alpha))
} else {
return UIColor(red: \(lightComponents.red), green: \(lightComponents.green), blue: \(lightComponents.blue), alpha: \(lightComponents.alpha))
if #available(iOS 13.0, *) {
UIColor { traitCollection -> UIColor in
if traitCollection.userInterfaceStyle == .dark {
return UIColor(red: \(darkComponents.red), green: \(darkComponents.green), blue: \(darkComponents.blue), alpha: \(darkComponents.alpha))
} else {
return UIColor(red: \(lightComponents.red), green: \(lightComponents.green), blue: \(lightComponents.blue), alpha: \(lightComponents.alpha))
}
}
} else {
return UIColor(red: \(lightComponents.red), green: \(lightComponents.green), blue: \(lightComponents.blue), alpha: \(lightComponents.alpha))
}
}\n
""")
Expand Down
14 changes: 9 additions & 5 deletions Tests/XcodeExportTests/XcodeColorExporterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ final class XcodeColorExporterTests: XCTestCase {
extension UIColor {
static var colorPair1: UIColor {
UIColor { traitCollection -> UIColor in
if traitCollection.userInterfaceStyle == .dark {
return UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 1.000)
} else {
return UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)
if #available(iOS 13.0, *) {
UIColor { traitCollection -> UIColor in
if traitCollection.userInterfaceStyle == .dark {
return UIColor(red: 0.000, green: 0.000, blue: 0.000, alpha: 1.000)
} else {
return UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)
}
}
} else {
return UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)
}
}
static var colorPair2: UIColor {
Expand Down

0 comments on commit cd3c47b

Please sign in to comment.