-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Fix single line text not fully rendered #41770
base: main
Are you sure you want to change the base?
Conversation
Base commit: 44f9371 |
This reverts commit 0da2607.
calculatedLineCount == 1 does not mean that text is single line, only that it has 1 line, but if adds more images, they need to wrap on second line.
Thanks for the code review.
I updated the solution to use StaticLayout instead of BoringLayout.
The new solution supports not boring text, emoji, RTL, etc (test cases).
I added the Fabric implementation and included tests of the functionalities on Fabric and Paper. |
@dmytrorykun has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@fabOnReact there is a new comment in the corresponding issue #39722 |
@realsoelynn this might be related to the measurement issues you are working on. |
Is this still being worked on / reviewed? Wondering if I need to use a workaround for all the text in my app or if a fix for this issue is likely to be merged before we ship. |
Sorry about missing this. This is NOT related to measurement issue that i was previously working on. @fabOnReact Please also attach I saw this issues on Expensify/App#43068 is closed and mentioned it's no longer reproducible. Do you mind retesting your test cases https://gist.github.com/fabOnReact/6a58c713d32ce5bb9c164b6906abac12?permalink_comment_id=4956212 with latest React Native version with New Architecture Enabled ? |
I tested again the test case with the latest React Native main branch and new architecture enabled. CLICK TO OPEN SOURCECODE
import * as React from 'react';
import {StyleSheet, Text, TextInput, View} from 'react-native';
export default function App() {
const email =
'From [email protected] From [email protected]';
return (
<>
<View style={styles.container}>
<View style={styles.flexBrokenStyle}>
<Text
style={styles.parentText}
numberOfLines={1}
>
{email}
</Text>
</View>
</View>
</>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
padding: 8,
backgroundColor: 'yellow',
},
flexBrokenStyle: {
flexDirection: 'row',
},
parentText: {
backgroundColor: 'red',
},
}); I added a log statement in TextLayoutManager.java and verified that we are running on the new architecture. The width is calculated with TextLayoutManager (newArchitecture). The text does not take the full width, because TextLayoutManager calculates the wrong width. Metro output shows Fabric is enabled.
The PR was not created to fix Issue Expensify/App#43068. The Expensify Issue is Expensify/App#21219.
OUTPUT OF NPX REACT-NATIVE INFO
|
The problem is that the created layout renders the text with line break enabled and what we end up measuring is just the first line which does not include all the text (since the rest wrapped). IOW we are measuring the text as if |
An alternate solution is to render the text without line break (setLineBreakConfig) but I got the app crashed trying to work with this one. Edit: This won't fix the problem if numberOfLines > 1 |
Summary:
Please re-state the problem that we are trying to solve in this issue.
ReactTextShadowNode#measure calculates the wrong width for single line Text that has an ellipsis (fixes #39722).
What is the root cause of that problem?
React Native sets the wrong width in the ReactTextShadowNode onMeasure function for single line Text, demonstrated with:
The android minimum reproducible example:
onMeasure
). It is not the expected/intended behavior on Android.What changes do you think we should make in order to solve the problem?
Set the correct width for single-line Text in the measure callback.
Changelog:
[ANDROID] [FIXED] - Fix single line text not fully rendered
Test Plan: