Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Space between components in React Native styling

enter image description here

I have 6 View components (shown in the picture) , I want to have space between all 6 View components.

My code:

<View style={{flexDirection:'column',flex:6}}>             <View style={{flex:2,flexDirection:"row",justifyContent:'space-between'}}>                 <View style={{backgroundColor:'red',flex:1}}>                 </View>                 <View style={{backgroundColor:'blue',flex:1}}>                 </View>             </View>               <View style={{flex:2,flexDirection:"row",justifyContent:'space-between'}}>                 <View style={{backgroundColor:'white',flex:1}}>                 </View>                 <View style={{backgroundColor:'black',flex:1}}>                 </View>              </View>              <View style={{flex:2,flexDirection:"row",justifyContent:'space-between'}}>                 <View style={{backgroundColor:'gray',flex:1}}>                 </View>                 <View style={{backgroundColor:'yellow',flex:1}}>                 </View>              </View>    </View> 
like image 879
Behdad Avatar asked Aug 04 '17 09:08

Behdad


People also ask

How do you put a space between two components in React Native?

To add space between two elements on the same line in React Native, we can set justifyContent to 'space-between' in the View . to set the flexDirection to 'row' and the justifyContent style to 'space-between' to spread the Text components on the screen.

How do you add flex gap in React Native?

Using flexbox's gap in React Native Below, let's set the container's gap property to 1rem to add spacing of 1rem between items horizontally and vertically: import React, { useState } from "react"; import { StyleSheet, View } from "react-native"; export default function App() { return ( <> <View style={styles.

What is spacer in React Native?

A react-native component wrapper that avoiding keyboard when it displayed, support 'absolute' or 'fix' style position (while keyboardAvoidingView and react-native-keyboard-spacer doesn't)


1 Answers

Try to add padding to the element then and another blank view in each row, padding make space between each item

enter image description here

<View style={{       flexDirection:'column',       flex:1,     }}>         <View style={{flex:2,flexDirection:"row",justifyContent:'space-between',padding:10}}>             <View style={{backgroundColor:'red',flex:2,padding:10}}>             </View>           <View style={{flex:0.1}}/>             <View style={{backgroundColor:'blue',flex:2,padding:10}}>             </View>         </View>          <View style={{flex:2,flexDirection:"row",justifyContent:'space-between',padding:10}}>             <View style={{backgroundColor:'white',flex:2,padding:10}}>             </View>             <View style={{flex:0.1}}/>             <View style={{backgroundColor:'black',flex:2,padding:10}}>             </View>       </View>       <View style={{flex:2,flexDirection:"row",justifyContent:'space-between',padding:10}}>             <View style={{backgroundColor:'gray',flex:1,padding:10}}>             </View>             <View style={{flex:0.1}}/>             <View style={{backgroundColor:'yellow',flex:1,padding:10}}>             </View>         </View> 
like image 153
Maulana Prambadi Avatar answered Sep 20 '22 07:09

Maulana Prambadi