Skip to content

[Text] Text doesn't wrap  #1438

Closed
Closed

Description

@bogdantmm92

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

msgReceivedAlignContainer: {
    flex: 1,
    flexDirection: 'column',
    alignItems: 'flex-w',
  },

Activity

  1. brentvatne commented on May 28, 2015

    @brentvatne
    Collaborator

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

  2. changed the title [-]Text doesn't wrap [/-] [+][Text] Text doesn't wrap [/+] on May 28, 2015
  3. bogdantmm92 commented on May 28, 2015

    @bogdantmm92
    Author
  4. brentvatne commented on May 28, 2015

    @brentvatne
    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

  5. bogdantmm92 commented on May 28, 2015

    @bogdantmm92
    Author

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

  6. uc-hus commented on Jul 29, 2016

    @uc-hus

    How to break text of flexDirection: row view
    image

  7. peter4k commented on Aug 5, 2016

    @peter4k

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

  8. mvnnn commented on Sep 8, 2016

    @mvnnn

    @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>
    
  9. peter4k commented on Sep 9, 2016

    @peter4k

    @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>
    
  10. mvnnn commented on Sep 10, 2016

    @mvnnn

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

  11. a11y1337 commented on Sep 13, 2016

    @a11y1337

    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>

  12. janaka120 commented on Dec 20, 2016

    @janaka120

    I think this also work

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

  13. dwilt commented on Feb 9, 2017

    @dwilt

    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

  14. georgemickael-b commented on Feb 17, 2017

    @georgemickael-b

    @dwilt That helped!

  15. 5 remaining items

  16. added a commit that references this issue on May 21, 2017
  17. pavloko commented on May 27, 2017

    @pavloko

    Hi all,

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

    <Text numberOfLines={2}/>
    
  18. gusgard commented on Jun 6, 2017

    @gusgard
    Contributor

    @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,
      }
    });
    
  19. pie6k commented on Oct 13, 2017

    @pie6k

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

  20. mehdialouafi commented on Dec 5, 2017

    @mehdialouafi

    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.

  21. yordis commented on Dec 14, 2017

    @yordis

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

  22. benevbright commented on Dec 23, 2017

    @benevbright

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

  23. charleylla commented on Dec 27, 2017

    @charleylla

    this worked for me:

    <View style={{flexGrow:1,width:0,flexDirection:"column",justifyContent:"center"}}>
        <Text >{handle_description}</Text>
    </View>
    
  24. nanosoft-vivek commented on Jan 25, 2018

    @nanosoft-vivek

    screenshot_1516863404

  25. dmeehan1968 commented on Feb 4, 2018

    @dmeehan1968

    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.

  26. mehdialouafi commented on Feb 6, 2018

    @mehdialouafi

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

    There are a lot of solutions to this problem

  27. Fi2zz commented on May 24, 2018

    @Fi2zz
     <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
      }
    }
    
    
  28. locked as resolved and limited conversation to collaborators on May 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions