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](https://github.com/facebook/react-native/issues/18579#issuecomment-474466525) sent by TheSavior (Thanks, by the way 😄) ## Changelog [Android] [Fixed] - fix(android): Normalize start and end args Pull Request resolved: https://github.com/facebook/react-native/pull/24938 Differential Revision: D15412005 Pulled By: cpojer fbshipit-source-id: bb132313cfb8877a682f3865a5f9e48d45ac20ac
This commit is contained in:
Родитель
d4ff5ed258
Коммит
2ad3bb2e2d
|
@ -963,16 +963,22 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
|||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче