31

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,

G Clovs
  • 2,442
  • 3
  • 19
  • 24

3 Answers3

61

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

G Clovs
  • 2,442
  • 3
  • 19
  • 24
11

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()}
/>
duan
  • 8,515
  • 3
  • 48
  • 70
Shlomi Fresko
  • 909
  • 11
  • 15
  • Thanks for this. I think this answer is more accurate based on Today's date. Things to note: - Convert the index to string else you'll receive a warning. - The item separator, which separates the elements of the list (very handy). – Karl Djotchuang Tamo Sep 09 '22 at 20:42
0

FlatList answers are above, but it is not the only way to make horizontal list in RN.

If you want to make display elements in React Native displayed in horizontal list the simplest way possible, you only need the Flex Direction as Row:

  myElement: {
    display: 'flex',
    flexDirection: 'row',
  },
Matteus Barbosa
  • 2,409
  • 20
  • 21