Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alignItems: baseline not working on Android

Tags:

react-native

I'm trying to have a phrase, which has different font-sizes all aligned on bottom and so, I have done the following:

<View style={styles.header}>
  <TextCustomized style={styles.balance} text="você tem" />
  <TextCustomized style={styles.number} text=" R$" />
  <TextCustomized style={styles.integer} text="100" />
  <TextCustomized style={styles.number} text=",00" />
  <TextCustomized style={styles.balance} text=" de saldo" />
</View>

const styles = StyleSheet.create({
  header: {
   flexDirection: 'row',
   alignItems: 'baseline',
   justifyContent: 'center',
   paddingTop: 10,
   borderBottomWidth: 1,
   borderBottomColor: '#e1e1e1',
   paddingBottom: 10,
 },
 balance: {
   fontSize: 14
 },
 number: {
  fontSize: 18,
  color: '#0778e4',
  fontWeight: 'bold',
 },
 integer: {
   fontSize: 30,
   color: '#0778e4',
   fontWeight: "800",
   lineHeight: 30,
 },
})

It works perfectly on iOS, but on Android it doesn`t work as it should, as you can see on this PS.

enter image description here

How can I achieve it?

like image 884
Morris Avatar asked Oct 18 '25 21:10

Morris


1 Answers

As a workaround, you can wrap the text you want aligned baseline into a Text element. The alignItems: baseline in the parent will be unnecessary at that point. Something like this should work:

<View style={styles.header}>
  <Text>
    <TextCustomized style={styles.balance} text="você tem" />
    <TextCustomized style={styles.number} text=" R$" />
    <TextCustomized style={styles.integer} text="100" />
    <TextCustomized style={styles.number} text=",00" />
    <TextCustomized style={styles.balance} text=" de saldo" />
  </Text>
</View>

const styles = StyleSheet.create({
  header: {
   flexDirection: 'row',
   justifyContent: 'center',
   paddingTop: 10,
   borderBottomWidth: 1,
   borderBottomColor: '#e1e1e1',
   paddingBottom: 10,
 },
 balance: {
   fontSize: 14
 },
 number: {
  fontSize: 18,
  color: '#0778e4',
  fontWeight: 'bold',
 },
 integer: {
   fontSize: 30,
   color: '#0778e4',
   fontWeight: "800",
   lineHeight: 30,
 }
});

React Native Align Baseline Android

like image 109
Ben Kane Avatar answered Oct 22 '25 06:10

Ben Kane



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!