From d457fb87d6b3278bee05661077d4c59434d61ab7 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Fri, 22 Nov 2024 10:19:49 +0100 Subject: [PATCH 1/2] Select only once --- .../com/facebook/react/views/textinput/ReactEditText.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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..6ea85fc6de77 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 hasSelectedTextOnFocus = 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() && !hasSelectedTextOnFocus) { // Explicitly call this method to select text when layout is drawn selectAll(); // Prevent text on being selected for next layout pass - mSelectTextOnFocus = false; + hasSelectedTextOnFocus = true; } } @@ -630,6 +631,7 @@ public void maybeUpdateTypeface() { // VisibleForTesting from {@link TextInputEventsTestCase}. public void requestFocusFromJS() { requestFocusInternal(); + hasSelectedTextOnFocus = true; } /* package */ void clearFocusFromJS() { From c2f3e3a26738d9be3c29012544d88d8e2369fcd7 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Tue, 26 Nov 2024 11:36:15 +0100 Subject: [PATCH 2/2] Rename field --- .../com/facebook/react/views/textinput/ReactEditText.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 6ea85fc6de77..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,7 +134,7 @@ public class ReactEditText extends AppCompatEditText { private boolean mContextMenuHidden = false; private boolean mDidAttachToWindow = false; private boolean mSelectTextOnFocus = false; - private boolean hasSelectedTextOnFocus = false; + private boolean mDidSelectTextOnFocus = false; private @Nullable String mPlaceholder = null; private Overflow mOverflow = Overflow.VISIBLE; @@ -251,11 +251,11 @@ public boolean isLayoutRequested() { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { onContentSizeChange(); - if (mSelectTextOnFocus && isFocused() && !hasSelectedTextOnFocus) { + 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 - hasSelectedTextOnFocus = true; + mDidSelectTextOnFocus = true; } } @@ -631,7 +631,7 @@ public void maybeUpdateTypeface() { // VisibleForTesting from {@link TextInputEventsTestCase}. public void requestFocusFromJS() { requestFocusInternal(); - hasSelectedTextOnFocus = true; + mDidSelectTextOnFocus = true; } /* package */ void clearFocusFromJS() {