Skip to content
Permalink
Browse files

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

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 2ad3bb2e2d62ffb780bab020f645626a16dd3b4a
@@ -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;
}
}
}

0 comments on commit 2ad3bb2

Please sign in to comment.
You can’t perform that action at this time.