Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate "align-items: baseline" in React Native?

Since there is no "align-items: baseline" in RN's implementation of Flexbox, how can I align the baselines of two text element horizontally?

enter image description here

The JSX:

<View style={styles.numberAndPercent}>
  <Text style={styles.number}>6.80</Text>
  <Text style={styles.percent}>%</Text>
</View>
like image 234
irrigator Avatar asked Mar 24 '16 02:03

irrigator


People also ask

How do you align items in Center in react native?

Syntax: alignItems: stretch|center|flex-start|flex-end|baseline; Property Values: stretch: It is the default value of alignItems.

How do you align an item right in react native?

Use textAlign: 'right' on the Text element (This approach doesn't change the fact that the Text fills the entire width of the View ; it just right-aligns the text within the Text .)


1 Answers

React Native now supports alignItems: 'baseline', so the following should work:

numberAndPercent: {
  flexDirection: 'row',
  alignItems: 'baseline',
}

Flexbox docs here; full list of supported values here.

like image 114
Kevin Cooper Avatar answered Oct 17 '22 23:10

Kevin Cooper