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

[Text-Input][Android][Fix]-fixes scroll on first render of textinput with default Value

Open Biki-das opened this issue 1 year ago • 3 comments

Reopen #43342 Closed due to mess up with the forked branch!

Summary:

On rendering The TextInput with defaultValue at a case when the text string is longer than the screen size , a weird behaviour follows on android, where the leftmost text characters gets cut off and hidden, the reason is the cursor which moves to the end.

The cause of the same to my understanding is how the text is getting updated inside the ReactEditText. it has a range which it replaces with the text provided, if the cursor is in close proximity , the same is moved to the end for the replaced text.

the solution that i used is pretty straightforward, we need to make sure our cursor's position should be at the start of the text for the first render, we can just simply use the setText() method from the EditText, while we create the editText for the first time in the render cycle. I have introduced a flag variable of isFirstRender initialised to true, this would allow us to call the EditText method and then eventually toggling it to false.

Changelog:

[ANDROID] [Fixed] - Fixes The Position of cursor on Overflowing Text on Android Text Input

Test Plan:

All Test Passing Checked on RN TESTER Long Text Behaviour section has been added to demonstrate the same

Before Screenshot_1709111184

After

Screenshot_1709111606

Biki-das avatar Mar 14 '24 11:03 Biki-das

cc @javache @NickGerleman

Biki-das avatar Mar 14 '24 11:03 Biki-das

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 18,127,401 +65
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 21,493,975 +86
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: 14a72029836ee42ce919112973afab87164bc6e9 Branch: main

analysis-bot avatar Mar 18 '24 12:03 analysis-bot

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

react-native-bot avatar Sep 17 '24 05:09 react-native-bot

This PR was closed because it has been stalled for 7 days with no activity.

react-native-bot avatar Sep 24 '24 05:09 react-native-bot

@Abbondanzo could you see if this is valuable? and may be reopen it.

Biki-das avatar Jan 11 '25 18:01 Biki-das

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

facebook-github-bot avatar Jan 17 '25 17:01 facebook-github-bot

will fix the lint failure, thanks for re-opening and checking it out!

Biki-das avatar Jan 17 '25 17:01 Biki-das

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

facebook-github-bot avatar Jan 17 '25 18:01 facebook-github-bot

@Abbondanzo let me know where the internal Linter tests failed.

Biki-das avatar Jan 17 '25 19:01 Biki-das

thanks @Abbondanzo for the review, yeah let me have a look at the same, to not have isFirstRender in the public api!

Biki-das avatar Jan 19 '25 17:01 Biki-das

friendly ping @Abbondanzo

Biki-das avatar Feb 06 '25 16:02 Biki-das

@Biki-das were you able to find a way around adding isFirstRender to the public API?

Abbondanzo avatar Feb 06 '25 21:02 Abbondanzo

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

react-native-bot avatar Aug 14 '25 05:08 react-native-bot

This PR was closed because it has been stalled for 7 days with no activity.

react-native-bot avatar Aug 21 '25 05:08 react-native-bot