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

[Text] Text doesn't wrap #1438

Closed
bogdantmm92 opened this issue May 28, 2015 · 29 comments
Closed

[Text] Text doesn't wrap #1438

bogdantmm92 opened this issue May 28, 2015 · 29 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@bogdantmm92
Copy link

http://puu.sh/i407j/805ec722a0.png
Text doesn't wrap when it's wrapped inside :

msgReceivedAlignContainer: {
    flex: 1,
    flexDirection: 'column',
    alignItems: 'flex-w',
  },
@brentvatne
Copy link
Collaborator

@bogdantmm92 - can you post a complete minimal example on rnplay.org please?

@brentvatne brentvatne changed the title Text doesn't wrap [Text] Text doesn't wrap May 28, 2015
@bogdantmm92
Copy link
Author

Demo: https://rnplay.org/plays/21GRFQ

@brentvatne
Copy link
Collaborator

@bogdantmm92 - the problem is that it won't wrap because the flexDirection is row - it just continues flowing in that direction rather than downwards (as it would with column). I fixed this for you in this example on rnplay - thanks for providing an excellent sample! Makes the issue much easier to address

@bogdantmm92
Copy link
Author

Thanks for testing & fixing this so fast! Really appreciate it!

@uc-hus
Copy link

uc-hus commented Jul 29, 2016

How to break text of flexDirection: row view
image

@peter4k
Copy link

peter4k commented Aug 5, 2016

Try add flexWrap: "wrap" to the style of the Text component

@mvnnn
Copy link

mvnnn commented Sep 8, 2016

@peter4k That's not works in my case.

              <View style={{flexDirection:'row',flexWrap: 'wrap'}}>
              <Text> You miss fdddddd dddddddd You miss fdddddd dddddddd</Text>
              </View>

@peter4k
Copy link

peter4k commented Sep 9, 2016

@mvnnn You have to add it to your component, like:

<View style={{flexDirection:'row'}}>
       <Text style={{flexWrap: 'wrap'}}> You miss fdddddd dddddddd You miss fdddddd dddddddd</Text>
</View>

@mvnnn
Copy link

mvnnn commented Sep 10, 2016

@peter4k thanks, I also try this but that's not working inside card so i use "minWidth" and "maxWidth" and that's working great.

@a11y1337
Copy link

a11y1337 commented Sep 13, 2016

Hey there @mvnnn, I was able to get this to work by adding a 'flex: 1' property to the text element. Hopefully it works in your situation, as well.

<View style={{flexDirection:'row'}}> <Text style={{flex: 1, flexWrap: 'wrap'}}> You miss fdddddd dddddddd You miss fdddddd dddddddd</Text> </View>

@janaka120
Copy link

I think this also work

<View style={{flexDirection:'row', flex: 1, flexWrap: 'wrap'}}> <Text> You miss fdddddd dddddddd You miss fdddddd dddddddd</Text> </View>

@dwilt
Copy link

dwilt commented Feb 9, 2017

I tried @a11y1337 's method and it didn't work for me. I have a situation where I have text sitting in a View along side of another View and the text is running through the parent's padding and out of the parent's container:

image

Markup:

<View style={styles.container}>
    <AlbumCover
        image={album_cover}
        width={smallAlbumCover}
        height={smallAlbumCover}
        borderRadius={6}
    />
    <View style={styles.info}>
        <Text style={styles.title} allowFontScaling={false}>{title}</Text>
        <Text style={styles.author} allowFontScaling={false}>{author}</Text>
    </View>
</View>

Styles:

export default StyleSheet.create({
    container: {
        flexDirection: 'row',
        alignItems: 'center',
    },
    info: {
        flexGrow: 1,
        marginLeft: gutter,
    },
    title: {
        fontSize: 16,
        fontFamily: sansSerifLight,
        color: nearlyBlack,
    },
    author: {
        fontSize: 12,
        fontFamily: sansSerif,
        color: greyishBrown,
    }
});

As I said, I tried all of the the suggestions here and nothing seemed to work. WHAT DID WORK was adding a width: 0 to the info style:

