@@ -39,6 +39,8 @@ class AdvancedTextInputMaskDecoratorView: UIView {
3939 if result. formattedText. string == nextText { return }
4040
4141 let attributedText = NSAttributedString ( string: result. formattedText. string)
42+
43+ setText ( textField: textField, text: attributedText)
4244 }
4345 }
4446
@@ -166,12 +168,12 @@ class AdvancedTextInputMaskDecoratorView: UIView {
166168 #endif
167169 }
168170
169- private func getMaskResultForText( text: String ) -> Mask . Result ? {
171+ private func getMaskResultForText( text: String , autocomplete : Bool = false ) -> Mask . Result ? {
170172 guard let primaryMask = maskInputListener? . primaryMask else { return nil }
171173 let caretString = CaretString (
172174 string: text,
173175 caretPosition: text. endIndex,
174- caretGravity: CaretString . CaretGravity. forward ( autocomplete: false )
176+ caretGravity: CaretString . CaretGravity. forward ( autocomplete: autocomplete )
175177 )
176178 return primaryMask. apply ( toText: caretString)
177179 }
@@ -190,19 +192,14 @@ class AdvancedTextInputMaskDecoratorView: UIView {
190192 setText ( textField: textField, text: attributedText)
191193 }
192194
193- @objc private func maybeUpdateText( text: String ) {
194- guard let primaryMask = maskInputListener? . primaryMask else { return }
195+ @objc func maybeUpdateText( text: String , autocomplete _ : Bool = false ) {
196+ guard ( maskInputListener? . primaryMask) != nil else { return }
195197 guard let textField = textField else { return }
196198
197199 if text == textField. attributedText? . string {
198200 return
199201 }
200202
201- let caretString = CaretString (
202- string: text,
203- caretPosition: text. endIndex,
204- caretGravity: CaretString . CaretGravity. forward ( autocomplete: false )
205- )
206203 guard let result = getMaskResultForText ( text: text) else { return }
207204
208205 if text == result. formattedText. string {
@@ -266,6 +263,17 @@ class AdvancedTextInputMaskDecoratorView: UIView {
266263 textFieldDelegate = nil
267264 }
268265
266+ @objc ( setMaskedText: autocomplete: )
267+ func setMaskedText( text: NSString , autocomplete: Bool ) {
268+ guard let result = getMaskResultForText ( text: text as String , autocomplete: autocomplete) else { return }
269+
270+ let attributedText = NSAttributedString ( string: result. formattedText. string)
271+ guard let textField = textField else { return }
272+
273+ setText ( textField: textField, text: attributedText)
274+ maskInputListener? . notifyOnMaskedTextChangedListeners ( forTextInput: textField, result: result)
275+ }
276+
269277 // MARK: - View Lifecycle
270278
271279 override func didMoveToWindow( ) {
0 commit comments