I tried to create a stack of images in React Native using a FlatList. I set the position to relative and made the items of the list positioned absolute. Then, I set their top and left to 0 to stack them, adjusting the z-index accordingly. However, the items are not displaying. Interestingly, they appear when I remove the position absolute property.
The code is something like this
<code><FlatList
style={styles.images}
data={images}
keyExtractor={(item) => item.id}
renderItem={({ item, index, separators }) =>(
<View
style={styles.imageContainer}
key={item.id}
>
<Image
source={item.image}
style={styles.image}
/>
</View>
)
/>
</code>
<code><FlatList
style={styles.images}
data={images}
keyExtractor={(item) => item.id}
renderItem={({ item, index, separators }) =>(
<View
style={styles.imageContainer}
key={item.id}
>
<Image
source={item.image}
style={styles.image}
/>
</View>
)
/>
</code>
<FlatList
style={styles.images}
data={images}
keyExtractor={(item) => item.id}
renderItem={({ item, index, separators }) =>(
<View
style={styles.imageContainer}
key={item.id}
>
<Image
source={item.image}
style={styles.image}
/>
</View>
)
/>
And the styles are
<code>images: {
height: 600,
alignSelf: "flex-start",
width: "100%",
position: "relative",
},
imageContainer: {
position: "absolute",
alignSelf: "flex-start",
top: 0,
left: 0,
},
image: {
height: imgHeight,
width: imgWidth,
resizeMode: "contain",
}
</code>
<code>images: {
height: 600,
alignSelf: "flex-start",
width: "100%",
position: "relative",
},
imageContainer: {
position: "absolute",
alignSelf: "flex-start",
top: 0,
left: 0,
},
image: {
height: imgHeight,
width: imgWidth,
resizeMode: "contain",
}
</code>
images: {
height: 600,
alignSelf: "flex-start",
width: "100%",
position: "relative",
},
imageContainer: {
position: "absolute",
alignSelf: "flex-start",
top: 0,
left: 0,
},
image: {
height: imgHeight,
width: imgWidth,
resizeMode: "contain",
}
New contributor
WALKER is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.