Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 93c70db

Browse files
committed
make columns dynamic
1 parent 7acb7fd commit 93c70db

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export interface RNMasonryScrollViewProps extends ScrollViewProps {
1515
evenColumnStyle?: StyleProp<ViewStyle>;
1616
}
1717

18-
function generateMasonryGrid<T>(data: T[]): T[][] {
18+
function generateMasonryGrid<T>(data: T[], columns: number): T[][] {
1919
return data.reduce((collection: T[][], child: T, childIndex: number) => {
20-
const itemIndex = childIndex % 4;
20+
const itemIndex = childIndex % columns;
2121
if (collection[itemIndex]) {
2222
collection[itemIndex].push(child);
2323
} else {
@@ -36,7 +36,7 @@ const RNMasonryScrollView = ({
3636
evenColumnStyle = null,
3737
...otherProps
3838
}: RNMasonryScrollViewProps) => {
39-
const masonryGrid = generateMasonryGrid(children);
39+
const masonryGrid = generateMasonryGrid(children, columns);
4040

4141
return (
4242
<ScrollView {...otherProps}>

0 commit comments

Comments
 (0)