Fix Multiline TextInput with a fixed height scrolls to the bottom when prepending new lines to the text #60
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Upstream PR Link
Upstream PR facebook#38679
fixes Expensify/App#19507
Summary:
Please re-state the problem that we are trying to solve in this issue.
Multiline TextInput with a fixed height will scroll to the bottom of the screen when prepending new lines to the text.
What is the root cause of that problem?
The issue is caused by iOS UITextView:
The behavior was reproduced on an iOS App (without react-native).
The example included below implements a Component RCTUITextView based on UITextView, which modifies the UITextView attributedText with the textViewDidChange callback (source code available in this comment).
Adding a new line on top of the UITextView on iOS results in:
Issue 1) The cursor moves to the end of TextInput text
Issue 2) The TextInput scrolls to the bottom
Reproducing the issue on an iOS App without react-native
2023-06-17.18-16-16.mp4
Issue 1) is already fixed in react-native, which restores the previous cursor position (on Fabric with _setAttributedString) after changing the text.
Issue 2) needs to be fixed in react-native.
What changes do you think we should make in order to solve the problem?
Disable scrollingEnabled when changing the attributedText.
Changelog:
[IOS] [FIXED] - Fix Multiline TextInput with a fixed height scrolls to the bottom when prepending new lines to the text
Test Plan:
Fabric (reproduces on controlled/not controlled TextInput example):
Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-07-29.at.11.57.04.mp4
Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-07-29.at.11.55.11.mp4
Paper (reproduces only on controlled TextInput example):
Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-07-29.at.13.05.48.mp4
Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-07-29.at.13.09.48.mp4
Expensify
Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-07-29.at.13.36.02.mp4
Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-07-29.at.13.39.42.mp4