Issue with rendering a list of elements in React Native FlatList or using the array mapping method.
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 127k
- Forks
- 25.3k
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 4
Description
Description
Hi,
I’m encountering an issue with the FlatList in React Native (or when using the array mapping method). The rendered items are stacking on top of the previous ones. Below is the code I'm working with. Could you please help me resolve this behavior?
Thank you!
Steps to reproduce
`import { useState } from 'react';
import {
Text,
SafeAreaView,
StyleSheet,
FlatList,
View,
TouchableOpacity,
} from 'react-native';
export default function App() {
const [showOptions, setShowOptions] = useState(false);
const [activeCard, setActiveCard] = useState(null);
return (
<FlatList
data={[0, 1, 2, 3, 4, 5]}
renderItem={({ item, index }) => (
<TouchableOpacity
style={styles.button}
onPress={() => {
setShowOptions(true);
setActiveCard(index);
}}
>
Click me
{showOptions && activeCard === index && (
)}
)}
ItemSeparatorComponent={() => }
contentContainerStyle={styles.listContent}
/>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
},
card: {
height: 100,
width: '100%',
backgroundColor: 'green',
borderRadius: 8,
position: 'relative',
},
button: {
position: 'absolute',
bottom: 10,
right: 10,
},
buttonText: {
color: '#fff',
fontWeight: 'bold',
},
optionsContainer: {
backgroundColor: 'yellow',
borderRadius: 8,
height: 80,
width: '50%',
position: 'absolute',
top: 80,
},
separator: {
height: 20,
},
listContent: {
padding: 20,
paddingBottom: 100,
},
});
`
This is the code
React Native Version
0.73.0
Affected Platforms
Runtime - Android, Runtime - iOS, Runtime - Web
Output of npx react-native info
NA
Stacktrace or Logs
NA
Reproducer
https://snack.expo.dev/nGlFBl-YeXppULXrGhsy9
Screenshots and Videos
https://github.com/user-attachments/assets/141325b0-1851-4067-8328-ce2b5a5f26d8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Snack reproducer and the provided App component, focusing on FlatList, the card and optionsContainer styles, and the state controlling the active card. Compare the behavior on the listed Android, iOS, and Web platforms; done means identifying a reproducible React Native issue and confirming its scope or documenting that it is caused by the example code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react-native
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100