Sometimes, we want to show 2 items per row with React Native.
In this article, we’ll look at how to show 2 items per row with React Native.
How to show 2 items per row with React Native?
To show 2 items per row with React Native, we can set flexDirection
to 'row'
and flexWrap
to 'wrap'
.
For instance, we write:
import * as React from 'react';
import { Text, View } from 'react-native';
import Constants from 'expo-constants';
import { Card } from 'react-native-paper';
export default function App() {
return (
<View style={{ flexDirection: 'row', flexWrap: 'wrap' }}>
{Array(100)
.fill()
.map((_, i) => {
return (
<View style={{ width: '50%' }}>
<Text>{i}</Text>
</View>
);
})}
</View>
);
}
to set flexDirection
and flexWrap
so we get a horizontal flex layout and we wrap overflowing components to the next row.
Then we set each View
‘s width to 50% so that they take half the width of the screen.
Conclusion
To show 2 items per row with React Native, we can set flexDirection
to 'row'
and flexWrap
to 'wrap'
.