Commit b591c92d by Daniel Dahan

added feature where TextField placeholder does not animate issue-534

parent 7b0a4f16
...@@ -339,6 +339,14 @@ ...@@ -339,6 +339,14 @@
/* End PBXFrameworksBuildPhase section */ /* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */ /* Begin PBXGroup section */
9602F00C1DA1163000F3FB79 /* Grid */ = {
isa = PBXGroup;
children = (
96BCB7611CB40DC500C806FE /* Grid.swift */,
);
name = Grid;
sourceTree = "<group>";
};
96090B031D9D709E00709CA6 /* TextField */ = { 96090B031D9D709E00709CA6 /* TextField */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -520,6 +528,7 @@ ...@@ -520,6 +528,7 @@
96230AB61D6A51FD00AF47DC /* Divider */, 96230AB61D6A51FD00AF47DC /* Divider */,
96BCB80A1CB410A100C806FE /* Extension */, 96BCB80A1CB410A100C806FE /* Extension */,
96BCB8071CB4101C00C806FE /* Font */, 96BCB8071CB4101C00C806FE /* Font */,
9602F00C1DA1163000F3FB79 /* Grid */,
96BCB8081CB4105E00C806FE /* Icon */, 96BCB8081CB4105E00C806FE /* Icon */,
96BCB80D1CB410FD00C806FE /* Layer */, 96BCB80D1CB410FD00C806FE /* Layer */,
96BCB8041CB40F6C00C806FE /* Layout */, 96BCB8041CB40F6C00C806FE /* Layout */,
...@@ -619,7 +628,6 @@ ...@@ -619,7 +628,6 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96BCB7811CB40DC500C806FE /* Layout.swift */, 96BCB7811CB40DC500C806FE /* Layout.swift */,
96BCB7611CB40DC500C806FE /* Grid.swift */,
); );
name = Layout; name = Layout;
sourceTree = "<group>"; sourceTree = "<group>";
......
...@@ -48,6 +48,7 @@ open class ErrorTextField: TextField { ...@@ -48,6 +48,7 @@ open class ErrorTextField: TextField {
*/ */
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
isErrorRevealed = false
detailColor = Color.red.base detailColor = Color.red.base
} }
} }
...@@ -214,9 +214,14 @@ public class Grid { ...@@ -214,9 +214,14 @@ public class Grid {
return return
} }
let count = views.count
guard 0 < count else {
return
}
var n: Int = 0 var n: Int = 0
var i: Int = 0 var i: Int = 0
var count = views.count
for child in views { for child in views {
guard let canvas = context else { guard let canvas = context else {
...@@ -230,7 +235,7 @@ public class Grid { ...@@ -230,7 +235,7 @@ public class Grid {
switch axis.direction { switch axis.direction {
case .horizontal: case .horizontal:
let c = 0 == child.grid.columns ? axis.columns / views.count : child.grid.columns let c = 0 == child.grid.columns ? axis.columns / count : child.grid.columns
let co = child.grid.offset.columns let co = child.grid.offset.columns
let w = (canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns) let w = (canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns)
...@@ -242,7 +247,7 @@ public class Grid { ...@@ -242,7 +247,7 @@ public class Grid {
n += c + co - 1 n += c + co - 1
case .vertical: case .vertical:
let r = 0 == child.grid.rows ? axis.rows / views.count : child.grid.rows let r = 0 == child.grid.rows ? axis.rows / count : child.grid.rows
let ro = child.grid.offset.rows let ro = child.grid.offset.rows
let h = (canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows) let h = (canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows)
...@@ -254,9 +259,9 @@ public class Grid { ...@@ -254,9 +259,9 @@ public class Grid {
n += r + ro - 1 n += r + ro - 1
case .any: case .any:
let r = 0 == child.grid.rows ? axis.rows / views.count : child.grid.rows let r = 0 == child.grid.rows ? axis.rows / count : child.grid.rows
let ro = child.grid.offset.rows let ro = child.grid.offset.rows
let c = 0 == child.grid.columns ? axis.columns / views.count : child.grid.columns let c = 0 == child.grid.columns ? axis.columns / count : child.grid.columns
let co = child.grid.offset.columns let co = child.grid.offset.columns
let w = (canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns) let w = (canvas.bounds.width - contentEdgeInsets.left - contentEdgeInsets.right - layoutEdgeInsets.left - layoutEdgeInsets.right + interimSpace) / CGFloat(axis.columns)
let h = (canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows) let h = (canvas.bounds.height - contentEdgeInsets.top - contentEdgeInsets.bottom - layoutEdgeInsets.top - layoutEdgeInsets.bottom + interimSpace) / CGFloat(axis.rows)
......
...@@ -40,6 +40,10 @@ open class TextField: UITextField { ...@@ -40,6 +40,10 @@ open class TextField: UITextField {
return CGSize(width: width, height: 32) return CGSize(width: width, height: 32)
} }
/// A Boolean that indicates if the placeholder label is animated.
@IBInspectable
open var isPlaceholderAnimated = true
/// A Boolean that indicates if the TextField is in an animating state. /// A Boolean that indicates if the TextField is in an animating state.
open internal(set) var isAnimating = false open internal(set) var isAnimating = false
...@@ -161,7 +165,7 @@ open class TextField: UITextField { ...@@ -161,7 +165,7 @@ open class TextField: UITextField {
/// The detailLabel UILabel that is displayed. /// The detailLabel UILabel that is displayed.
@IBInspectable @IBInspectable
open private(set) lazy var detailLabel = UILabel(frame: .zero) open private(set) lazy var detailLabel = UILabel()
/// The detailLabel text value. /// The detailLabel text value.
@IBInspectable @IBInspectable
...@@ -432,7 +436,7 @@ open class TextField: UITextField { ...@@ -432,7 +436,7 @@ open class TextField: UITextField {
/// Layout the placeholderLabel. /// Layout the placeholderLabel.
open func layoutPlaceholderLabel() { open func layoutPlaceholderLabel() {
if !isEditing && true == text?.isEmpty { if !isEditing && true == text?.isEmpty && isPlaceholderAnimated {
placeholderLabel.frame = bounds placeholderLabel.frame = bounds
} else if placeholderLabel.transform.isIdentity { } else if placeholderLabel.transform.isIdentity {
placeholderLabel.frame = bounds placeholderLabel.frame = bounds
...@@ -493,6 +497,10 @@ open class TextField: UITextField { ...@@ -493,6 +497,10 @@ open class TextField: UITextField {
/// The animation for the placeholder when editing begins. /// The animation for the placeholder when editing begins.
open func placeholderEditingDidBeginAnimation() { open func placeholderEditingDidBeginAnimation() {
guard isPlaceholderAnimated else {
return
}
guard placeholderLabel.transform.isIdentity else { guard placeholderLabel.transform.isIdentity else {
if isEditing { if isEditing {
placeholderLabel.textColor = placeholderActiveColor placeholderLabel.textColor = placeholderActiveColor
...@@ -525,6 +533,10 @@ open class TextField: UITextField { ...@@ -525,6 +533,10 @@ open class TextField: UITextField {
/// The animation for the placeholder when editing ends. /// The animation for the placeholder when editing ends.
open func placeholderEditingDidEndAnimation() { open func placeholderEditingDidEndAnimation() {
guard isPlaceholderAnimated else {
return
}
if !placeholderLabel.transform.isIdentity && true == text?.isEmpty { if !placeholderLabel.transform.isIdentity && true == text?.isEmpty {
isAnimating = true isAnimating = true
UIView.animate(withDuration: 0.15, animations: { [weak self] in UIView.animate(withDuration: 0.15, animations: { [weak self] in
...@@ -551,7 +563,7 @@ open class TextField: UITextField { ...@@ -551,7 +563,7 @@ open class TextField: UITextField {
/// Prepares the placeholderLabel. /// Prepares the placeholderLabel.
private func preparePlaceholderLabel() { private func preparePlaceholderLabel() {
placeholderLabel = UILabel(frame: .zero) placeholderLabel = UILabel()
placeholderNormalColor = Color.darkText.others placeholderNormalColor = Color.darkText.others
font = RobotoFont.regular(with: 16) font = RobotoFont.regular(with: 16)
addSubview(placeholderLabel) addSubview(placeholderLabel)
......
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