Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native: textAlign: 'right' not styling correctly

I'm quite new to react-native css-styling.. and have the following code:

 <Text> <Text style={(styles.author, { textAlign: "left" })}>     {question.view_count + " views\t" + question.comment_count}     {question.comment_count > 1 || question.comment_count == 0         ? " comments"         : " comment"} </Text> <Text style={{ textAlign: "right" }}>     {question.solution_count > 0         ? question.solution_count + " solutions"         : " Solve this"} </Text> </Text>; 

The problem is the second "textAlign: 'right' " isn't working - the text is still on the left. I want the text to be on the same line, but (obviously) the second text-object on the right.

Any hints? thanks!

edit output looks like this: Screenshot

like image 584
dv3 Avatar asked Aug 12 '16 11:08

dv3


People also ask

How do you make text left Align in React Native?

textAlign Props textAlign use for align text in react native like left, right, etc. Specifies text alignment. On Android, the value 'justify' is only supported on Oreo (8.0) or above (API level >= 26). The value will fallback to left on lower Android versions.

How do you align text in react?

Center Text Horizontally in React When working on a page, we have to align text towards, right, left, or center. It is very easy to align text in React using textAlign property inside style in index. tsx file. Another way to center the text for multiple elements is by adding the css code in the style.


1 Answers

Work-around -

<View style={{flex: 1, flexDirection: 'row'}}>   <View style={{flex: 1}}>     <Text>4 Views 0 Comments</Text>   </View>   <View style={{flex: 1}}>     <Text style={{textAlign: 'right'}}>Solve This</Text>   </View> </View> 
like image 169
Mihir Avatar answered Sep 22 '22 21:09

Mihir