Multiline text with different widths?

273 Views Asked by At

Is it possible to make a multiline text where the lines are different lengths in React Native?

My situation with an example address (could be any string) where the same length rows:

const address = 'Circular Quay, Alfred St, Sydney 2021 NSW Alexandria';
return ( 
    <View style={{width: 80}}>
        <Text>{address}</Text>
    </View>
)

Desired result:

multiline text with different widths

Thanks!

2

There are 2 best solutions below

3
On

You can reach this by applying different widths in the texts styles

<Text style={{width='200'}}>Text 1</Text>
<Text style={{width='100'}}>Text 2</Text>
0
On

Solution to your problem can be textAlign prop in Text Component.

<View style={{width: 80}}>
    <Text style={{ textAlign:'center'}}>{address}</Text>
</View>