Skip to content
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

flexDirection: row breaks numberOfLines in nested <Text/> #4733

Closed
doochik opened this issue Dec 11, 2015 · 14 comments
Closed

flexDirection: row breaks numberOfLines in nested <Text/> #4733

doochik opened this issue Dec 11, 2015 · 14 comments
Labels
JavaScript Resolution: Locked This issue was locked by the bot.

Comments

@doochik
Copy link
Contributor

doochik commented Dec 11, 2015

The actual result I want to get is

<View>
<Text>Long truncated text...</Text> <Text>Fixed string on same line</Text>
</View>

I tried some cases, but it seems that flex breaks Text@numberOfLines

// works but "Fixed" on the new line
<View style={{padding: 20}}>
    <Text numberOfLines={1}>
        1. This text is truncated This text is truncated This text is truncated
    </Text>
    <Text>Fixed</Text>
</View>

// text is not truncated, padding is ignored
<View style={{padding: 20, flexDirection: 'row'}}>
    <Text numberOfLines={1}>
        2. This text is truncated 2. This text is truncated 2. This text is truncated
    </Text>
    <Text>Fixed</Text>
</View>

// text is not truncated, padding is ignored
<View style={{padding: 20, flexDirection: 'row'}}>
    <Text numberOfLines={1} style={{flex: 1, overflow: 'hidden'}}>
        3. This text is truncated 3. This text is truncated 3. This text is truncated
    </Text>
    <Text>Fixed</Text>
</View>

// text is not truncated, padding is ignored
<View style={{padding: 20, flexDirection: 'row'}}>
    <Text numberOfLines={1} style={{flex: 1, overflow: 'hidden', minWidth: 0}}>
        4. This text is truncated 4. This text is truncated 4. This text is truncated
    </Text>
    <Text>Fixed</Text>
</View>

// text is not truncated, padding is ignored
<View style={{padding: 20, flexDirection: 'row'}}>
    <Text numberOfLines={1} style={{overflow: 'hidden'}}>
        5. This text is truncated 5. This text is truncated 5. This text is truncated
    </Text>
    <Text style={{flex: 1}}>Fixed</Text>
</View>

Here is my result

2015-12-11 21-23-28 iphone 5s - iphone 5s ios 9 0 13a344

@facebook-github-bot
Copy link
Contributor

Hey doochik, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If this is a feature request or a bug that you would like to be fixed by the team, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • If you don't know how to do something or not sure whether some behavior is expected or a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • We welcome clear issues and PRs that are ready for in-depth discussion; thank you for your contributions!

@hufeng
Copy link

hufeng commented Jan 15, 2016

+1

2 similar comments
@zoontek
Copy link
Contributor

zoontek commented Jan 15, 2016

+1

@pocman
Copy link

pocman commented Jan 15, 2016

+1

@9mm
Copy link

9mm commented Mar 17, 2016

Have any of you guys found workarounds for this? Not sure how to go about doing this...

@mikelambert
Copy link
Contributor

mikelambert commented Apr 13, 2016

I had the same issue, and spent 45m+ trying to figure out why this worked: http://stackoverflow.com/questions/36284453/react-native-text-going-off-my-screen-refusing-to-wrap-what-to-do but my code did not.

Looks like my top-most Component had a style containing alignItems: 'center', which caused the above problem to happen for me. Have a look here: https://rnplay.org/apps/Usel7g (change the parent from fixedContainer to brokenContainer to see things break).

I still believe this represents some sort of bug in React, and should remain open. (Or at least, something that needs more thorough documentation to clarify the layout model here in this action-at-a-distance of sorts), but at least I have a workaround that works for me.

mikelambert added a commit to DanceDeets/dancedeets-react that referenced this issue Apr 17, 2016
@fov42550564
Copy link

just use View wrap it,

<View style={{width: screen.width}}>
    <Text>Long truncated text...</Text>
</View>

it work fine for me

@jzzj
Copy link

jzzj commented Jun 23, 2016

I have a very simple solution:
change this:
<Text numberOfLines={1} >long text....</Text>
to:
<View style={{flex: 1}}> <Text numberOfLines={1} >long text....</Text> </View>

This solved my problem.

@jzzj
Copy link

jzzj commented Jun 23, 2016

@facebook-github-bot fixed.

@oureta
Copy link

oureta commented Sep 21, 2016

numberOfLines does not work on Text nested inside Text

@ericnakagawa
Copy link
Contributor

Hi @doochik, are you still experiencing this issue? Seems like the suggested solution of wrapping it in a is workable?

As for numberOfLines not working properly, @oureta can you put together a PR?

@oureta
Copy link

oureta commented Jan 12, 2017

Hi @ericnakagawa, i just do JS.

@doochik
Copy link
Contributor Author

doochik commented Jan 13, 2017

@ericnakagawa I've tested my examples in RN 0.40. This example works as expected

                <View style={{padding: 20, flexDirection: 'row'}}>
                    <Text numberOfLines={1} style={{flex: 1, overflow: 'hidden'}}>
                        3. This text is truncated 3. This text is truncated 3. This text is truncated
                    </Text>
                    <Text>Fixed text</Text>
                </View>

@doochik doochik closed this as completed Jan 13, 2017
@mr-piratman
Copy link

@doochik it is working only for numberOfLines={1}.
if you use a different number of lines it makes all of the shorter...

@facebook facebook locked as resolved and limited conversation to collaborators Jul 20, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
JavaScript Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests