-
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 vincenzoddragon+five@gmail.com From vincenzoddrlxagon+five@gmail.com';
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: ### Problem The calculated width for a multiline text is based on the longest line. However it does not account for text that wraps. **Example** if numberOfLines=1 and the text wraps ``` +---------------------------+ This is a long text that will wrap +---------------------------+ ``` The TextView will render ``` +---------------------------+ This is a long text t... +---------------------------+ ``` because the `calculatedWidth` took the width of the first line. Also see #41770 (comment) for additional context. ### Solution If the text wraps, take the whole width. ``` +---------------------------+ This is a long text that w... +---------------------------+ ``` Fixes #39722 Fixes facebook/yoga#1730 ## Changelog: [GENERAL] [FIXED] - Fix text not taking full width Pull Request resolved: #47435 Test Plan: ```tsx <Text numberOfLines={1} style={{ backgroundColor: 'red', alignSelf: 'flex-start', color: 'white', fontSize: 34, }}> {'This is a long text that will wrap.'} </Text> <Text numberOfLines={3} style={{ backgroundColor: 'red', alignSelf: 'flex-start', color: 'white', fontSize: 34, }}> { '1\n\ntest\nThis is a long text that will wrap.This is a long text that will wrap.This is a long text that will wrap.\n' } </Text> <Text numberOfLines={3} style={{ backgroundColor: 'red', alignSelf: 'flex-start', color: 'white', fontSize: 34, }}> { '1\n\nThis is a long text that will wrap.This is a long text that will wrap.This is a long text that will wrap.\n' } </Text> ``` 1. Verify that the first and third text take full width 2. Verify that the second text does not take full width | Before | After | |:------:|:-----:| | <img width="480" alt="Screenshot 2024-11-05 at 9 00 24 PM" src="https://github.com/user-attachments/assets/b8d765c0-f4b1-42c6-afc7-75862c52612a"> | <img width="480" alt="Screenshot 2024-11-05 at 9 01 49 PM" src="https://github.com/user-attachments/assets/f1534c14-a56a-4d44-8edc-4d9f75166cb2"> | Reviewed By: NickGerleman Differential Revision: D65521732 Pulled By: realsoelynn fbshipit-source-id: 0bb0bb306445e73e8b24ff4c02921739d15ee07e
commit 550b0c0 landed, can we close this? |
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: