diff --git a/AnimatedTextInput/Classes/AnimatedTextField.swift b/AnimatedTextInput/Classes/AnimatedTextField.swift index b1bb1f4..64790f2 100644 --- a/AnimatedTextInput/Classes/AnimatedTextField.swift +++ b/AnimatedTextInput/Classes/AnimatedTextField.swift @@ -1,6 +1,6 @@ import UIKit -final internal class AnimatedTextField: UITextField { +final public class AnimatedTextField: UITextField { enum TextFieldType { case text @@ -13,9 +13,9 @@ final internal class AnimatedTextField: UITextField { fileprivate let clearButtonPadding: CGFloat = -8 var rightViewPadding: CGFloat - weak var textInputDelegate: TextInputDelegate? + weak public var textInputDelegate: TextInputDelegate? - var textAttributes: [String: Any]? + public var textAttributes: [String: Any]? fileprivate var disclosureButtonAction: ((Void) -> Void)? @@ -27,9 +27,10 @@ final internal class AnimatedTextField: UITextField { setup() } - required init?(coder aDecoder: NSCoder) { + required public init?(coder aDecoder: NSCoder) { self.rightViewPadding = defaultPadding + super.init(coder: aDecoder) setup() @@ -40,22 +41,22 @@ final internal class AnimatedTextField: UITextField { addTarget(self, action: #selector(textFieldDidChange), for: .editingChanged) } - @discardableResult override func becomeFirstResponder() -> Bool { + @discardableResult override public func becomeFirstResponder() -> Bool { if let alignment = (textAttributes?[NSParagraphStyleAttributeName] as? NSMutableParagraphStyle)?.alignment { textAlignment = alignment } return super.becomeFirstResponder() } - override func rightViewRect(forBounds bounds: CGRect) -> CGRect { + override public func rightViewRect(forBounds bounds: CGRect) -> CGRect { return super.rightViewRect(forBounds: bounds).offsetBy(dx: rightViewPadding, dy: 0) } - override func clearButtonRect(forBounds bounds: CGRect) -> CGRect { + override public func clearButtonRect(forBounds bounds: CGRect) -> CGRect { return super.clearButtonRect(forBounds: bounds).offsetBy(dx: clearButtonPadding, dy: 0) } - override func textRect(forBounds bounds: CGRect) -> CGRect { + override public func textRect(forBounds bounds: CGRect) -> CGRect { var width = bounds.width if clearButtonMode == .always || clearButtonMode == .unlessEditing { width = bounds.width - clearButtonRect(forBounds: bounds).width * 2 @@ -63,7 +64,7 @@ final internal class AnimatedTextField: UITextField { return CGRect(x: bounds.origin.x, y: bounds.origin.y, width: width, height: bounds.height) } - override func editingRect(forBounds bounds: CGRect) -> CGRect { + override public func editingRect(forBounds bounds: CGRect) -> CGRect { var width = bounds.width if clearButtonMode != .never { width = bounds.width - clearButtonRect(forBounds: bounds).width * 2 @@ -97,24 +98,24 @@ final internal class AnimatedTextField: UITextField { extension AnimatedTextField: TextInput { - func changeReturnKeyType(with newReturnKeyType: UIReturnKeyType) { + public func changeReturnKeyType(with newReturnKeyType: UIReturnKeyType) { returnKeyType = newReturnKeyType } - func currentPosition(from: UITextPosition, offset: Int) -> UITextPosition? { + public func currentPosition(from: UITextPosition, offset: Int) -> UITextPosition? { return position(from: from, offset: offset) } - func changeClearButtonMode(with newClearButtonMode: UITextFieldViewMode) { + public func changeClearButtonMode(with newClearButtonMode: UITextFieldViewMode) { clearButtonMode = newClearButtonMode } - var currentText: String? { + public var currentText: String? { get { return text } set { self.text = newValue } } - var currentSelectedTextRange: UITextRange? { + public var currentSelectedTextRange: UITextRange? { get { return self.selectedTextRange } set { self.selectedTextRange = newValue } } @@ -126,38 +127,38 @@ extension AnimatedTextField: TextInput { extension AnimatedTextField: TextInputError { - func configureErrorState(with message: String?) { + public func configureErrorState(with message: String?) { placeholder = message } - func removeErrorHintMessage() { + public func removeErrorHintMessage() { placeholder = nil } } extension AnimatedTextField: UITextFieldDelegate { - func textFieldDidBeginEditing(_ textField: UITextField) { + public func textFieldDidBeginEditing(_ textField: UITextField) { textInputDelegate?.textInputDidBeginEditing(textInput: self) } - func textFieldDidEndEditing(_ textField: UITextField) { + public func textFieldDidEndEditing(_ textField: UITextField) { textInputDelegate?.textInputDidEndEditing(textInput: self) } - func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { + public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { return textInputDelegate?.textInput(textInput: self, shouldChangeCharactersInRange: range, replacementString: string) ?? true } - func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool { + public func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool { return textInputDelegate?.textInputShouldBeginEditing(textInput: self) ?? true } - func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { + public func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { return textInputDelegate?.textInputShouldEndEditing(textInput: self) ?? true } - func textFieldShouldReturn(_ textField: UITextField) -> Bool { + public func textFieldShouldReturn(_ textField: UITextField) -> Bool { return textInputDelegate?.textInputShouldReturn(textInput: self) ?? true } } diff --git a/AnimatedTextInput/Classes/AnimatedTextView.swift b/AnimatedTextInput/Classes/AnimatedTextView.swift index dadcf73..e993ac5 100644 --- a/AnimatedTextInput/Classes/AnimatedTextView.swift +++ b/AnimatedTextInput/Classes/AnimatedTextView.swift @@ -1,15 +1,15 @@ import UIKit -final internal class AnimatedTextView: UITextView { +final public class AnimatedTextView: UITextView { - var textAttributes: [String: Any]? { + public var textAttributes: [String: Any]? { didSet { guard let attributes = textAttributes else { return } typingAttributes = attributes } } - weak var textInputDelegate: TextInputDelegate? + public weak var textInputDelegate: TextInputDelegate? override init(frame: CGRect, textContainer: NSTextContainer?) { super.init(frame: frame, textContainer: textContainer) @@ -17,7 +17,7 @@ final internal class AnimatedTextView: UITextView { setup() } - required init?(coder aDecoder: NSCoder) { + public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setup() @@ -27,50 +27,50 @@ final internal class AnimatedTextView: UITextView { delegate = self } - override func resignFirstResponder() -> Bool { + public override func resignFirstResponder() -> Bool { return super.resignFirstResponder() } } extension AnimatedTextView: TextInput { - var currentText: String? { + public var currentText: String? { get { return text } set { self.text = newValue } } - var currentSelectedTextRange: UITextRange? { + public var currentSelectedTextRange: UITextRange? { get { return self.selectedTextRange } set { self.selectedTextRange = newValue } } - open var currentBeginningOfDocument: UITextPosition? { + public var currentBeginningOfDocument: UITextPosition? { return self.beginningOfDocument } - func changeReturnKeyType(with newReturnKeyType: UIReturnKeyType) { + public func changeReturnKeyType(with newReturnKeyType: UIReturnKeyType) { returnKeyType = newReturnKeyType } - func currentPosition(from: UITextPosition, offset: Int) -> UITextPosition? { + public func currentPosition(from: UITextPosition, offset: Int) -> UITextPosition? { return position(from: from, offset: offset) } - func changeClearButtonMode(with newClearButtonMode: UITextFieldViewMode) {} + public func changeClearButtonMode(with newClearButtonMode: UITextFieldViewMode) {} } extension AnimatedTextView: UITextViewDelegate { - func textViewDidBeginEditing(_ textView: UITextView) { + public func textViewDidBeginEditing(_ textView: UITextView) { textInputDelegate?.textInputDidBeginEditing(textInput: self) } - func textViewDidEndEditing(_ textView: UITextView) { + public func textViewDidEndEditing(_ textView: UITextView) { textInputDelegate?.textInputDidEndEditing(textInput: self) } - func textViewDidChange(_ textView: UITextView) { + public func textViewDidChange(_ textView: UITextView) { let range = textView.selectedRange textView.attributedText = NSAttributedString(string: textView.text, attributes: textAttributes) textView.selectedRange = range @@ -78,18 +78,18 @@ extension AnimatedTextView: UITextViewDelegate { textInputDelegate?.textInputDidChange(textInput: self) } - func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { + public func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { if text == "\n" { return textInputDelegate?.textInputShouldReturn(textInput: self) ?? true } return textInputDelegate?.textInput(textInput: self, shouldChangeCharactersInRange: range, replacementString: text) ?? true } - func textViewShouldBeginEditing(_ textView: UITextView) -> Bool { + public func textViewShouldBeginEditing(_ textView: UITextView) -> Bool { return textInputDelegate?.textInputShouldBeginEditing(textInput: self) ?? true } - func textViewShouldEndEditing(_ textView: UITextView) -> Bool { + public func textViewShouldEndEditing(_ textView: UITextView) -> Bool { return textInputDelegate?.textInputShouldEndEditing(textInput: self) ?? true } }