Reputation: 21
I have some text paragraph like this:
<Text>
<Text>1111</Text>
<Text>2222</Text>
<Text style={{textAlign:"center"}}>
<Text>3333</Text>
</Text>
<Text>4444</Text>
<Text>5555</Text>
</Text>
It shows like:
11112222333344445555
While I want it to show like:
11112222
3333
44445555
in which 3333 is textAlign Center
how can I do this?
I tried to set flexDirection, but it did not work.
The data stuct is a little complicated, such as
{
{ text : 'aaaa'}
{ text: [
{
text: [
{ text: 'bbbb' },
{ text: 'cccc', style:'bold' },
{
text : '3333',
style: 'center'
},
{ text: 'dddd'},
], style: 'bold'
},
{ text: 'eeee' }
]},
{ text: 'ffff', style:'i' },
{ text: 'gggg' }
}
Because View Component cannot be nested in Text Component, so I can not change the Text wrapped 3333 to View.
Upvotes: 2
Views: 73
Reputation: 1289
this is working for me
<View style={{ width: '100%', flexDirection: 'column' }}>
<Text style={{ width: '100%' }}>1111</Text>
<Text style={{ width: '100%' }}>2222</Text>
<Text style={{ textAlign: "center", width: '100%' }}>
<Text>3333</Text>
</Text>
<Text style={{ width: '100%' }}>4444</Text>
<Text style={{ width: '100%' }}>5555</Text>
</View>
Upvotes: 0
Reputation: 45
Use a View
component as a container then wrap the items you want inline in a Text component. example here
Edit 1:
estructure exampe:
<View>
<text>
<Text>1111</Text>
<Text>2222</Text>
</text>
<Text style={{textAlign:"center"}}>
<Text>3333</Text>
</Text>
<text>
<Text>4444</Text>
<Text>5555</Text>
</text>
</View>
Upvotes: 1
Reputation: 243
try this.
<Text>
<Text>1111</Text>
<Text>2222</Text>
<Text style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Text>3333</Text>
</Text>
<Text>4444</Text>
<Text>5555</Text>
</Text>
Upvotes: 0
Reputation: 1099
You can use View as I mentioned here.
<View style={{alignItems:'flex-start'}}>
<Text>111111</Text>
</View>
<View style={{alignItems:'center'}}>
<Text>2222222</Text>
</View>
<View style={{alignItems:'flex-start'}}>
<Text>333333</Text>
</View>
Upvotes: 0