I have a FlatList with multiple columns:
<FlatList
numColumns={4}
ItemSeparatorComponent={this.renderSeparator}
...
</FlatList>
And a line separator:
renderSeparator = () => (
<View
style={{
backgroundColor: 'red',
height: 0.5,
}}
/>
);
But the separator only appear between rows, not between columns (even if i add width: 0.5
you can just add if else condition inside renderItems and check the index modulus to add separator.. I just use this one and everything works great.
something like :-
hope this will help you.
I watched your Expo. It is as below.
I assume you want as below.
To do this, It is not possible with
ItemSeparatorComponent
only. as Hazim Ali says, use different style per index.This is the complete example.
--
As far as I read the source code, when numColumns > 2, there is no itemseparator between columns. Itemseparator is only between row and row.
Here is example. When numColumns is set 4, four items are grouped to one cell. And one itemSeparator is put between cells.
You can add a View wrapper around your Text component and apply borderRight style to the View component, see example here: https://snack.expo.io/HJx68bKvb, try run in the Android emulator on Expo, the Expo's iOS emulator for some reason is not showing the border correctly, but is working on my local emulator.
You can play around with padding on View component and Text component to get the desired border position.
I am bit to the party but I ran into same problem and solved this problem by using this renderRow code. I have 2 columns in grid view. Please change column length by replacing X in index % X === 0 and index <= Y where Y is columns-1
You can provide a margin for each item and a negative margin for the container. This is a very common trick for CSS flex layout.
Click here to see my work
Sorry, I also did not find a way to add a column separator using properties in the flatlist component. So I just added the view outside the text component in the render item like this:
And this is the result:
I hope this is can help you. :)