Add a workaround for text being measured incorrectly when ending with an empty line
Summary:
It looks like StaticLayout used for measuring multiline text on the new architecture returns wrong metrics for the last line if it's empty, however, if it contains anything, then the returned values are correct.
Similar approach with measuring I was already used in ReactEditText: https://github.com/facebook/react-native/blob/258d8e51b451b221e557dad4647cbd210fe37392/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java#L1203-L1213
Changelog:
[ANDROID] [FIXED] - Fixed text being measured incorrectly when ending with an empty line on the new architecture
Test Plan:
I tested the change on this simple code on React Native 0.73.2 (with the new arch enabled)
import React from 'react';
import {useState} from 'react';
import {SafeAreaView, TextInput} from 'react-native';
export default function App() {
const [text, setText] = useState('ABC\nDEF\nGHI\n');
return (
<SafeAreaView style={{flex: 1}}>
<TextInput
value={text}
onChangeText={setText}
style={{borderWidth: 1, margin: 20, padding: 30}}
multiline
/>
</SafeAreaView>
);
}
Before:
https://github.com/facebook/react-native/assets/21055725/0787cc86-70c6-4238-b93a-87984e527a83
After:
https://github.com/facebook/react-native/assets/21055725/2acf619f-5cb4-4869-9576-cb8cc081c15b
| Platform | Engine | Arch | Size (bytes) | Diff |
|---|---|---|---|---|
| android | hermes | arm64-v8a | 16,798,999 | +7 |
| android | hermes | armeabi-v7a | n/a | -- |
| android | hermes | x86 | n/a | -- |
| android | hermes | x86_64 | n/a | -- |
| android | jsc | arm64-v8a | 20,190,313 | -5 |
| android | jsc | armeabi-v7a | n/a | -- |
| android | jsc | x86 | n/a | -- |
| android | jsc | x86_64 | n/a | -- |
Base commit: 6c8dfc89566d27c36f9ca3828bcf3a63dfcb6942 Branch: main
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.
Not stale
@cortinico has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@cortinico merged this pull request in facebook/react-native@bd323929dc5be5666ee36043babec7d981a095dc.
This pull request was successfully merged by @j-piasecki in bd323929dc5be5666ee36043babec7d981a095dc
When will my fix make it into a release? | How to file a pick request?
FYI that https://github.com/facebook/react-native/pull/46613 replaces this logic with a proper fix (we were not correctly propagating settings to TextPaint used for layout)