question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<Text numberOfLines={1} ellipsizeMode="middle"> crashes on Android

See original GitHub issue

Issue 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
kkgelucommented, May 16, 2017

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.

        <View style={{marginTop: 9,
                      height: 16,
                      width: 16,
                      borderRadius: 8,
                      justifyContent:'center',
                      backgroundColor:  badgeBackgroundColor,
                    }}>
          <Text numberOfLines={1} ellipsizeMode={'clip'}
              style={{
                color: textColor,
                fontSize: 12,
                alignSelf:'center',
                backgroundColor:'transparent'}}>
             {count}
          </Text>
       </View>
1reaction
hramoscommented, Jul 21, 2017

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:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

<Text numberOfLines={1} ellipsizeMode="middle"> crashes ...
Issue Description. When using. <Text numberOfLines={1} ellipsizeMode="middle">. , this will throw an error on Android in some situations.
Read more >
ellipsizeMode={'head'} did not work when numberOfLines > 1 ...
I am trying to show ... in the starting of the text but it is working when numberOfLines={1}. Code: <Text style={styles.
Read more >
[Solved]-React native determine when text is cut off-React Native
<Text numberOfLines={4} ellipsizeMode="tail" onPress={(e) ... let end = text.length - 1; while (start <= end) { const middle = start + (end -...
Read more >
Text - React Native Archive
A React component for displaying text. Text supports nesting, styling, and touch handling. In the following example, the nested title and body text...
Read more >
This Text Will CRASH ANY ANDROID APP!!! - YouTube
This Text will Crash any Android Application.. WhatsApp, WeChat, Text Msg.. It can crash any Android App.. Don't Touch It..
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found