From 248099447b12d639a21167724ba836de3721c1c0 Mon Sep 17 00:00:00 2001 From: Andreas Date: Mon, 19 Feb 2018 15:53:10 +0100 Subject: [PATCH 1/2] Added property for autocorrection By adressing issue #67, I added a property to set the UITextAutocorrectionType on the underlaying UITextField / UITextView. Is is still turned off by default but the user now has the choice to turn it on. --- AnimatedTextInput/Classes/AnimatedTextField.swift | 5 +++++ AnimatedTextInput/Classes/AnimatedTextInput.swift | 11 ++++++++++- AnimatedTextInput/Classes/AnimatedTextView.swift | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/AnimatedTextInput/Classes/AnimatedTextField.swift b/AnimatedTextInput/Classes/AnimatedTextField.swift index 387474e..452a9c1 100755 --- a/AnimatedTextInput/Classes/AnimatedTextField.swift +++ b/AnimatedTextInput/Classes/AnimatedTextField.swift @@ -132,6 +132,11 @@ extension AnimatedTextField: TextInput { get { return text } set { self.text = newValue } } + + public var autocorrection: UITextAutocorrectionType { + get { return self.autocorrectionType } + set { self.autocorrectionType = newValue } + } public var currentSelectedTextRange: UITextRange? { get { return self.selectedTextRange } diff --git a/AnimatedTextInput/Classes/AnimatedTextInput.swift b/AnimatedTextInput/Classes/AnimatedTextInput.swift index 1667499..f69bc2a 100755 --- a/AnimatedTextInput/Classes/AnimatedTextInput.swift +++ b/AnimatedTextInput/Classes/AnimatedTextInput.swift @@ -23,7 +23,13 @@ open class AnimatedTextInput: UIControl { configureType() } } - + + open var autocorrection: UITextAutocorrectionType = .no { + didSet { + configureType() + } + } + open var returnKeyType: UIReturnKeyType = .default { didSet { textInput.changeReturnKeyType(with: returnKeyType) @@ -291,6 +297,7 @@ open class AnimatedTextInput: UIControl { textInput.view.tintColor = style.activeColor textInput.textColor = style.textInputFontColor textInput.font = style.textInputFont + textInput.autocorrection = autocorrection textInput.view.translatesAutoresizingMaskIntoConstraints = false addSubview(textInput.view) invalidateIntrinsicContentSize() @@ -559,6 +566,8 @@ public protocol TextInput { var currentSelectedTextRange: UITextRange? { get set } var currentBeginningOfDocument: UITextPosition? { get } var contentInset: UIEdgeInsets { get set } + var autocorrection: UITextAutocorrectionType {get set} + func configureInputView(newInputView: UIView) func changeReturnKeyType(with newReturnKeyType: UIReturnKeyType) diff --git a/AnimatedTextInput/Classes/AnimatedTextView.swift b/AnimatedTextInput/Classes/AnimatedTextView.swift index baa999a..38d4fb9 100755 --- a/AnimatedTextInput/Classes/AnimatedTextView.swift +++ b/AnimatedTextInput/Classes/AnimatedTextView.swift @@ -60,6 +60,11 @@ extension AnimatedTextView: TextInput { return self.beginningOfDocument } + public var autocorrection: UITextAutocorrectionType { + get { return self.autocorrectionType } + set { self.autocorrectionType = newValue } + } + public func changeReturnKeyType(with newReturnKeyType: UIReturnKeyType) { returnKeyType = newReturnKeyType } From 07aae0dba0c0d80fa43f918b8d977b701435e867 Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 20 Mar 2018 16:27:27 +0100 Subject: [PATCH 2/2] Only autocorrection value will be updated when set Not the entire text input is re-created but only its autocorrection property is updated when a change to the value is made. --- AnimatedTextInput/Classes/AnimatedTextInput.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AnimatedTextInput/Classes/AnimatedTextInput.swift b/AnimatedTextInput/Classes/AnimatedTextInput.swift index f69bc2a..efa9250 100755 --- a/AnimatedTextInput/Classes/AnimatedTextInput.swift +++ b/AnimatedTextInput/Classes/AnimatedTextInput.swift @@ -26,7 +26,7 @@ open class AnimatedTextInput: UIControl { open var autocorrection: UITextAutocorrectionType = .no { didSet { - configureType() + textInput.autocorrection = autocorrection } }