-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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 |
Thanks @dmytrorykun, could we land this PR? Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forwarding an internal comment:
- The premise that we need to use the simpler
BoringLayout
to get the max width text could take without breaking seems strange.StaticLayout
has options to not line break (maybe we should be setting that for single line instead?)- This will leave the bug when there is a unicode, RTL, or other complicated character.
- This code is duplicated into Fabric (
TextLayoutManager.java
and now some more variants), and this code does not change anything there. If has same issue, we introduce new Fabric regression to Paper. If it isn't there, it has a different solution probably.
// StaticLayout#getLineWidth does not work with single-line text. | ||
boolean overrideTextBreakStrategySingleLine = | ||
boring == null | ||
? false | ||
: mNumberOfLines == 1 && !mAdjustsFontSizeToFit && boring.width > width; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
// StaticLayout#getLineWidth does not work with single-line text. | |
boolean overrideTextBreakStrategySingleLine = | |
boring == null | |
? false | |
: mNumberOfLines == 1 && !mAdjustsFontSizeToFit && boring.width > width; | |
// StaticLayout#getLineWidth does not work with single-line text. | |
boolean overrideTextBreakStrategySingleLine = | |
boring != null && mNumberOfLines == 1 && !mAdjustsFontSizeToFit && boring.width > width; |
and we avoid the ternary?
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
|
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: