mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
686d8a57f8
commit
f3a53fd338
@@ -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<TextWatcher> 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;
|
||||
}
|
||||
|
||||
|
||||
+16
-23
@@ -208,7 +208,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
this.receiveCommand(reactEditText, "blur", args);
|
||||
break;
|
||||
case SET_MOST_RECENT_EVENT_COUNT:
|
||||
this.receiveCommand(reactEditText, "setMostRecentEventCount", args);
|
||||
// TODO: delete, this is no longer used from JS
|
||||
break;
|
||||
case SET_TEXT_AND_SELECTION:
|
||||
this.receiveCommand(reactEditText, "setTextAndSelection", args);
|
||||
@@ -229,27 +229,25 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
reactEditText.clearFocusFromJS();
|
||||
break;
|
||||
case "setMostRecentEventCount":
|
||||
reactEditText.setMostRecentEventCount(args.getInt(0));
|
||||
// TODO: delete, this is no longer used from JS
|
||||
break;
|
||||
case "setTextAndSelection":
|
||||
int mostRecentEventCount = args.getInt(0);
|
||||
reactEditText.setMostRecentEventCount(mostRecentEventCount);
|
||||
|
||||
if (mostRecentEventCount != UNSET) {
|
||||
String text = args.getString(1);
|
||||
|
||||
int start = args.getInt(2);
|
||||
int end = args.getInt(3);
|
||||
if (end == UNSET) {
|
||||
end = start;
|
||||
}
|
||||
|
||||
// TODO: construct a ReactTextUpdate and use that with maybeSetText
|
||||
// instead of calling setText, etc directly - doing that will definitely cause bugs.
|
||||
reactEditText.maybeSetTextFromJS(
|
||||
getReactTextUpdate(text, mostRecentEventCount, start, end));
|
||||
reactEditText.maybeSetSelection(mostRecentEventCount, start, end);
|
||||
if (mostRecentEventCount == UNSET) {
|
||||
return;
|
||||
}
|
||||
|
||||
String text = args.getString(1);
|
||||
|
||||
int start = args.getInt(2);
|
||||
int end = args.getInt(3);
|
||||
if (end == UNSET) {
|
||||
end = start;
|
||||
}
|
||||
|
||||
reactEditText.maybeSetTextFromJS(
|
||||
getReactTextUpdate(text, mostRecentEventCount, start, end));
|
||||
reactEditText.maybeSetSelection(mostRecentEventCount, start, end);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -470,11 +468,6 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
}
|
||||
}
|
||||
|
||||
@ReactProp(name = "mostRecentEventCount", defaultInt = 0)
|
||||
public void setMostRecentEventCount(ReactEditText view, int mostRecentEventCount) {
|
||||
view.setMostRecentEventCount(mostRecentEventCount);
|
||||
}
|
||||
|
||||
@ReactProp(name = "caretHidden", defaultBoolean = false)
|
||||
public void setCaretHidden(ReactEditText view, boolean caretHidden) {
|
||||
view.setCursorVisible(!caretHidden);
|
||||
|
||||
Reference in New Issue
Block a user