Skip to content

Commit

Permalink
introduce gracefully degrading abstractions for dark mode for ios and… (
Browse files Browse the repository at this point in the history
#4171)

* introduce gracefully degrading abstractions for dark mode for ios and macos and use them to draw text

* it's .labelColor not .label on NSColor
  • Loading branch information
motocodeltd authored and jjatie committed Oct 28, 2019
1 parent 25c0742 commit a5fda8f
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ for index in 0..<ITEM_COUNT
//: ### BubbleChartDataSet
let set = BubbleChartDataSet(values: entries, label: "Bubble DataSet")
set.colors = ChartColorTemplates.vordiplom()
set.valueTextColor = NSUIColor.black
set.valueTextColor = NSUIColor.labelOrBlack
set.valueFont = NSUIFont.systemFont(ofSize: CGFloat(10.0))
set.drawValuesEnabled = true
set.normalizeSizeEnabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ rightAxis.granularityEnabled = false
//: ### Legend
let legend = chartView.legend
legend.font = NSUIFont(name: "HelveticaNeue-Light", size: CGFloat(12.0))!
legend.textColor = NSUIColor.black
legend.textColor = NSUIColor.labelOrBlack
legend.form = .square
legend.drawInside = false
legend.orientation = .horizontal
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
@objc open var noDataFont = NSUIFont.systemFont(ofSize: 12)

/// color of the no data text
@objc open var noDataTextColor: NSUIColor = NSUIColor.black
@objc open var noDataTextColor: NSUIColor = NSUIColor.labelOrBlack

/// alignment of the no data text
@objc open var noDataTextAlignment: NSTextAlignment = .left
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Charts/PieChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ open class PieChartView: PieRadarChartViewBase

attrString = NSMutableAttributedString(string: newValue!)
attrString?.setAttributes([
.foregroundColor: NSUIColor.black,
.foregroundColor: NSUIColor.labelOrBlack,
.font: NSUIFont.systemFont(ofSize: 12.0),
.paragraphStyle: paragraphStyle
], range: NSMakeRange(0, attrString!.length))
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Components/AxisBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open class AxisBase: ComponentBase
private var _axisValueFormatter: IAxisValueFormatter?

@objc open var labelFont = NSUIFont.systemFont(ofSize: 10.0)
@objc open var labelTextColor = NSUIColor.black
@objc open var labelTextColor = NSUIColor.labelOrBlack

@objc open var axisLineColor = NSUIColor.gray
@objc open var axisLineWidth = CGFloat(0.5)
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Components/ChartLimitLine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ open class ChartLimitLine: ComponentBase
@objc open var lineDashPhase = CGFloat(0.0)
@objc open var lineDashLengths: [CGFloat]?

@objc open var valueTextColor = NSUIColor.black
@objc open var valueTextColor = NSUIColor.labelOrBlack
@objc open var valueFont = NSUIFont.systemFont(ofSize: 13.0)

@objc open var drawLabelEnabled = true
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Components/Description.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ open class Description: ComponentBase
@objc open var font: NSUIFont

/// Text color used for drawing the description text
@objc open var textColor = NSUIColor.black
@objc open var textColor = NSUIColor.labelOrBlack
}
2 changes: 1 addition & 1 deletion Source/Charts/Components/Legend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ open class Legend: ComponentBase
@objc open var direction: Direction = Direction.leftToRight

@objc open var font: NSUIFont = NSUIFont.systemFont(ofSize: 10.0)
@objc open var textColor = NSUIColor.black
@objc open var textColor = NSUIColor.labelOrBlack

/// The form/shape of the legend forms
@objc open var form = Form.square
Expand Down
4 changes: 2 additions & 2 deletions Source/Charts/Data/Implementations/ChartBaseDataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ open class ChartBaseDataSet: NSObject, IChartDataSet, NSCopying

// default color
colors.append(NSUIColor(red: 140.0/255.0, green: 234.0/255.0, blue: 255.0/255.0, alpha: 1.0))
valueColors.append(NSUIColor.black)
valueColors.append(NSUIColor.labelOrBlack)
}

@objc public init(label: String?)
Expand All @@ -30,7 +30,7 @@ open class ChartBaseDataSet: NSObject, IChartDataSet, NSCopying

// default color
colors.append(NSUIColor(red: 140.0/255.0, green: 234.0/255.0, blue: 255.0/255.0, alpha: 1.0))
valueColors.append(NSUIColor.black)
valueColors.append(NSUIColor.labelOrBlack)

self.label = label
}
Expand Down
36 changes: 36 additions & 0 deletions Source/Charts/Utils/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ public typealias NSUIScreen = UIScreen

public typealias NSUIDisplayLink = CADisplayLink

private func fetchLabelColor() -> UIColor
{
if #available(iOS 13, tvOS 13, *)
{
return .label
}
else
{
return .black
}
}
private let labelColor: UIColor = fetchLabelColor()

extension UIColor
{
static var labelOrBlack: UIColor { labelColor }
}

extension NSUITapGestureRecognizer
{
@objc final func nsuiNumberOfTouches() -> Int
Expand Down Expand Up @@ -520,6 +538,24 @@ extension NSTouch
}
}

private func fetchLabelColor() -> NSColor
{
if #available(macOS 10.14, *)
{
return .labelColor
}
else
{
return .black
}
}
private let labelColor: NSColor = fetchLabelColor()

extension NSColor
{
static var labelOrBlack: NSColor { labelColor }
}

extension NSScrollView
{
var scrollEnabled: Bool
Expand Down

0 comments on commit a5fda8f

Please sign in to comment.