Customizable color for disabled navigation bar buttons

This commit is contained in:
Ilya Laktyushin 2018-10-06 00:49:03 +03:00
parent 2e9350d717
commit b3a1027822
6 changed files with 43 additions and 15 deletions

View File

@ -104,7 +104,7 @@ enum DeviceMetrics {
case .iPhone4, .iPhone5:
return 37.0
case .iPhone6, .iPhoneX:
return 42.0
return 44.0
case .iPhone6Plus:
return 42.0
case .iPhoneXSMax:

View File

@ -20,7 +20,7 @@ public protocol ListViewItemHeader: class {
open class ListViewItemHeaderNode: ASDisplayNode {
private final var spring: ListViewItemSpring?
let wantsScrollDynamics: Bool
open private(set) var wantsScrollDynamics: Bool
let isRotated: Bool
final private(set) var internalStickLocationDistanceFactor: CGFloat = 0.0
final var internalStickLocationDistance: CGFloat = 0.0

View File

@ -94,7 +94,7 @@ open class ListViewItemNode: ASDisplayNode {
private final var spring: ListViewItemSpring?
private final var animations: [(String, ListViewAnimation)] = []
final let wantsScrollDynamics: Bool
open private(set) var wantsScrollDynamics: Bool
public final var wantsTrailingItemSpaceUpdates: Bool = false
@ -178,14 +178,10 @@ open class ListViewItemNode: ASDisplayNode {
}
public init(layerBacked: Bool, dynamicBounce: Bool = true, rotated: Bool = false, seeThrough: Bool = false) {
if true {
if dynamicBounce {
self.spring = ListViewItemSpring(stiffness: -280.0, damping: -24.0, mass: 0.85)
}
self.wantsScrollDynamics = dynamicBounce
} else {
self.wantsScrollDynamics = false
if dynamicBounce {
self.spring = ListViewItemSpring(stiffness: -280.0, damping: -24.0, mass: 0.85)
}
self.wantsScrollDynamics = dynamicBounce
self.rotated = rotated
@ -198,7 +194,7 @@ open class ListViewItemNode: ASDisplayNode {
} else {
super.init()
self.setViewBlock({
self.setViewBlock({
return CASeeThroughTracingView()
})
}

View File

@ -9,7 +9,7 @@ public class NavigationBackButtonNode: ASControlNode {
private func attributesForCurrentState() -> [NSAttributedStringKey : AnyObject] {
return [
NSAttributedStringKey.font: self.fontForCurrentState(),
NSAttributedStringKey.foregroundColor: self.isEnabled ? self.color : UIColor.gray
NSAttributedStringKey.foregroundColor: self.isEnabled ? self.color : self.disabledColor
]
}
@ -36,6 +36,12 @@ public class NavigationBackButtonNode: ASControlNode {
}
}
public var disabledColor: UIColor = UIColor(rgb: 0xd0d0d0) {
didSet {
self.label.attributedText = NSAttributedString(string: self._text, attributes: self.attributesForCurrentState())
}
}
private var touchCount = 0
var pressed: () -> () = {}

View File

@ -16,6 +16,7 @@ public final class NavigationBarTheme {
}
public let buttonColor: UIColor
public let disabledButtonColor: UIColor
public let primaryTextColor: UIColor
public let backgroundColor: UIColor
public let separatorColor: UIColor
@ -23,8 +24,9 @@ public final class NavigationBarTheme {
public let badgeStrokeColor: UIColor
public let badgeTextColor: UIColor
public init(buttonColor: UIColor, primaryTextColor: UIColor, backgroundColor: UIColor, separatorColor: UIColor, badgeBackgroundColor: UIColor, badgeStrokeColor: UIColor, badgeTextColor: UIColor) {
public init(buttonColor: UIColor, disabledButtonColor: UIColor, primaryTextColor: UIColor, backgroundColor: UIColor, separatorColor: UIColor, badgeBackgroundColor: UIColor, badgeStrokeColor: UIColor, badgeTextColor: UIColor) {
self.buttonColor = buttonColor
self.disabledButtonColor = disabledButtonColor
self.primaryTextColor = primaryTextColor
self.backgroundColor = backgroundColor
self.separatorColor = separatorColor
@ -34,7 +36,7 @@ public final class NavigationBarTheme {
}
public func withUpdatedSeparatorColor(_ color: UIColor) -> NavigationBarTheme {
return NavigationBarTheme(buttonColor: self.buttonColor, primaryTextColor: self.primaryTextColor, backgroundColor: self.backgroundColor, separatorColor: color, badgeBackgroundColor: self.badgeBackgroundColor, badgeStrokeColor: self.badgeStrokeColor, badgeTextColor: self.badgeTextColor)
return NavigationBarTheme(buttonColor: self.buttonColor, disabledButtonColor: self.disabledButtonColor, primaryTextColor: self.primaryTextColor, backgroundColor: self.backgroundColor, separatorColor: color, badgeBackgroundColor: self.badgeBackgroundColor, badgeStrokeColor: self.badgeStrokeColor, badgeTextColor: self.badgeTextColor)
}
}
@ -606,8 +608,11 @@ open class NavigationBar: ASDisplayNode {
self.clippingNode.clipsToBounds = true
self.backButtonNode.color = self.presentationData.theme.buttonColor
self.backButtonNode.disabledColor = self.presentationData.theme.disabledButtonColor
self.leftButtonNode.color = self.presentationData.theme.buttonColor
self.leftButtonNode.disabledColor = self.presentationData.theme.disabledButtonColor
self.rightButtonNode.color = self.presentationData.theme.buttonColor
self.rightButtonNode.disabledColor = self.presentationData.theme.disabledButtonColor
self.backButtonArrow.image = backArrowImage(color: self.presentationData.theme.buttonColor)
if let title = self.title {
self.titleNode.attributedText = NSAttributedString(string: title, font: Font.semibold(17.0), textColor: self.presentationData.theme.primaryTextColor)
@ -676,8 +681,11 @@ open class NavigationBar: ASDisplayNode {
self.backgroundColor = self.presentationData.theme.backgroundColor
self.backButtonNode.color = self.presentationData.theme.buttonColor
self.backButtonNode.disabledColor = self.presentationData.theme.disabledButtonColor
self.leftButtonNode.color = self.presentationData.theme.buttonColor
self.leftButtonNode.disabledColor = self.presentationData.theme.disabledButtonColor
self.rightButtonNode.color = self.presentationData.theme.buttonColor
self.rightButtonNode.disabledColor = self.presentationData.theme.disabledButtonColor
self.backButtonArrow.image = backArrowImage(color: self.presentationData.theme.buttonColor)
if let title = self.title {
self.titleNode.attributedText = NSAttributedString(string: title, font: Font.semibold(17.0), textColor: self.presentationData.theme.primaryTextColor)

View File

@ -9,7 +9,7 @@ private final class NavigationButtonItemNode: ASTextNode {
private func attributesForCurrentState() -> [NSAttributedStringKey : AnyObject] {
return [
NSAttributedStringKey.font: self.fontForCurrentState(),
NSAttributedStringKey.foregroundColor: self.isEnabled ? self.color : UIColor.gray
NSAttributedStringKey.foregroundColor: self.isEnabled ? self.color : self.disabledColor
]
}
@ -93,6 +93,14 @@ private final class NavigationButtonItemNode: ASTextNode {
}
}
public var disabledColor: UIColor = UIColor(rgb: 0xd0d0d0) {
didSet {
if let text = self._text {
self.attributedText = NSAttributedString(string: text, attributes: self.attributesForCurrentState())
}
}
}
private var _bold: Bool = false
public var bold: Bool {
get {
@ -229,6 +237,16 @@ final class NavigationButtonNode: ASDisplayNode {
}
}
public var disabledColor: UIColor = UIColor(rgb: 0xd0d0d0) {
didSet {
if !self.disabledColor.isEqual(oldValue) {
for node in self.nodes {
node.disabledColor = self.disabledColor
}
}
}
}
override init() {
super.init()
}