Search code examples
cssreactjsreact-nativecss-in-js

react-native flatList, make negative space between each element


I tried to make a flatlist of image, but each image should be above the others:

enter image description here

<FlatList
    style={styles.listAvatar}
    data={item.etudiants}
    keyExtractor={(item, index) => index.toString()}
    renderItem={({ item, index }) => <ItemAvatar urlAvatar={item.avatar} />}
    horizontal
/>
const ItemAvatar = ({urlAvatar}:any) => {
    return (
            <Image
                style={{ width: 35, height: 35, borderRadius: 100}}
                source={{uri: urlAvatar}}
            />
    )
}

enter image description here

So I tried to do something like that:

<Image
    style={{ width: 35, height: 35, borderRadius: 100, marginRight: -15}}
    source={{uri: urlAvatar}}
/>

But I got:

enter image description here

The last image is cut..


Solution

  • you can try this

    <Image
        style={{
          width: 35,
          height: 35,
          borderRadius: 100,
          left: index * -15,
        }}
        source={{ uri: urlAvatar }}
    />