Skip to content

Commit 89340f1

Browse files
Dave MillerFacebook Github Bot 3
authored andcommitted
Fix an issue with removeClippedSubviews and TextInput
Summary:This issue was found by brentvatne in #6805 The problem is an ordering issue. The internal state of the TextView (Editor) is updated when we set the text value for a ReactTextInput. When removeClippedSubviews is false, we addView the view which attaches it to the window, and then set the text. When removeClippedSubviews is false, we defer adding the view (caching it in mAllChildren in ReactViewGroup) until we know whether the view is actually going to show. This means when we set the initial text, that there is no window attached. Not having a window attached means that the Editor can't display the popup for PASTE and thinks that the text is not selectable and won't respond to the long press. To fix this we explicitly call setTextIsSelectable in onAttachedToWindow. This will cause the underlying TextView to have the Editor update and all will be in agreement. Note: This also makes it really easy to expose a selectable property on both Text and TextInput at the js level now. Reviewed By: andreicoman11 Differential Revision: D3173631 fb-gh-sync-id: a208214474a92ecc1277b3be0d38e2ef9327ea2e fbshipit-source-id: a208214474a92ecc1277b3be0d38e2ef9327ea2e
1 parent a8f4159 commit 89340f1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

‎ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class ReactTextView extends TextView implements ReactCompoundView {
2323
private boolean mContainsImages;
2424
private int mDefaultGravityHorizontal;
2525
private int mDefaultGravityVertical;
26+
private boolean mTextIsSelectable;
2627

2728
public ReactTextView(Context context) {
2829
super(context);
@@ -81,6 +82,12 @@ public int reactTagForTouch(float touchX, float touchY) {
8182
return target;
8283
}
8384

85+
@Override
86+
public void setTextIsSelectable(boolean selectable) {
87+
mTextIsSelectable = selectable;
88+
super.setTextIsSelectable(selectable);
89+
}
90+
8491
@Override
8592
protected boolean verifyDrawable(Drawable drawable) {
8693
if (mContainsImages && getText() instanceof Spanned) {
@@ -136,6 +143,7 @@ public void onStartTemporaryDetach() {
136143
@Override
137144
public void onAttachedToWindow() {
138145
super.onAttachedToWindow();
146+
setTextIsSelectable(mTextIsSelectable);
139147
if (mContainsImages && getText() instanceof Spanned) {
140148
Spanned text = (Spanned) getText();
141149
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);

‎ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class ReactEditText extends EditText {
6666
private @Nullable ArrayList<TextWatcher> mListeners;
6767
private @Nullable TextWatcherDelegator mTextWatcherDelegator;
6868
private int mStagedInputType;
69+
private boolean mTextIsSelectable = true;
6970
private boolean mContainsImages;
7071
private boolean mBlurOnSubmit;
7172
private @Nullable SelectionWatcher mSelectionWatcher;
@@ -215,6 +216,12 @@ public void setInputType(int type) {
215216
setKeyListener(mKeyListener);
216217
}
217218

219+
@Override
220+
public void setTextIsSelectable(boolean selectable) {
221+
mTextIsSelectable = selectable;
222+
super.setTextIsSelectable(selectable);
223+
}
224+
218225
// VisibleForTesting from {@link TextInputEventsTestCase}.
219226
public void requestFocusFromJS() {
220227
mIsJSSettingFocus = true;
@@ -389,6 +396,7 @@ public void onStartTemporaryDetach() {
389396
@Override
390397
public void onAttachedToWindow() {
391398
super.onAttachedToWindow();
399+
setTextIsSelectable(mTextIsSelectable);
392400
if (mContainsImages && getText() instanceof Spanned) {
393401
Spanned text = (Spanned) getText();
394402
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);

0 commit comments

Comments
 (0)