react / react/react-native

Issue with rendering a list of elements in React Native FlatList or using the array mapping method.

Aperta
#47,048 15 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Component: FlatList Issue: Author Provided Repro Needs: Author Feedback Newer Patch Available Type: Old Architecture
Lingua principale
C++
Stelle
127k
Fork
25.3k
Merge medio
1g 23h
PR unite (30g)
4

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il riproduttore Snack collegato e il componente App fornito, concentrandoti su FlatList, sugli stili di card e optionsContainer e sullo stato che controlla la scheda attiva. Confronta il comportamento sulle piattaforme elencate Android, iOS e Web; il lavoro è completato quando è stato identificato un problema riproducibile di React Native e ne è stata confermata la portata, oppure è stato documentato che è causato dal codice di esempio.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, react-native
Ambito
mobile-dev
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.