Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Darkmode #216

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
619cca9
Add new color support for pre ios 13
lkeude96 Oct 13, 2019
af32858
Create System theme
lkeude96 Oct 17, 2019
ca764c1
Applying new bg colors and returning UIColor instead CGColor for traits
lkeude96 Oct 19, 2019
99d8701
Update the CardPartStackView example to use dynamic colors
lkeude96 Oct 30, 2019
be4b147
Update tableview cardpart to use dynamic colors
lkeude96 Oct 30, 2019
e92d118
Update Collectionview example to use dynamic colors
lkeude96 Oct 30, 2019
ec054ec
Update cardpart's pagedview
lkeude96 Oct 30, 2019
f186c4b
Update Barview to use dynamic colors
lkeude96 Oct 30, 2019
a5a67a1
Update border colors to be dynamic, started on shadows as well
lkeude96 Oct 30, 2019
50581b1
Update PillLabel example to use dynamic colors
lkeude96 Oct 30, 2019
6efe5ed
Update rounded stackview example to use dynamic colors
lkeude96 Oct 30, 2019
a8c0865
Update iconlabel card example to use dynamic colors
lkeude96 Oct 30, 2019
8935c90
Update Progress bar view to use dynamic colors
lkeude96 Oct 30, 2019
3e27d41
Update fullscreen vc to use theme's bgColor
lkeude96 Oct 30, 2019
8b50193
Update confetti view 's default colors to use dynamic color
lkeude96 Oct 30, 2019
53f469b
Add custom theme, remove turbo / mint reference and cleanup
lkeude96 Oct 30, 2019
9dd7f43
Add dynamic colors for confetti
lkeude96 Oct 30, 2019
e013f7e
Update radioButton card to use dynamic colors
lkeude96 Oct 30, 2019
fd1ba75
Update tableview cell's test to use dynamic colors instead
lkeude96 Oct 31, 2019
5f19002
Merge branch 'master' into dark-mode
croossin Nov 12, 2019
cfe5770
Update where we override apply the custom themes
lkeude96 Nov 19, 2019
73cd9fd
Merge conflicts
croossin Jan 7, 2020
8dc2474
Remove background on image to support darkmode
croossin Jan 7, 2020
adca0a1
More dark mode cleanup for attributedtext
croossin Jan 7, 2020
6a2c87f
Working on attributedtext dark mode
croossin Jan 10, 2020
57d6cce
Merge branch 'master' into darkmode
croossin Jan 10, 2020
e61e47e
Merge conflicts
croossin Jan 22, 2020
45fabd5
Update README with darkmode
croossin Jan 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public class CardPartAttributedTextView: UIView, CardPartView {
textView.translatesAutoresizingMaskIntoConstraints = false
textView.textContainer.lineBreakMode = NSLineBreakMode.byWordWrapping
textView.isScrollEnabled = false
textView.textColor = textColor
textView.text = text
textView.backgroundColor = CardParts.theme.attributedTextBackgroundColor
textView.isEditable = false
self.textView.isSelectable = textView.isSelectable
self.isEditable = textView.isEditable
Expand All @@ -185,6 +186,7 @@ public class CardPartAttributedTextView: UIView, CardPartView {

addSubview(textView)
setDefaultsForType(type)
setNeedsUpdateConstraints()
}

required public init?(coder: NSCoder) {
Expand Down
9 changes: 6 additions & 3 deletions CardParts/src/Classes/Card Parts/CardPartBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ public class CardPartBarView: UIView, CardPartView {

backgroundLayer = CALayer()
backgroundLayer.anchorPoint = .zero
backgroundLayer.backgroundColor = CardParts.theme.barBackgroundColor.cgColor

barLayer = CALayer()
barLayer.anchorPoint = .zero

verticalLine = CALayer()
verticalLine.anchorPoint = .zero
verticalLine.backgroundColor = CardParts.theme.todayLineColor.cgColor

self.layer.addSublayer(backgroundLayer)
self.layer.addSublayer(barLayer)
Expand Down Expand Up @@ -78,24 +76,29 @@ public class CardPartBarView: UIView, CardPartView {
override public var intrinsicContentSize: CGSize {
return CGSize(width: UIView.noIntrinsicMetric, height: 18.0)
}
public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
updateBarLayer()
}

fileprivate func updateBarLayer() {

let desiredHeight = self.barHeight ?? CGFloat(0.75 * self.bounds.height)

let bounds = CGRect(x: 0, y: 0, width: CGFloat(percent) * self.bounds.width , height: desiredHeight)
barLayer.bounds = bounds
barLayer.backgroundColor = barColor.cgColor
barLayer.backgroundColor = barColor.cgColor(with: traitCollection)
if CardParts.theme.roundedCorners {
barLayer.cornerRadius = bounds.height / 2
}

let backgroundBounds = CGRect(x: 0, y: 0, width: self.bounds.width , height: desiredHeight)
backgroundLayer.bounds = backgroundBounds
backgroundLayer.backgroundColor = CardParts.theme.barBackgroundColor.cgColor(with: traitCollection)
if CardParts.theme.roundedCorners {
backgroundLayer.cornerRadius = bounds.height / 2
}

verticalLine.backgroundColor = CardParts.theme.todayLineColor.cgColor(with: traitCollection)
if CardParts.theme.showTodayLine {
let verticalLineBounds = CGRect(x: 0, y: 0, width: 1.0 , height: self.bounds.height)
verticalLine.bounds = verticalLineBounds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ open class CardPartCollectionViewCardPartsCell : UICollectionViewCell {
private var rightTopConstraint: NSLayoutConstraint!
private var leftTopConstraint: NSLayoutConstraint!

public var borderColor = UIColor.SystemGray6 {
didSet {
layer.borderColor = borderColor.cgColor
}
}

private var cardParts:[CardPartView] = []

override public init(frame: CGRect) {
Expand All @@ -28,6 +34,10 @@ open class CardPartCollectionViewCardPartsCell : UICollectionViewCell {
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
layer.borderColor = borderColor.cgColor(with: traitCollection)
}

public func setupCardParts(_ cardParts:[CardPartView]) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum ConfettiType {
public class CardPartConfettiView: UIView, CardPartView {

public var margins: UIEdgeInsets = CardParts.theme.cardPartMargins
public var colors:[UIColor] = [ UIColor.red, UIColor.green, UIColor.blue ]
public var colors:[UIColor] = [ UIColor.SystemRed, UIColor.SystemGreen, UIColor.SystemBlue ]
public var type:ConfettiType = .star
/// default : 0.5 value ranges from 0 - 1(being very slow)
public var intensity:Float = 0.5
Expand Down
4 changes: 2 additions & 2 deletions CardParts/src/Classes/Card Parts/CardPartPagedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class CardPartPagedView: UIView, CardPartView {

pageControl = UIPageControl(frame: .zero)
pageControl.translatesAutoresizingMaskIntoConstraints = false
pageControl.pageIndicatorTintColor = UIColor.lightGray
pageControl.currentPageIndicatorTintColor = UIColor.darkGray
pageControl.pageIndicatorTintColor = UIColor.SystemFill
pageControl.currentPageIndicatorTintColor = UIColor.SystemGray

currentPage = 0

Expand Down
14 changes: 5 additions & 9 deletions CardParts/src/Classes/Card Parts/CardPartProgressBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,16 @@ public class CardPartProgressBarView: UIView, CardPartView {
}
}

public var bgColor: UIColor = UIColor.white {
public var bgColor: UIColor = .clear {
didSet {
addMarker(marker: customMarker)
layoutSubviews()
}
}

public var markerColor: UIColor? = UIColor.Black {
public var markerColor: UIColor = UIColor.Label {
didSet {
if markerColor != nil {
layout()
}
layout()
}
}

Expand Down Expand Up @@ -315,14 +313,12 @@ public class CardPartProgressBarView: UIView, CardPartView {


fileprivate func addMarker(marker: UIView?) {
let color: UIColor = UIColor.black

if let marker = marker {
self.markerView.addSubview(marker)
} else {
let triangleView = CardPartTriangleView(frame: CGRect(x: 0, y: 0, width: markerHeight, height: markerHeight))
triangleView.fillColor = color
triangleView.backgroundColor = .white
triangleView.fillColor = markerColor
triangleView.backgroundColor = bgColor
self.markerView.addSubview(triangleView)
}
layoutSubviews()
Expand Down
13 changes: 9 additions & 4 deletions CardParts/src/Classes/Card Parts/CardPartRadioButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public class CardPartRadioButton: UIButton, CardPartView {
var outerCircleLayer = CAShapeLayer()
var innerCircleLayer = CAShapeLayer()

public var outerCircleColor:UIColor = .blue {
public var outerCircleColor:UIColor = .SystemBlue {
didSet{
outerCircleLayer.strokeColor = outerCircleColor.cgColor
outerCircleLayer.strokeColor = outerCircleColor.cgColor(with: traitCollection)
}
}

public var innerCircleColor:UIColor = .blue {
public var innerCircleColor:UIColor = .SystemBlue {
didSet {
setFillState()
}
Expand Down Expand Up @@ -85,10 +85,15 @@ public class CardPartRadioButton: UIButton, CardPartView {
super.layoutSubviews()
setCircleLayouts()
}

public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
outerCircleLayer.strokeColor = outerCircleColor.cgColor(with: traitCollection)
setFillState()
}

/// fills the color inside the button based the selected state.
private func setFillState() {
innerCircleLayer.fillColor = self.isSelected ? outerCircleColor.cgColor : UIColor.clear.cgColor
innerCircleLayer.fillColor = self.isSelected ? outerCircleColor.cgColor(with: traitCollection) : UIColor.clear.cgColor
}

/// configures outer/inner circle frame,line widt and path
Expand Down
2 changes: 1 addition & 1 deletion CardParts/src/Classes/Card Parts/CardPartTableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class CardPartTableView : UIView, CardPartView, UITableViewDelegate {
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.register(CardPartTableViewCell.self, forCellReuseIdentifier: kDefaultCellId)
tableView.isScrollEnabled = false
tableView.separatorColor = UIColor.turboSeperatorColor
tableView.separatorColor = CardParts.theme.separatorColor
tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1))

super.init(frame: CGRect.zero)
Expand Down
11 changes: 6 additions & 5 deletions CardParts/src/Classes/Card Parts/CardPartTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ public class CardPartTableViewCell : UITableViewCell {

public var displayAsHidden: Bool = false {
didSet {
leftTitleLabel.textColor = displayAsHidden ? UIColor.Gray2 : leftTitleColor
rightTitleLabel.textColor = displayAsHidden ? UIColor.Gray2 : rightTitleColor
leftDescriptionLabel.textColor = displayAsHidden ? UIColor.Gray2 : leftDescriptionColor
rightDescriptionLabel.textColor = displayAsHidden ? UIColor.Gray2 : rightDescriptionColor
leftTitleLabel.textColor = displayAsHidden ? UIColor.SystemGray2 : leftTitleColor
rightTitleLabel.textColor = displayAsHidden ? UIColor.SystemGray2 : rightTitleColor
leftDescriptionLabel.textColor = displayAsHidden ? UIColor.SystemGray2 : leftDescriptionColor
rightDescriptionLabel.textColor = displayAsHidden ? UIColor.SystemGray2 : rightDescriptionColor

leftTitleLabel.alpha = displayAsHidden ? 0.6 : 1.0
rightTitleLabel.alpha = displayAsHidden ? 0.6 : 1.0
leftDescriptionLabel.alpha = displayAsHidden ? 0.6 : 1.0
rightDescriptionLabel.alpha = displayAsHidden ? 0.6 : 1.0

backgroundColor = displayAsHidden ? UIColor.Gray6 : UIColor.white
backgroundColor = displayAsHidden ? UIColor.SystemGray6 : CardParts.theme.cardBackgroundColor
}
}

Expand Down Expand Up @@ -121,6 +121,7 @@ public class CardPartTableViewCell : UITableViewCell {

separatorInset = UIEdgeInsets.init(top: 0, left: 0, bottom: 0, right: 0)

backgroundColor = CardParts.theme.cardBackgroundColor

for subview in contentView.subviews {
subview.removeFromSuperview()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CardPartTriangleView: UIView,CardPartView {

var margins: UIEdgeInsets = CardParts.theme.cardPartMargins

var fillColor: UIColor = UIColor.white
var fillColor: UIColor = .Label

override init(frame: CGRect) {
super.init(frame: frame)
Expand Down
41 changes: 28 additions & 13 deletions CardParts/src/Classes/CardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ open class CardCell : UICollectionViewCell {

private var currentSize = CGSize.zero
private var gradientLayer = CAGradientLayer()

private var borderColor = CardParts.theme.cardBorderColor {
didSet {
contentView.layer.borderColor = borderColor.cgColor(with: traitCollection)
}
}
private var shadowColor = CardParts.theme.cardShadowColor {
didSet {
contentView.layer.shadowColor = shadowColor.cgColor(with: traitCollection)
}
}

override init(frame: CGRect) {

Expand All @@ -26,18 +37,17 @@ open class CardCell : UICollectionViewCell {

contentView.translatesAutoresizingMaskIntoConstraints = false

contentView.backgroundColor = UIColor.white
contentView.layer.borderColor = UIColor.Gray7.cgColor
contentView.backgroundColor = CardParts.theme.cardBackgroundColor
contentView.layer.borderColor = borderColor.cgColor(with: traitCollection)
contentView.layer.borderWidth = 0.5
if CardParts.theme.cardShadow {
contentView.layer.shadowColor = UIColor.Gray7.cgColor
contentView.layer.shadowColor = shadowColor.cgColor(with: traitCollection)
contentView.layer.shadowOffset = CGSize(width: 0, height: 1)
contentView.layer.shadowRadius = 1.0
contentView.layer.shadowOpacity = 0.9
}

contentView.addSubview(cardContentView)
contentView.backgroundColor = UIColor.white

contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[cardContentView]|",
options: [],
Expand Down Expand Up @@ -111,6 +121,11 @@ open class CardCell : UICollectionViewCell {
return layoutAttributes
}

open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
contentView.layer.borderColor = borderColor.cgColor(with: traitCollection)
contentView.layer.shadowColor = shadowColor.cgColor(with: traitCollection)
}

func requiresNoTopBottomMargins(_ noTopBottomMargins: Bool) {

contentView.removeConstraints(topBottomMarginConstraints)
Expand All @@ -135,27 +150,27 @@ open class CardCell : UICollectionViewCell {
func requiresTransparentCard(transparentCard: Bool) {
if transparentCard {
contentView.backgroundColor = UIColor.clear
contentView.layer.borderColor = UIColor.clear.cgColor
self.borderColor = UIColor.clear
contentView.layer.borderWidth = 0.0
contentView.layer.shadowColor = UIColor.clear.cgColor
self.shadowColor = UIColor.clear
contentView.layer.shadowOffset = CGSize.zero
contentView.layer.shadowRadius = 0.0
contentView.layer.shadowOpacity = 0.0
} else {
contentView.backgroundColor = UIColor.white
contentView.layer.borderColor = UIColor.Gray7.cgColor
contentView.backgroundColor = CardParts.theme.cardBackgroundColor
contentView.layer.borderColor = borderColor.cgColor(with: traitCollection)
contentView.layer.borderWidth = 0.5
if CardParts.theme.cardShadow {
contentView.layer.shadowColor = UIColor.Gray7.cgColor
contentView.layer.shadowColor = shadowColor.cgColor(with: traitCollection)
contentView.layer.shadowOffset = CGSize(width: 0, height: 1)
contentView.layer.shadowRadius = 1.0
contentView.layer.shadowOpacity = 0.9
}
}
}

func addShadowToCard(shadowRadius: CGFloat = 8.0, shadowOpacity: Float = 0.7, shadowColor: CGColor = UIColor.Gray2.cgColor, shadowOffset: CGSize = CGSize(width: 0, height: 5)) {
contentView.layer.shadowColor = shadowColor
func addShadowToCard(shadowRadius: CGFloat = 8.0, shadowOpacity: Float = 0.7, shadowColor: UIColor = UIColor.Gray2, shadowOffset: CGSize = CGSize(width: 0, height: 5)) {
self.shadowColor = shadowColor
contentView.layer.shadowOffset = shadowOffset
contentView.layer.shadowRadius = shadowRadius
contentView.layer.shadowOpacity = shadowOpacity
Expand All @@ -166,9 +181,9 @@ open class CardCell : UICollectionViewCell {
gradientLayer.cornerRadius = radius
}

func addBorderToCard(borderWidth: CGFloat = 0.5, borderColor: CGColor = UIColor.Gray7.cgColor) {
func addBorderToCard(borderWidth: CGFloat = 0.5, borderColor: UIColor = UIColor.SystemGray6) {
self.borderColor = borderColor
contentView.layer.borderWidth = borderWidth
contentView.layer.borderColor = borderColor
}

func addLongGestureRecognizer(minimumPressDuration: CFTimeInterval, delegate: CardPartsLongPressGestureRecognizerDelegate) {
Expand Down
12 changes: 6 additions & 6 deletions CardParts/src/Classes/CardController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public protocol HiddenCardTrait {
}

public protocol ShadowCardTrait {
func shadowColor() -> CGColor
func shadowColor() -> UIColor
func shadowRadius() -> CGFloat
func shadowOpacity() -> Float
func shadowOffset() -> CGSize
}

extension ShadowCardTrait {
func shadowColor() -> CGColor {
return UIColor.Gray2.cgColor
func shadowColor() -> UIColor {
return UIColor.Gray2
}

func shadowRadius() -> CGFloat {
Expand Down Expand Up @@ -111,7 +111,7 @@ extension CardPartsLongPressGestureRecognizerDelegate {

public protocol BorderCardTrait {
func borderWidth() -> CGFloat
func borderColor() -> CGColor
func borderColor() -> UIColor
}

extension BorderCardTrait {
Expand All @@ -120,8 +120,8 @@ extension BorderCardTrait {
return 0.5
}

func borderColor() -> CGColor {
return UIColor.Gray7.cgColor
func borderColor() -> UIColor {
return UIColor.Gray7
}
}

Expand Down
2 changes: 1 addition & 1 deletion CardParts/src/Classes/CardParts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import Foundation

public class CardParts {
public static var theme: CardPartsTheme = CardPartsTurboTheme()
public static var theme: CardPartsTheme = CardPartsSystemTheme()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ open class CardPartsFullScreenViewController: CardPartsViewController {
open override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = UIColor.white
view.backgroundColor = CardParts.theme.backgroundColor
}

}
Loading