Commit 55625112 by Daniel Dahan

development: reworked TextField complete

parent c06092a1
......@@ -107,6 +107,7 @@
TargetAttributes = {
96090AE31D9CDD2E00709CA6 = {
CreatedOnToolsVersion = 8.0;
DevelopmentTeam = 9Z76XCNLGL;
ProvisioningStyle = Automatic;
};
};
......@@ -262,7 +263,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 9Z76XCNLGL;
INFOPLIST_FILE = TextField/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.cosmicmind.TextField;
......@@ -275,7 +276,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 9Z76XCNLGL;
INFOPLIST_FILE = TextField/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.cosmicmind.TextField;
......
......@@ -45,7 +45,7 @@ class ViewController: UIViewController {
prepareNameField()
prepareEmailField()
preparePasswordField()
// preparePasswordField()
prepareResignResponderButton()
}
......@@ -72,14 +72,13 @@ class ViewController: UIViewController {
private func prepareNameField() {
nameField = TextField()
nameField.text = "Daniel Dahan"
nameField.placeholder = "Name"
nameField.detail = "Your given name"
nameField.textAlignment = .center
nameField.isClearIconButtonEnabled = true
nameField.clearButtonMode = .whileEditing
let leftView = UIImageView()
leftView.image = Icon.email?.tint(with: Color.cyan.base)
leftView.image = Icon.phone?.tint(with: Color.blue.base)
nameField.leftView = leftView
nameField.leftViewMode = .always
......@@ -89,15 +88,13 @@ class ViewController: UIViewController {
private func prepareEmailField() {
emailField = ErrorTextField(frame: CGRect(x: constant, y: 7 * constant, width: view.width - (2 * constant), height: constant))
emailField.text = "Daniel Dahan"
emailField.placeholder = "Email"
emailField.detail = "Error, incorrect email"
emailField.isClearIconButtonEnabled = true
emailField.textAlignment = .right
emailField.delegate = self
let leftView = UIImageView()
leftView.image = Icon.email?.tint(with: Color.cyan.base)
leftView.image = Icon.email?.tint(with: Color.blue.base)
emailField.leftView = leftView
emailField.leftViewMode = .always
......@@ -112,7 +109,6 @@ class ViewController: UIViewController {
private func preparePasswordField() {
passwordField = TextField()
passwordField.text = "Daniel Dahan"
passwordField.placeholder = "Password"
passwordField.detail = "At least 8 characters"
passwordField.clearButtonMode = .whileEditing
......
{
"images" : [
{
"idiom" : "universal",
"filename" : "ic_phone_white.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "ic_phone_white@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "ic_phone_white@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
......@@ -37,7 +37,7 @@ public enum ContentViewAlignment: Int {
}
open class Bar: View {
/// Will render the view.
/// Will layout the view.
open var willLayout: Bool {
return 0 < width && 0 < height && nil != superview
}
......
......@@ -31,7 +31,7 @@
import UIKit
open class Card: PulseView {
/// Will render the view.
/// Will layout the view.
open var willLayout: Bool {
return 0 < width && nil != superview
}
......
......@@ -46,7 +46,11 @@ open class Divider {
internal var line: UIView?
/// A reference to the height.
open var thickness: CGFloat
open var thickness: CGFloat {
didSet {
reload()
}
}
/// A preset wrapper around contentEdgeInsets.
open var contentEdgeInsetsPreset = EdgeInsetsPreset.none {
......
......@@ -35,6 +35,7 @@ open class ErrorTextField: TextField {
@IBInspectable
open var isErrorRevealed = false {
didSet {
layoutDetailLabel()
detailLabel.isHidden = !isErrorRevealed
}
}
......
......@@ -79,6 +79,7 @@ public struct Icon {
public static let movie = Icon.icon("ic_movie_white")
public static let pen = Icon.icon("ic_edit_white")
public static let place = Icon.icon("ic_place_white")
public static let phone = Icon.icon("ic_phone_white")
public static let photoCamera = Icon.icon("ic_photo_camera_white")
public static let photoLibrary = Icon.icon("ic_photo_library_white")
public static let search = Icon.icon("ic_search_white")
......
......@@ -31,7 +31,7 @@
import UIKit
open class NavigationBar: UINavigationBar {
/// Will render the view.
/// Will layout the view.
open var willLayout: Bool {
return 0 < width && 0 < height && nil != superview
}
......
......@@ -61,7 +61,7 @@ public protocol SwitchDelegate {
@objc(Switch)
open class Switch: UIControl {
/// Will render the view.
/// Will layout the view.
open var willLayout: Bool {
return 0 < width && 0 < height && nil != superview
}
......
......@@ -60,6 +60,11 @@ public protocol TextFieldDelegate: UITextFieldDelegate {
}
open class TextField: UITextField {
/// Will layout the view.
open var willLayout: Bool {
return 0 < width && 0 < height && nil != superview
}
/// Default size when using AutoLayout.
open override var intrinsicContentSize: CGSize {
return CGSize(width: width, height: 32)
......@@ -79,6 +84,11 @@ open class TextField: UITextField {
}
}
/// A boolean indicating whether the text is empty.
open var isEmpty: Bool {
return true == text?.isEmpty
}
/// The leftView width value.
open var leftViewWidth: CGFloat {
guard nil != leftView else {
......@@ -136,7 +146,7 @@ open class TextField: UITextField {
@IBInspectable
open override var text: String? {
didSet {
guard true == text?.isEmpty else {
guard isEmpty else {
return
}
......@@ -227,6 +237,9 @@ open class TextField: UITextField {
}
}
/// A reference to the clearIconButton.
open private(set) var clearIconButton: IconButton?
/// Enables the clearIconButton.
@IBInspectable
open var isClearIconButtonEnabled: Bool {
......@@ -252,7 +265,7 @@ open class TextField: UITextField {
rightView = clearIconButton
isClearIconButtonAutoHandled = isClearIconButtonAutoHandled ? true : false
layoutButton(button: clearIconButton)
layoutSubviews()
}
}
......@@ -269,6 +282,9 @@ open class TextField: UITextField {
clearIconButton?.addTarget(self, action: #selector(handleClearIconButton), for: .touchUpInside)
}
}
/// A reference to the visibilityIconButton.
open private(set) var visibilityIconButton: IconButton?
/// Enables the visibilityIconButton.
@IBInspectable
......@@ -296,7 +312,7 @@ open class TextField: UITextField {
rightView = visibilityIconButton
isVisibilityIconButtonAutoHandled = isVisibilityIconButtonAutoHandled ? true : false
layoutButton(button: visibilityIconButton)
layoutSubviews()
}
}
......@@ -314,12 +330,6 @@ open class TextField: UITextField {
}
}
/// A reference to the clearIconButton.
open private(set) var clearIconButton: IconButton?
/// A reference to the visibilityIconButton.
open private(set) var visibilityIconButton: IconButton?
open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
guard "placeholderLabel.text" != keyPath else {
updatePlaceholderLabelColor()
......@@ -381,8 +391,9 @@ open class TextField: UITextField {
/// Handles the text editing did begin state.
@objc
open func handleEditingDidBegin() {
placeholderEditingDidBeginAnimation()
dividerEditingDidBeginAnimation()
placeholderEditingDidBeginAnimation()
}
// Live updates the textField text.
......@@ -394,8 +405,8 @@ open class TextField: UITextField {
/// Handles the text editing did end state.
@objc
open func handleEditingDidEnd() {
dividerEditingDidEndAnimation()
placeholderEditingDidEndAnimation()
placeholderEditingDidEndAnimation()
dividerEditingDidEndAnimation()
}
/// Handles the clearIconButton TouchUpInside event.
......@@ -448,6 +459,10 @@ open class TextField: UITextField {
/// Ensures that the components are sized correctly.
open func reload() {
guard willLayout else {
return
}
guard !isAnimating else {
return
}
......@@ -465,7 +480,7 @@ open class TextField: UITextField {
let w = leftViewWidth
let h = 0 == height ? intrinsicContentSize.height : height
guard isEditing || false == text?.isEmpty || !isPlaceholderAnimated else {
guard isEditing || !isEmpty || !isPlaceholderAnimated else {
placeholderLabel.frame = CGRect(x: w, y: 0, width: width - w, height: h)
return
}
......@@ -523,7 +538,7 @@ open class TextField: UITextField {
open func dividerEditingDidBeginAnimation() {
dividerThickness = dividerActiveHeight
dividerColor = dividerActiveColor
}
}
/// The animation for the divider when editing ends.
open func dividerEditingDidEndAnimation() {
......@@ -537,8 +552,7 @@ open class TextField: UITextField {
return
}
guard placeholderLabel.transform.isIdentity else {
updatePlaceholderLabelColor()
guard isEmpty && !isAnimating else {
return
}
......@@ -570,8 +584,7 @@ open class TextField: UITextField {
return
}
guard !placeholderLabel.transform.isIdentity && true == text?.isEmpty else {
updatePlaceholderLabelColor()
guard isEmpty && !isAnimating else {
return
}
......@@ -614,7 +627,7 @@ open class TextField: UITextField {
/// Prepares the leftView.
private func prepareLeftView() {
leftView?.contentMode = .center
leftView?.contentMode = .left
}
/// Prepares the target handlers.
......
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