Vertically align a component in React Native

4.7k Views Asked by At

I want my items to be aligned like this: enter image description here

But somehow its like this: enter image description here

The code is:

 <View style={{flex: 1}}>
  <View style={{flexDirection: 'row'}>
    <Component.CircledIcon
       source={iconSource}
    />
    <Component.Text style={{fontWeight: 'bold',
      fontSize: '$regular',
      color: '$body',
      flex: 1,
      marginRight: '2.5rem',
      paddingBottom: '1rem',
    }}>
      {name}
    </Component.Text>
  </View>
 </View>
2

There are 2 best solutions below

3
On

Try this:-

<View style={{flex: 1}}>
<View style={{flexDirection: 'row'
alignItems:"center"  //add this line to your code
 }>
<Component.CircledIcon
   source={iconSource}
/>
<Component.Text style={{fontWeight: 'bold',
  fontSize: '$regular',
  color: '$body',
  flex: 1,
  marginRight: '2.5rem',
  paddingBottom: '1rem',
}}>
  {name}
</Component.Text>
0
On

U just have to add one attribute into the parent of components (in your view.)

justifyContent:"space-between"

Please refer this link that might help your for understanding the styling.

(React-Native Styling Cheat sheet)[https://github.com/vhpoet/react-native-styling-cheat-sheet]