fix(TextInput): report correct selection after autofill on Android - #57809
Open
stareezy-1 wants to merge 1 commit into
Open
fix(TextInput): report correct selection after autofill on Android#57809stareezy-1 wants to merge 1 commit into
stareezy-1 wants to merge 1 commit into
Conversation
Move the onChange event dispatch from onTextChanged to afterTextChanged.
During system autofill, Android sets the text content before updating the
cursor position. When onTextChanged fires, editText.selectionStart/End
still report {0, 0} from the initial empty state. By the time
afterTextChanged runs, the Editable is fully committed and Android has
updated the selection to reflect the actual cursor position.
This fixes the regression where autofill produces
selection: {start: 0, end: 0} instead of the correct position at the
end of the inserted text. Paste and keyboard input are unaffected since
Android updates their selection synchronously before the TextWatcher
callbacks.
Fixes react#57458
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes the
onChangeevent reportingselection: {start: 0, end: 0}instead of the actual cursor position when text is filled via Android's system autofill.Fixes #57458
Changelog:
[ANDROID] [FIXED] - TextInput onChange now reports correct selection after system autofill
Problem
ReactTextInputTextWatcher.onTextChangeddispatches theonChangeevent witheditText.selectionStart/End. During autofill, Android sets the text before updating the cursor position — so atonTextChangedtime, the selection is still at{0, 0}.Paste and keyboard input work correctly because Android updates their selection synchronously before the TextWatcher callbacks.
Solution
Moved the event dispatch (state update +
ReactTextChangedEvent) fromonTextChangedtoafterTextChanged. By that point the Editable is fully committed and Android has updated the selection to reflect the actual cursor position.The change detection logic stays in
onTextChanged(where it has access to thestart/before/countparameters) and sets a flag thatafterTextChangedchecks before dispatching.Test Plan
onChangenow reportsselection: {start: N, end: N}where N = text length