- use
flexbox(because it is react-native) - parent container's width is a percentage
- item count can be 4/5/6/7..
- same gap spaces between items
- like picture below
Here is my code:
const styles = {
container: {
width: screenWidth * 0.9,
flexWrap: 'wrap',
flexDirection: 'row'
},
item: {
backgroundColor: 'red',
height: 120,
width: (width * 0.9 - 20) / 3,
marginBottom: 10
}
}
<View style={styles.container}>
{items.map((item, idx) =>
<View style={[styles.item, { marginHorizontal: idx % 3 === 1 ? 10 : 0}]} />
)}
</View>
Is there another better way to realize this layout?
