Skip to content

Commit

Permalink
fix(android): Normalize start and end args (#24938)
Browse files Browse the repository at this point in the history
Summary:
Fixes #18579

Normalize `start` and `end` arguments when `onSelectionChange` is
dispatched on Android.

It just applies a [fix](#18579 (comment)) sent by TheSavior (Thanks, by the way 😄)

## Changelog

[Android] [Fixed] - fix(android): Normalize start and end args
Pull Request resolved: #24938

Differential Revision: D15412005

Pulled By: cpojer

fbshipit-source-id: bb132313cfb8877a682f3865a5f9e48d45ac20ac
  • Loading branch information
uqmessias authored and facebook-github-bot committed May 20, 2019
1 parent d4ff5ed commit 2ad3bb2
Showing 1 changed file with 11 additions and 5 deletions.
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

0 comments on commit 2ad3bb2

Please sign in to comment.