patterncssreactCritical
React native text going off my screen, refusing to wrap. What to do?
Viewed 0 times
whatscreenrefusingwrapnativereactoffgoingtext
Problem
The following code can be found in this live example
I've got the following react native element:
with the following styles:
This result
I've got the following react native element:
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
} = React;
var SampleApp = React.createClass({
render: function() {
return (
Here is a really long text that you can do nothing about, its gonna be long wether you like it or not, so be prepared for it to go off screen. Right? Right..!
Some other long text which you can still do nothing about.. Off the screen we go then.
);
}
});
AppRegistry.registerComponent('SampleApp', () => SampleApp);with the following styles:
var styles = StyleSheet.create({
container:{
flex:1,
flexDirection:'column',
justifyContent: 'flex-start',
backgroundColor: 'grey'
},
descriptionContainerVer:{
flex:0.5, //height (according to its parent)
flexDirection: 'column', //its children will be in a row
alignItems: 'center',
backgroundColor: 'blue',
// alignSelf: 'center',
},
descriptionContainerVer2:{
flex:0.5, //height (according to its parent)
flexDirection: 'column', //its children will be in a row
alignItems: 'center',
backgroundColor: 'orange',
// alignSelf: 'center',
},
descriptionContainerHor:{
//width: 200, //I DON\'T want this line here, because I need to support many screen sizes
flex: 0.3, //width (according to its parent)
flexDirection: 'column', //its children will be in a column
alignItems: 'center', //align items according to this parent (like setting self align on each item)
justifyContent: 'center',
flexWrap: 'wrap'
},
descriptionText: {
backgroundColor: 'green',//Colors.transparentColor,
fontSize: 16,
color: 'white',
textAlign: 'center',
flexWrap: 'wrap'
}
});This result
Solution
The solution to that issue is
Depending on your set up, you may also also need to add
The solution was discovered by Adam Pietrasiak in this thread.
flexShrink: 1.
Really really long text...
Depending on your set up, you may also also need to add
flexShrink: 1 to the ``'s parent as well, to get this to work, so play with that and you'll make it.The solution was discovered by Adam Pietrasiak in this thread.
Code Snippets
<View
style={{ flexDirection: 'row' }}
>
<Text style={{ flexShrink: 1 }}>
Really really long text...
</Text>
</View>Context
Stack Overflow Q#36284453, score: 271
Revisions (0)
No revisions yet.