Commit a0ec4fa2 by Daniel Dahan

development: issue-568: fixed issue where active color was not being updated in TextField

parent dd7019e0
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>2.3.2</string> <string>2.3.3</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
......
...@@ -35,8 +35,8 @@ open class ErrorTextField: TextField { ...@@ -35,8 +35,8 @@ open class ErrorTextField: TextField {
@IBInspectable @IBInspectable
open var isErrorRevealed = false { open var isErrorRevealed = false {
didSet { didSet {
layoutDetailLabel()
detailLabel.isHidden = !isErrorRevealed detailLabel.isHidden = !isErrorRevealed
layoutSubviews()
} }
} }
......
...@@ -103,7 +103,7 @@ open class PageTabBarController: RootController { ...@@ -103,7 +103,7 @@ open class PageTabBarController: RootController {
/// Reference to the PageTabBar. /// Reference to the PageTabBar.
open private(set) lazy var pageTabBar: PageTabBar = PageTabBar() open private(set) lazy var pageTabBar: PageTabBar = PageTabBar()
/// A boolean that indicates whether bounds is enabled. /// A boolean that indicates whether bounce is enabled.
open var isBounceEnabled: Bool { open var isBounceEnabled: Bool {
didSet { didSet {
scrollView?.bounces = isBounceEnabled scrollView?.bounces = isBounceEnabled
......
...@@ -388,56 +388,6 @@ open class TextField: UITextField { ...@@ -388,56 +388,6 @@ open class TextField: UITextField {
layoutShape() layoutShape()
} }
/// Handles the text editing did begin state.
@objc
open func handleEditingDidBegin() {
placeholderEditingDidBeginAnimation()
dividerEditingDidBeginAnimation()
}
// Live updates the textField text.
@objc
internal func handleEditingChanged(textField: UITextField) {
(delegate as? TextFieldDelegate)?.textField?(textField: self, didChange: textField.text)
}
/// Handles the text editing did end state.
@objc
open func handleEditingDidEnd() {
placeholderEditingDidEndAnimation()
dividerEditingDidEndAnimation()
}
/// Handles the clearIconButton TouchUpInside event.
@objc
open func handleClearIconButton() {
guard nil == delegate?.textFieldShouldClear || true == delegate?.textFieldShouldClear?(self) else {
return
}
let t = text
(delegate as? TextFieldDelegate)?.textField?(textField: self, willClear: t)
text = nil
(delegate as? TextFieldDelegate)?.textField?(textField: self, didClear: t)
}
/// Handles the visibilityIconButton TouchUpInside event.
@objc
open func handleVisibilityIconButton() {
isSecureTextEntry = !isSecureTextEntry
if !isSecureTextEntry {
super.font = nil
font = placeholderLabel.font
}
visibilityIconButton?.tintColor = visibilityIconButton?.tintColor.withAlphaComponent(isSecureTextEntry ? 0.38 : 0.54)
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method it is recommended to override the prepare method
...@@ -450,6 +400,7 @@ open class TextField: UITextField { ...@@ -450,6 +400,7 @@ open class TextField: UITextField {
borderStyle = .none borderStyle = .none
backgroundColor = nil backgroundColor = nil
contentScaleFactor = Device.scale contentScaleFactor = Device.scale
prepareDivider() prepareDivider()
preparePlaceholderLabel() preparePlaceholderLabel()
prepareDetailLabel() prepareDetailLabel()
...@@ -459,11 +410,7 @@ open class TextField: UITextField { ...@@ -459,11 +410,7 @@ open class TextField: UITextField {
/// Ensures that the components are sized correctly. /// Ensures that the components are sized correctly.
open func reload() { open func reload() {
guard willLayout else { guard willLayout && !isAnimating else {
return
}
guard !isAnimating else {
return return
} }
...@@ -474,9 +421,70 @@ open class TextField: UITextField { ...@@ -474,9 +421,70 @@ open class TextField: UITextField {
layoutDivider() layoutDivider()
layoutLeftView() layoutLeftView()
} }
}
extension TextField {
/// Prepares the divider.
fileprivate func prepareDivider() {
dividerColor = dividerNormalColor
}
/// Prepares the placeholderLabel.
fileprivate func preparePlaceholderLabel() {
font = RobotoFont.regular(with: 16)
placeholderNormalColor = Color.darkText.others
addSubview(placeholderLabel)
addObserver(self, forKeyPath: "placeholderLabel.text", options: [], context: &TextFieldContext)
}
/// Prepares the detailLabel.
fileprivate func prepareDetailLabel() {
detailLabel.font = RobotoFont.regular(with: 12)
detailLabel.numberOfLines = 0
detailColor = Color.darkText.others
addSubview(detailLabel)
addObserver(self, forKeyPath: "detailLabel.text", options: [], context: &TextFieldContext)
}
/// Prepares the leftView.
fileprivate func prepareLeftView() {
leftView?.contentMode = .left
}
/// Prepares the target handlers.
fileprivate func prepareTargetHandlers() {
addTarget(self, action: #selector(handleEditingDidBegin), for: .editingDidBegin)
addTarget(self, action: #selector(handleEditingChanged), for: .editingChanged)
addTarget(self, action: #selector(handleEditingDidEnd), for: .editingDidEnd)
}
/// Prepares the textAlignment.
fileprivate func prepareTextAlignment() {
textAlignment = .rightToLeft == UIApplication.shared.userInterfaceLayoutDirection ? .right : .left
}
/// Updates the placeholderLabel attributedText.
fileprivate func updatePlaceholderLabelColor() {
guard let v = placeholder else {
return
}
placeholderLabel.textColor = isEditing ? placeholderActiveColor : placeholderNormalColor
}
/// Updates the detailLabel attributedText.
fileprivate func updateDetailLabelColor() {
guard let v = detail else {
return
}
detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor])
}
}
extension TextField {
/// Layout the placeholderLabel. /// Layout the placeholderLabel.
open func layoutPlaceholderLabel() { fileprivate func layoutPlaceholderLabel() {
let w = leftViewWidth let w = leftViewWidth
let h = 0 == height ? intrinsicContentSize.height : height let h = 0 == height ? intrinsicContentSize.height : height
...@@ -501,7 +509,7 @@ open class TextField: UITextField { ...@@ -501,7 +509,7 @@ open class TextField: UITextField {
} }
/// Layout the detailLabel. /// Layout the detailLabel.
open func layoutDetailLabel() { fileprivate func layoutDetailLabel() {
let c = dividerContentEdgeInsets let c = dividerContentEdgeInsets
detailLabel.sizeToFit() detailLabel.sizeToFit()
detailLabel.x = c.left detailLabel.x = c.left
...@@ -510,7 +518,7 @@ open class TextField: UITextField { ...@@ -510,7 +518,7 @@ open class TextField: UITextField {
} }
/// Layout the a button. /// Layout the a button.
open func layoutButton(button: UIButton?) { fileprivate func layoutButton(button: UIButton?) {
guard 0 < width && 0 < height else { guard 0 < width && 0 < height else {
return return
} }
...@@ -519,12 +527,12 @@ open class TextField: UITextField { ...@@ -519,12 +527,12 @@ open class TextField: UITextField {
} }
/// Layout the divider. /// Layout the divider.
open func layoutDivider() { fileprivate func layoutDivider() {
divider.reload() divider.reload()
} }
/// Layout the leftView. /// Layout the leftView.
open func layoutLeftView() { fileprivate func layoutLeftView() {
guard let v = leftView else { guard let v = leftView else {
return return
} }
...@@ -533,21 +541,75 @@ open class TextField: UITextField { ...@@ -533,21 +541,75 @@ open class TextField: UITextField {
v.frame = CGRect(x: 0, y: 0, width: w, height: height) v.frame = CGRect(x: 0, y: 0, width: w, height: height)
dividerContentEdgeInsets.left = w dividerContentEdgeInsets.left = w
} }
}
extension TextField {
/// Handles the text editing did begin state.
@objc
fileprivate func handleEditingDidBegin() {
placeholderEditingDidBeginAnimation()
dividerEditingDidBeginAnimation()
}
// Live updates the textField text.
@objc
fileprivate func handleEditingChanged(textField: UITextField) {
(delegate as? TextFieldDelegate)?.textField?(textField: self, didChange: textField.text)
}
/// Handles the text editing did end state.
@objc
fileprivate func handleEditingDidEnd() {
placeholderEditingDidEndAnimation()
dividerEditingDidEndAnimation()
}
/// Handles the clearIconButton TouchUpInside event.
@objc
fileprivate func handleClearIconButton() {
guard nil == delegate?.textFieldShouldClear || true == delegate?.textFieldShouldClear?(self) else {
return
}
let t = text
(delegate as? TextFieldDelegate)?.textField?(textField: self, willClear: t)
text = nil
(delegate as? TextFieldDelegate)?.textField?(textField: self, didClear: t)
}
/// Handles the visibilityIconButton TouchUpInside event.
@objc
fileprivate func handleVisibilityIconButton() {
isSecureTextEntry = !isSecureTextEntry
if !isSecureTextEntry {
super.font = nil
font = placeholderLabel.font
}
visibilityIconButton?.tintColor = visibilityIconButton?.tintColor.withAlphaComponent(isSecureTextEntry ? 0.38 : 0.54)
}
}
extension TextField {
/// The animation for the divider when editing begins. /// The animation for the divider when editing begins.
open func dividerEditingDidBeginAnimation() { fileprivate func dividerEditingDidBeginAnimation() {
dividerThickness = dividerActiveHeight dividerThickness = dividerActiveHeight
dividerColor = dividerActiveColor dividerColor = dividerActiveColor
} }
/// The animation for the divider when editing ends. /// The animation for the divider when editing ends.
open func dividerEditingDidEndAnimation() { fileprivate func dividerEditingDidEndAnimation() {
dividerThickness = dividerNormalHeight dividerThickness = dividerNormalHeight
dividerColor = dividerNormalColor dividerColor = dividerNormalColor
} }
/// The animation for the placeholder when editing begins. /// The animation for the placeholder when editing begins.
open func placeholderEditingDidBeginAnimation() { fileprivate func placeholderEditingDidBeginAnimation() {
guard isPlaceholderAnimated else { guard isPlaceholderAnimated else {
return return
} }
...@@ -556,6 +618,8 @@ open class TextField: UITextField { ...@@ -556,6 +618,8 @@ open class TextField: UITextField {
return return
} }
updatePlaceholderLabelColor()
isAnimating = true isAnimating = true
UIView.animate(withDuration: 0.15, animations: { [weak self] in UIView.animate(withDuration: 0.15, animations: { [weak self] in
guard let s = self else { guard let s = self else {
...@@ -579,7 +643,7 @@ open class TextField: UITextField { ...@@ -579,7 +643,7 @@ open class TextField: UITextField {
} }
/// The animation for the placeholder when editing ends. /// The animation for the placeholder when editing ends.
open func placeholderEditingDidEndAnimation() { fileprivate func placeholderEditingDidEndAnimation() {
guard isPlaceholderAnimated else { guard isPlaceholderAnimated else {
return return
} }
...@@ -602,61 +666,4 @@ open class TextField: UITextField { ...@@ -602,61 +666,4 @@ open class TextField: UITextField {
self?.isAnimating = false self?.isAnimating = false
} }
} }
/// Prepares the divider.
private func prepareDivider() {
dividerColor = dividerNormalColor
}
/// Prepares the placeholderLabel.
private func preparePlaceholderLabel() {
font = RobotoFont.regular(with: 16)
placeholderNormalColor = Color.darkText.others
addSubview(placeholderLabel)
addObserver(self, forKeyPath: "placeholderLabel.text", options: [], context: &TextFieldContext)
}
/// Prepares the detailLabel.
private func prepareDetailLabel() {
detailLabel.font = RobotoFont.regular(with: 12)
detailLabel.numberOfLines = 0
detailColor = Color.darkText.others
addSubview(detailLabel)
addObserver(self, forKeyPath: "detailLabel.text", options: [], context: &TextFieldContext)
}
/// Prepares the leftView.
private func prepareLeftView() {
leftView?.contentMode = .left
}
/// Prepares the target handlers.
private func prepareTargetHandlers() {
addTarget(self, action: #selector(handleEditingDidBegin), for: .editingDidBegin)
addTarget(self, action: #selector(handleEditingChanged), for: .editingChanged)
addTarget(self, action: #selector(handleEditingDidEnd), for: .editingDidEnd)
}
/// Prepares the textAlignment.
private func prepareTextAlignment() {
textAlignment = .rightToLeft == UIApplication.shared.userInterfaceLayoutDirection ? .right : .left
}
/// Updates the placeholderLabel attributedText.
private func updatePlaceholderLabelColor() {
guard let v = placeholder else {
return
}
placeholderLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: isEditing ? placeholderActiveColor : placeholderNormalColor])
}
/// Updates the detailLabel attributedText.
private func updateDetailLabelColor() {
guard let v = detail else {
return
}
detailLabel.attributedText = NSAttributedString(string: v, attributes: [NSForegroundColorAttributeName: detailColor])
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment