Created
September 13, 2024 08:16
-
-
Save DenisDov/bc654323b8e8cfd2d7623a31dddb225c to your computer and use it in GitHub Desktop.
another react native grid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const FlexibleGrid = ({ columns, children }) => { | |
const columnWidth = 100 / columns; | |
return ( | |
<View style={{ flexDirection: "row", flexWrap: "wrap" }}> | |
{React.Children.map(children, (child, index) => { | |
return ( | |
<View | |
key={index} | |
style={{ | |
height: "100%", | |
width: `${columnWidth}%`, | |
aspectRatio: 1, | |
}}> | |
{child} | |
</View> | |
); | |
})} | |
</View> | |
); | |
}; | |
<FlexibleGrid columns={3}> | |
<Text>1</Text> | |
<Text>2</Text> | |
<Text>3</Text> | |
<Text>4</Text> | |
<Text>5</Text> | |
</FlexibleGrid> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment