diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index c7506b7dfc90..f13e4a584f90 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -134,6 +134,7 @@ public class ReactEditText extends AppCompatEditText { private boolean mContextMenuHidden = false; private boolean mDidAttachToWindow = false; private boolean mSelectTextOnFocus = false; + private boolean mDidSelectTextOnFocus = false; private @Nullable String mPlaceholder = null; private Overflow mOverflow = Overflow.VISIBLE; @@ -250,11 +251,11 @@ public boolean isLayoutRequested() { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { onContentSizeChange(); - if (mSelectTextOnFocus && isFocused()) { + if (mSelectTextOnFocus && isFocused() && !mDidSelectTextOnFocus) { // Explicitly call this method to select text when layout is drawn selectAll(); // Prevent text on being selected for next layout pass - mSelectTextOnFocus = false; + mDidSelectTextOnFocus = true; } } @@ -630,6 +631,7 @@ public void maybeUpdateTypeface() { // VisibleForTesting from {@link TextInputEventsTestCase}. public void requestFocusFromJS() { requestFocusInternal(); + mDidSelectTextOnFocus = true; } /* package */ void clearFocusFromJS() {