From f3a53fd3382c7665d79ee78f45c1e855330df6cf Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Wed, 11 Mar 2020 12:29:16 -0700 Subject: [PATCH] TextInput: keep less stateful data on the View Summary: Allow JS to keep track of mostRecentEventCount and pass it into each event or prop update. We really don't want to separately keep track of that data. In non-Fabric, the ShadowNode will keep track of the mostRecentEventCount associated to prop updates. In Fabric, that happens on the C++ ShadowNode. Changelog: [Internal] Simplification to TextInput native state Reviewed By: mdvacca Differential Revision: D20374573 fbshipit-source-id: 385fba6ec69a071c78832a686b397699a6c55d67 --- Libraries/Components/TextInput/TextInput.js | 10 ++--- .../react/views/textinput/ReactEditText.java | 16 +------- .../textinput/ReactTextInputManager.java | 39 ++++++++----------- 3 files changed, 21 insertions(+), 44 deletions(-) diff --git a/Libraries/Components/TextInput/TextInput.js b/Libraries/Components/TextInput/TextInput.js index df98a6402e5..7f4eaf2f1bb 100644 --- a/Libraries/Components/TextInput/TextInput.js +++ b/Libraries/Components/TextInput/TextInput.js @@ -985,14 +985,12 @@ function InternalTextInput(props: Props): React.Node { }; const _onChange = (event: ChangeEvent) => { - // Make sure to fire the mostRecentEventCount first so it is already set on - // native when the text value is set. if (AndroidTextInputCommands && inputRef.current != null) { - AndroidTextInputCommands.setMostRecentEventCount( - inputRef.current, - event.nativeEvent.eventCount, - ); + // Do nothing } else if (inputRef.current != null) { + // Make sure to fire the mostRecentEventCount first so it is already set on + // native when the text value is set. + // This is now only relevant on iOS until we migrate to ViewCommands everywhere inputRef.current.setNativeProps({ mostRecentEventCount: event.nativeEvent.eventCount, }); diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index 7d04a3abc68..86ae295b262 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -74,9 +74,6 @@ public class ReactEditText extends AppCompatEditText { /** A count of events sent to JS or C++. */ protected int mNativeEventCount; - /** The most recent event number acked by JavaScript. Should only be updated from JS, not C++. */ - protected int mMostRecentEventCount; - private static final int UNSET = -1; private @Nullable ArrayList mListeners; @@ -122,7 +119,6 @@ public class ReactEditText extends AppCompatEditText { getGravity() & (Gravity.HORIZONTAL_GRAVITY_MASK | Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK); mDefaultGravityVertical = getGravity() & Gravity.VERTICAL_GRAVITY_MASK; mNativeEventCount = 0; - mMostRecentEventCount = 0; mIsSettingTextFromJS = false; mBlurOnSubmit = null; mDisableFullscreen = false; @@ -285,10 +281,6 @@ public class ReactEditText extends AppCompatEditText { mContentSizeWatcher = contentSizeWatcher; } - public void setMostRecentEventCount(int mostRecentEventCount) { - mMostRecentEventCount = mostRecentEventCount; - } - public void setScrollWatcher(ScrollWatcher scrollWatcher) { mScrollWatcher = scrollWatcher; } @@ -313,11 +305,6 @@ public class ReactEditText extends AppCompatEditText { @Override public void setSelection(int start, int end) { - // Skip setting the selection if the text wasn't set because of an out of date value. - if (mMostRecentEventCount < mNativeEventCount) { - return; - } - super.setSelection(start, end); } @@ -489,8 +476,7 @@ public class ReactEditText extends AppCompatEditText { } // Only set the text if it is up to date. - mMostRecentEventCount = reactTextUpdate.getJsEventCounter(); - if (!canUpdateWithEventCount(mMostRecentEventCount)) { + if (!canUpdateWithEventCount(reactTextUpdate.getJsEventCounter())) { return; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index 6bfde5d42ec..97080239964 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -208,7 +208,7 @@ public class ReactTextInputManager extends BaseViewManager