[Layout] Text overflow in ListView with flexDirection: 'row'
Hi, I have problem with text overflow in ListView, when ancestor has set style flexDirection: 'row':

part of code:
render: function() {
return (
<View style={styles.container}>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderRow}
/>
</View>
);
},
renderRow: function (message, sectionID: number, rowID: number) {
return (
<View style={{flexDirection: 'row'}}>
<Image
source={{
uri: 'http://icons.iconarchive.com/icons/designbolts/free-male-avatars/128/Male-Avatar-icon.png',
}}
style={{flexWrap: 'wrap', width: 32, height:32}}
/>
<View style={{flexWrap: 'wrap'}}>
<Text>
{message}
</Text>
</View>
</View>
);
},
How to wrap text? Thanks.
I solved problem by set flex: 1 to wrapper view of text.
<View style={{flexDirection: 'row'}}>
<Image
source={{
uri: 'http://icons.iconarchive.com/icons/designbolts/free-male-avatars/128/Male-Avatar-icon.png',
}}
style={{width: 32, height:32}}
/>
<View style={{flex: 1}}>
<Text>
{message}
</Text>
</View>
</View>
@michalraska - that's the right way to go! Thanks for updating with your solution, should be helpful to others who have the same issue.
Setting flex: 1 will trigger the underlying text to wrap, but what if you want your view to grow with the text, and then wrap when it reaches the boundary?

The temporary hack I'm using right now is conditionally adding flex: 1, based on the content length. Of course this is pretty imprecise, and doesn't take into consideration orientation or variations in device resolution.
@brentvatne I just found the this solution only works if flex: 1 is apllied to the view immediately beneath the one where flexDirection: 'row' is being applied to.
Example: https://rnplay.org/apps/B8mUMw
If one removes the second view or applies flex: 1 to it it works, otherwise it won't.
Is this intended behaviour?
@despairblue - initially I was a bit confused but realize that it does indeed make sense - by setting flexDirection: 'row' we are telling it to flex on the horizontal axis. If you change that to column on the container it works as you would expect.
@brentvatne right, it's a contrived example, by not using row in the first place this does not happen, but let's assume I need to use row because I want to do something like @michalraska. I've updated the example above and made a drawing to elaborate on it:

It seems in row 1 the view with the question mark simply keeps growing to the right, thus the containing view never wraps. That's what I meant by the view immediately beneath the one where flexDirection: 'row' is applied needs to have flexDirection: 'column' applied. Knowing this it's perfectly fine to avoid it, though finding this out took me some time, I just wonder if this is intended behaviour?
@brentvatne is there a way to do this without using flex : 1, in my case i have multiple components stacked across a view with flexDirection : 'row'
what i want is each component to render to its full width, and if it overflows then go to the next line.
Using flex : 1, means that each component has the same width , which is not what i want, which means there's a lot of unwanted blank space.
in the screenshot you can see that the first row has less space between the emoticon and the space character, whereas the third row has far more spacing since other components aren't there

thanks for any help that you provide :)
cc @vjeux - not quite sure about the above, maybe you have some insight
ping @vjeux ? any ideas on this... i have to use webviews atm to get around this, and the performance isnt really great.
I believe what you're trying to do isn't achievable with this layout system right now. I ran into the same problem. I solved this by creating a native bridge to a function which does something like this:
let label = UILabel()
label.font = UIFont(name: "Avenir", size: 16.0)
label.text = THETEXT
return label.intrinsicContentSize().width

@abhoopathy Why didnt you try hooking that up directly in the RCTTextView.m or something like that ... wouldn't that make it much easier ? Plus also save computation on creating the unnecessary UILabel ?
That's probably a good idea. By not using the UILabel, are you suggesting using NSString's sizeWithFont? (discussed here http://stackoverflow.com/questions/1324379/how-to-calculate-the-width-of-a-text-string-of-a-specific-font-and-font-size)
@abhoopathy maybe sizeWithAttributes would be better since sizeWithFont is deprecated . However, I think I should have said RCTText.m instead of RCTTextView.
Good idea
@abhoopathy - any success with that?
Is there any update here? :)
Haven't heard back for like, forever (sorry I'm on a plane to LA, just embracing it), so I'm closing
If you feel the same pain, please let the team know HERE. I still seem to face the same problem. Also I opened an issue here in case someone can provide a solution specifically to my problem.
This issue should not be closed. Basically, if you use flexDirection : 'row', text wrapping doesn't work. There doesn't seem to be a clear workaround. Using flex : 1 now collapsed your content to nothing/invisible, so that workaround is gone. A very basic layout aspect is now a total time wasting nightmare. Please fix this!