Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do an Horizontal ListView, or FlatList in react-native

I'm searching a way to make an horizontal ListView or FlatList In React-native.

like the image below:

enter image description here

I tried to managed it with Flex but it's make me stranges results, and always with a vertical ListView

If you got any idea, let me know.

Regards,

like image 200
G Clovs Avatar asked Feb 15 '17 09:02

G Clovs


People also ask

How do you make a FlatList horizontal in React Native?

To add a horizontal FlatList in React Native, we just set the horizontal prop of the FlatList to true . to add horizontal to FlatList . As a result, we can scroll through the FlatList items horizontally.

How do you scroll horizontally in FlatList React Native?

The FlatList component has a prop named as horizontal={} which support Boolean value True and False. The default value is False and if we define its value to True then it will make our FlatList horizontal with horizontal scrolling enabled.

What is difference between FlatList and ListView React Native?

FlatList - More performant compared to ListView. ListView rendering can get slow once the number of items grows larger. FlatList significantly improves memory usage and efficiency (especially for large or complex lists) while also significantly simplifying the props — no more dataSource necessary!


2 Answers

The answer is to add the horizontal property set to true.

Yeah now it's described in the doc: https://reactnative.dev/docs/flatlist#horizontal

So obviously a FlatList is a Child of a ScrollView so he got the Horizontal Bool.

  <FlatList     horizontal={true}     data={DATA}     renderItem={renderItem}     keyExtractor={(item) => item.id}     extraData={selectedId}   /> 

Ciao

like image 173
G Clovs Avatar answered Sep 28 '22 01:09

G Clovs


Thanks for the last answer, ListView is now deprecated.

solution with FlatList:

<FlatList     style={styles.videos_flatList}     horizontal={true}     data={data1}     renderItem={({item}) =>          <RowItem/>     }      ItemSeparatorComponent={() => {         return (             <View                 style={{                 height: "100%",                 width: 20,                 backgroundColor: "#CED0CE",                  }}             />         );     }}      keyExtractor={(item, index) => index.toString()} /> 
like image 23
Shlomi Fresko Avatar answered Sep 28 '22 00:09

Shlomi Fresko