Fix iOS text input not working well with password auto-fill integration #11699
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR includes two separate fixes focusing towards the same goal, I'm not sure how to split them as they can't make sense on their own. My Objective-C coding skills are not that well so I apologise in advance if I made an idiotic mistake somewhere in the code 😅
Fix text field resetting text when replaced with a short string
When selecting a password to auto-fill in the current text field, the
textField.text
property is overwritten with that password, and if the password is less than 16 characters, it triggers the code that resets the text content and messes up the entire logic that is supposed to perform backspaces and such.The fix is to simply reset the text (i.e. fill back the "obligatory for backspace" text) when the event is triggered with a
string
of length zero, i.e. when the user deletes characters (see docs).The fix above can be argued to be more of a band-aid than a solid fix, as there's probably no better fix than to rewrite the iOS text input system from top to bottom and introduce text input events when a text is reset or replaced etc. It's a heavy one to discuss and my take on the matter may probably be biased towards iOS or not well thought of, but either way the fix above will do for now.
Associate text input state with the UITextField's focus state instead
When pressing the "Passwords" button on the keyboard to pick a keychain/vault, the keyboard hides, which triggers the
keyboardWillHide
animation, and incorrectly stop text input, ultimately not accepting any character entered from the selected password due to the text input being inactive.That issue made me try to "think out of the box", and I've noticed that UIKit synchronises the text field's "is first responder" state when the user dismisses the keyboard or otherwise, and correctly maintains it when the user presses the "Passwords" button and picks a password, as well as also keeping the text field focused when connecting a hardware keyboard or changing orientation. So overall it was a better state to associate with SDL text input's state rather than the on-screen keyboard's visibility.