react-native icon indicating copy to clipboard operation
react-native copied to clipboard

fix (iOS): fix `selectTextOnFocus` in Fabric and non-Fabric by calling `selectAll` after `becomeFirstResponder`

Open haileyok opened this issue 1 year ago • 2 comments

Summary:

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

Hopefully even if this isn't the right way to go about solving this, it at least points in the right direction for a different fix!

Currently - both on Paper and Fabric - the selectTextOnFocus prop does not work as expected on a single line text input. It seems that if the UITextField has not yet become the first responder, the text will be briefly selected but then deselected immediately afterward.

This can be seen in the tester when running for either Fabric or Paper (video using Fabric)

https://github.com/facebook/react-native/assets/153161762/aa9c609e-6eb8-4177-a41f-32aae53c06ac

Instead, we can move the selectAll call to reactFocus in RCTBaseTextInputView or focus RCTTextInputComponentView - both of which first call becomeFirstResponder - to get the expected result.

Changelog:

[IOS] [FIXED] - fix selectTextOnFocus in Fabric and non-Fabric by calling selectAll after becomeFirstResponder

Test Plan:

See the rn-tester above prior to these changes. Then test the same against this PR.

https://github.com/facebook/react-native/assets/153161762/8378157c-06e7-424c-a83c-fa71d737dc61

haileyok avatar Apr 29 '24 06:04 haileyok

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 19,626,370 -817,403
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 22,834,253 -808,216
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 5df5ed1a88a7119f9837e19169486522e615f93a Branch: main

analysis-bot avatar Apr 29 '24 07:04 analysis-bot

@fabriziocucci has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Apr 29 '24 10:04 facebook-github-bot

@fabriziocucci Is anything blocking getting this in? Did the diff fail internally?

gaearon avatar Jun 17 '24 07:06 gaearon

@fabriziocucci Is anything blocking getting this in? Did the diff fail internally?

@gaearon just added a small comment but otherwise LGTM, happy to merge it today.

fabriziocucci avatar Jun 17 '24 10:06 fabriziocucci

@fabriziocucci has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Jun 18 '24 08:06 facebook-github-bot

@fabriziocucci merged this pull request in facebook/react-native@cdab5370af7647d00cdf71a5e6134569ce66dc2b.

facebook-github-bot avatar Jun 18 '24 15:06 facebook-github-bot

This pull request was successfully merged by @haileyok in cdab5370af7647d00cdf71a5e6134569ce66dc2b.

When will my fix make it into a release? | How to file a pick request?

github-actions[bot] avatar Jun 18 '24 15:06 github-actions[bot]