<Text numberOfLines={1} ellipsizeMode="middle"> crashes on Android
See original GitHub issueIssue Description
When using <Text numberOfLines={1} ellipsizeMode="middle">
, this will throw an error on Android in some situations.
I’ve tracked this to an outstanding (but marked obsolete) issue in Android itself. People are suggesting to use singleLine=true rather than lines=1.
I think this can be fixed by changing setNumberOfLines
in ReactTextView.java to use setSingleLine() rather than setMaxLines(mNumberOfLines):
public void setNumberOfLines(int numberOfLines) {
mNumberOfLines = numberOfLines == 0 ? ViewDefaults.NUMBER_OF_LINES : numberOfLines;
if (mNumberOfLines == 1) {
setSingleLine();
} else {
setMaxLines(mNumberOfLines);
}
}
Unfortunately I’m unable to compile my forked version of React Native so I can’t test it. I’d love to contribute a fix though.
Steps to Reproduce / Code Snippets
Create the following and run it on Android:
<View style={{width: 150}}>
<Text numberOfLines={1} ellipsizeMode="middle">12345 12 12345678901234</Text>
</View>
This bug only happens in very specific situations. Both the size of the container and the length and proportion of word sizes matters. I haven’t tested on different devices, but I wouldn’t be surprised to find that screen resolution matters. I’m running this on a 5.0 inch 1920*1080 phone (~442 ppi) in portrait mode.
Expected Results
See https://cloud.githubusercontent.com/assets/321738/19646583/5cfcf35e-99fa-11e6-85ea-d94ef77d96fe.png
Additional Information
- React Native version: 0.35
- Platform(s) (iOS, Android, or both?): Android 5.0
- Operating System (macOS, Linux, or Windows?): macOS
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top GitHub Comments
RN 0.41: I am having crashes with ellipsizeMode={‘clip’}, as soon as I change to ‘middle’, ‘tail’ or ‘head’, the crash stops happening. Android only.
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we’re automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.