Fixed TextInput not being selectable in removeClippedSubviews FlatLists (#28852)

Summary:
This is a resubmit of D21499015. It resolves https://github.com/facebook/react-native/pull/28852 and https://github.com/facebook/react-native/issues/27787.

From Harry Yu's original PR (too old to merge now):

Text in TextInputs can't be selected by long press. This happens only when they're inside of FlatLists that are rendered with removeClippedSubview prop set to true on Android.

Fixes https://github.com/facebook/react-native/issues/27787

Issue https://github.com/facebook/react-native/issues/6085 2 years ago had fixed this issue with a quick fix, but the code has since disappeared in another change. It has a longer explanation for why it's fixed, but essentially - the text is assumed to be not selectable since the TextInput is initialized without being attached to the window. We need to explicitly set the text to be selectable on attachment. This change redoes that change with a 1-line fix.

Changelog: [Android] [Fixed] - Fixed TextInput not being selectable in removeClippedSubviews FlatLists

Pull Request resolved: https://github.com/facebook/react-native/pull/28852

Test Plan:
This can be tested with a new toggle in RNTesterApp.
Go to the FlatList in RNTesterApp
Toggle on "removeClippedSubviews"
Try selecting some text in the list header. It should fail without this comment but succeed with it

Reviewed By: sammy-SC

Differential Revision: D24043533

Pulled By: JoshuaGross

fbshipit-source-id: c8e60f8131ccc5f6af31ed976c4184d0a16eb3af
This commit is contained in:
hy.harry.yu@gmail.com
2020-10-04 22:13:07 -07:00
committed by Facebook GitHub Bot
parent 7c83eaba80
commit 12a50c0a44
@@ -827,6 +827,13 @@ public class ReactEditText extends AppCompatEditText
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
// Used to ensure that text is selectable inside of removeClippedSubviews
// See https://github.com/facebook/react-native/issues/6805 for original
// fix that was ported to here.
super.setTextIsSelectable(true);
if (mContainsImages) {
Spanned text = getText();
TextInlineImageSpan[] spans = text.getSpans(0, text.length(), TextInlineImageSpan.class);