info: {
    width: 0,
    flexGrow: 1,
    marginLeft: gutter,
},

and voilà:

image

@georgemickael-b
Copy link

@dwilt That helped!

@highbass
Copy link

@a11y1337 ... that saved me ton of headache! thank you.

@Tiger-NG
Copy link

thanks a lot, it is great help for me!

@IrvanWijaya
Copy link

@dwilt thanks for the solution. By the way what does the flexGrow do? I check it https://facebook.github.io/react-native/docs/layout-props.html there and it give me nothing.

thanks

@dwilt
Copy link

dwilt commented Mar 28, 2017

@IrvanWijaya read this guide which is probably implemented the same way on React Native.

@vardanmobiloitte
Copy link

Hello All,
I am using react native 0.28.0. and I am not able to wrap text in chat I am using react-native-gifted-chat . also I get error if I use maxWidth. Do anyone know workaround of maxWidth

hulkdx added a commit to hulkdx/react-native-crod that referenced this issue May 21, 2017
Solution found in this link: facebook/react-native#1438
@pavloko
Copy link

pavloko commented May 27, 2017

Hi all,

Text supports NumberOfLines property, not sure about the case described above, but maybe it can be an option.

<Text numberOfLines={2}/>

@gusgard
Copy link
Contributor

gusgard commented Jun 6, 2017

@dabit1 thanks!

Example that works:

Code

<View style={styles.container}>
  <Text style={styles.text}>{text}</Text>
</View>

Styles

export default StyleSheet.create({
  container: {
      flexDirection: 'row',
      alignItems: 'center',
  },
  text: {
    width: 0,
    flexGrow: 1,
    flex: 1,
  }
});

@pie6k
Copy link

pie6k commented Oct 13, 2017

After a bit of hard time I've found out that adding flexShrink: 1 to text container helped.

@maieonbrix
Copy link

So far @gusgard answer always worked for me but I just faced this issue and despite all of the documented solution no one actually worked except for that one :

I found this gem https://stackoverflow.com/questions/38233789/react-native-view-auto-width-by-text-inside. the accepted answer tells us that 👍

"alignSelf" does the same as 'display: inline-block' would in common HTML/CSS and it works very well for me.

I don't know you but I really didn't know. Just tested it and it worked like a charm.

@yordis
Copy link

yordis commented Dec 14, 2017

@pie6k solution is the best subjectively approach but put it on the Text that you want to wrap.

@benevbright
Copy link

@pie6k You saved my day. Many thanks for your sharing!

@charleylla
Copy link

this worked for me:

<View style={{flexGrow:1,width:0,flexDirection:"column",justifyContent:"center"}}>
    <Text >{handle_description}</Text>
</View>

@nanosoft-vivek
Copy link

screenshot_1516863404

@dmeehan1968
Copy link

All of the above solutions didn't work for me, I had a fairly complicated view hierarchy, simpler versions always worked as expected.

Also, I was using react-native-web, so coding to react-native standards, using View and Text components as the basis for all rendering. The above did allow me to resolve the issue on Native, but it didn't resolve it on Web.

The correct solution (for me) was to ensure that I had flex: 1 on ALL ancestors of the Text node that was not wrapping as expected.

So - check your view hierarchy, you can do this in the browser using the Element Inspector (Computed Styles), just walk up from the non-wrapping node and check for display: flex - anything missing flex is missing the corresponding flex: 1.

NB: Text nodes in react-native-web do not pass the flex property to the underlying div/span.

@maieonbrix
Copy link

@dmeehan1968 your solution solved this problem on one occasion thank you !

There are a lot of solutions to this problem

timothyej added a commit to blockfirm/pine-app that referenced this issue Apr 3, 2018
This commit fixes a visual bug that caused text not to wrap
properly for some paragraphs.

I was able to solve this thanks to this thread:
<facebook/react-native#1438>
@Fi2zz
Copy link

Fi2zz commented May 24, 2018

 <View style={style.textWrap}>
     <Text numberOfLines={your value} >
         Your very very very very very long text content
     </Text>
</View>

style ={
 textWrap:{ 
     width: your_certain_width
  }
}

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

No branches or pull requests