Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): Normalize start and end args #24938

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -963,16 +963,22 @@ public void onSelectionChanged(int start, int end) {
// Android will call us back for both the SELECTION_START span and SELECTION_END span in text
// To prevent double calling back into js we cache the result of the previous call and only
// forward it on if we have new values
if (mPreviousSelectionStart != start || mPreviousSelectionEnd != end) {

// Apparently Android might call this with an end value that is less than the start value
// Lets normalize them. See https://github.com/facebook/react-native/issues/18579
int realStart = Math.min(start, end);
int realEnd = Math.max(start, end);

if (mPreviousSelectionStart != realStart || mPreviousSelectionEnd != realEnd) {
mEventDispatcher.dispatchEvent(
new ReactTextInputSelectionEvent(
mReactEditText.getId(),
start,
end
realStart,
realEnd
));

mPreviousSelectionStart = start;
mPreviousSelectionEnd = end;
mPreviousSelectionStart = realStart;
mPreviousSelectionEnd = realEnd;
}
}
}
Expand Down