Commit b591c92d by Daniel Dahan

added feature where TextField placeholder does not animate issue-534

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