Replies: 10 comments
-
@wong2 , any news on this? |
Beta Was this translation helpful? Give feedback.
-
same needs |
Beta Was this translation helpful? Give feedback.
-
It's not implemented yet in the FlashList!
If you have more columns I still have a way to hack it! |
Beta Was this translation helpful? Give feedback.
-
if you have dynamic column number, you can try: const colNum = 4;
const gap = 8;
const renderRowItem = useCallback(({item, index}: any) => {
return (
<View
style={{
flexGrow: 1,
paddingLeft: index % colNum === 0 ? gap : 0,
paddingRight: index % 1 === 0 ? gap : 0,
paddingBottom: index % 1 === 0 ? gap : 0,
paddingTop: index < colNum ? gap : 0,
}}>
<RenderItemComponent {...item} />
</View>
);
}, []); |
Beta Was this translation helpful? Give feedback.
-
Although i am using tailwindcss with nativewind, you can use the same approach using stylesheet. const renderItem = React.useCallback(
({ item, index }: { item: BusinessType; index: number }) => (
<BusinessCard
className={cn("w-[95%]", {
"mr-auto": index % 2 === 0,
"ml-auto": index % 2 === 1
})}
{...item}
/>
),
[]
); with styles const renderItem = React.useCallback(
({ item, index }: { item: BusinessType; index: number }) => (
<BusinessCard
style={{
width: "95%",
marginRight: index % 2 === 0 ? "auto" : undefined,
marginLeft: index % 2 === 1 ? "auto" : undefined
}}
{...item}
/>
),
[]
); |
Beta Was this translation helpful? Give feedback.
-
How is this not already implemented?! |
Beta Was this translation helpful? Give feedback.
-
bump... we need this! |
Beta Was this translation helpful? Give feedback.
-
None of the above solutions worked for me - they all resulted in some columns being larger than others. After a lot of trial and error I landed on this which seems to work well for 2 or more columns, and keeps all columns the same width: const gap = 8;
const numCols = 4;
// Evenly distribute the gap width between each item (4 columns has 3 gaps)
const itemGap = (gap * (numCols - 1)) / numCols;
return (
<FlashList
renderItem={({ item, index }) => {
// Left margin increases for each column, right margin decreases for each column
// What's important is that marginRight + marginLeft === itemGap
const marginLeft = ((index % numCols) / (numCols - 1)) * itemGap;
const marginRight = itemGap - marginLeft
return (
<View
style={{
flexGrow: 1,
marginLeft,
marginRight,
}}
>
{'...'}
</View>
);
}}
/>
); With the example above you get 4 nicely spaced columns:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm implementing a two column list with FlashList,
ItemSeparatorComponent
are only added between rows, how can I add a gap between these two columns?Beta Was this translation helpful? Give feedback.
All reactions