From 12a50c0a442b78d9095398d955bec307cfcb0f69 Mon Sep 17 00:00:00 2001 From: "hy.harry.yu@gmail.com" Date: Sun, 4 Oct 2020 22:10:41 -0700 Subject: [PATCH] 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 --- .../com/facebook/react/views/textinput/ReactEditText.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 d8bac9ffb79..b5312d28ae5 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 @@ -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);