Skip to content

Instantly share code, notes, and snippets.

@DenisDov
Created September 13, 2024 08:16
Show Gist options
  • Save DenisDov/bc654323b8e8cfd2d7623a31dddb225c to your computer and use it in GitHub Desktop.
Save DenisDov/bc654323b8e8cfd2d7623a31dddb225c to your computer and use it in GitHub Desktop.
another react native grid
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