-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Select text inside TextInput only once from onLayout
#47902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there other cases in Reanimated where props are reapplied multiple times? There are other places where that will cause problems, e.g. for ScrollView setting the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not strictly Reanimated reapplying props - it's this part of the code: react-native/packages/react-native/ReactCommon/react/renderer/core/ShadowNode.cpp Lines 56 to 62 in d86412d
which relies on the previous node being mounted to apply only the props diff. This assumption is broken by Reanimated at the moment, but it's going to be fixed in the future. I think wrong behavior here was caused by the same field being used to store a prop and the view state at the same time. |
||||||||||||||||
hasSelectedTextOnFocus = true; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
@@ -630,6 +631,7 @@ public void maybeUpdateTypeface() { | |||||||||||||||
// VisibleForTesting from {@link TextInputEventsTestCase}. | ||||||||||||||||
public void requestFocusFromJS() { | ||||||||||||||||
requestFocusInternal(); | ||||||||||||||||
hasSelectedTextOnFocus = true; | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we avoid the onLayout focus here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original PR added this behavior to fix |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/* package */ void clearFocusFromJS() { | ||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.