             placeholderLabel.textAlignment = alignment
         }
     }
-    
+
     @IBInspectable public var placeholderTopColor: UIColor = UIColor.gray {
         didSet {
             setState(toState: state)

        selectedDate = datePicker.date
        text = datePicker.date.toString(withFormat: dateFormat)
    }
    
    @objc private func datePickerDoneAction() {
        if let datePicker = textField.inputView as? UIDatePicker {
            updateText(from: datePicker)
        }
        textField.resignFirstResponder()
    }
    
    @objc private func textFieldValueDidChange() {
        delegate?.animatedTextFieldValueDidChange?(self)
    }
    
}

// MARK: - Extension

extension UIAnimatedTextField: UITextFieldDelegate {
    
    open func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
        var result = true
        
        if let delegateResult = delegate?.animatedTextFieldShouldBeginEditing?(self) {
            result = delegateResult
        }
        
        return result
    }
    
    open func textFieldDidBeginEditing(_ textField: UITextField) {
        if textField.text?.characters.count ?? 0 == 0 {
            setState(toState: .text, duration: UIAnimatedTextField.animationDuration)
        }
        
        if case .date = type {
            if let datePicker = textField.inputView as? UIDatePicker {
                textField.text = datePicker.date.toString(withFormat: dateFormat)
            }
        }
        
        delegate?.animatedTextFieldDidBeginEditing?(self)
    }
    
    open func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
        var result = true
        
        if let delegateResult = delegate?.animatedTextFieldShouldEndEditing?(self) {
            result = delegateResult
        }
        
        return result
    }
    
    open func textFieldDidEndEditing(_ textField: UITextField) {
        if textField.text?.characters.count ?? 0 == 0 {
            setState(toState: .placeholder, duration: UIAnimatedTextField.animationDuration)

import UIKit

@objc public protocol UIAnimatedTextFieldDelegate: class {

    @objc optional func animatedTextFieldValueDidChange(_ animatedTextField: UIAnimatedTextField)
    @objc optional func animatedTextFieldWillReactForTap()
    @objc optional func animatedTextFieldShouldBeginEditing(_ animatedTextField: UIAnimatedTextField) -> Bool
