React-native textAlign justify

Brunaine picture Brunaine · May 9, 2017 · Viewed 30.7k times · Source

Android

I tried to use the textAlign to make the text justified but it doesn't work.

<Text style={{textAlign: 'justify',color:'#1B3D6C', margin: 20}}>
Lorem ipsum dolor sit amet, et usu congue vocibus, ei sea alienum repudiandae, intellegam quaerendum an nam. Vocibus apeirian no vis, eos cu conguemoo scaevola accusamus. Et sea placerat persecutii oinn
</Text>

enter image description here

Edit : Ok , textAlign justify doesnt work on Android , so what im asking now if there is some solution to this? I really need!

Answer

Bruno Peres picture Bruno Peres · May 9, 2017

Android does not support text justification. The docs of React Native Text component about the style attribute says:

textAlign enum('auto', 'left', 'right', 'center', 'justify') : Specifies text alignment. The value 'justify' is only supported on iOS and fallbacks to left on Android.

A workaround for this limitation is to use a React Native WebView component. The content of the WebView can be an HTML code with the justified text. Like this:

<View style={{flex: 1}}>
    <WebView
        source={{ html: "<p style='text-align: justify;'>Justified text here</p>" }}
    />
</View>