Search code examples
react-nativeflexboxflatlist

Handling space-between in flatlist when numColumns is 3


I have numColumns 3 in flatlist. I want my flatlist to be shown as

ooo
oo

not

ooo
o o

If my data is data%3==2

Here is my code

columnWrapperStyle={{justifyContent:'space-between'}}

And my component's width is (width-6)/3 so it needs 3 px space


Solution

  • Assuming your data is running over a state then you can try the following

    columnWrapperStyle={{justifyContent: data%3 == 2 ? 'flex-start' : 'space-between'}}