Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
¿Cómo seleccionar el primer elemento en FlatList como predeterminado?

Estoy tratando de usar Flatlist como Sidebar, pero se inicia solo después de hacer clic en él. ¿Hay alguna forma de que pueda hacer que el primer elemento de la lista plana sea el predeterminado? En otras palabras, el trabajo al hacer clic debería ocurrir antes de que se cargue la página, como en LifecycleHooks. También sugiérame si hay alguna forma de crear una barra lateral dinámicamente en lugar de usar Flatlist.

 <FlatList data={Object.keys(this.state.groups)} renderItem ={({ item, index }) => ( <TouchableOpacity onPress={() => { this.showDetails(item),this.setState({itemIndex:index}) }} // onPress={() => alert(item)} > {console.log(index,"index of cards",Object.keys(this.state.groups),"item index")} <View style={{width: 280, height:54 , flexDirection:"row",alignItems:"center",backgroundColor: (this.state.itemIndex === index) ? "#74C947" : "#F6F6F6"}}> {/* Use ExcludeIcon.svg for stop symbol*/} {(this.state.itemIndex === index) ? <Image source={require("../../../assets/images/WhiteTick.svg")} style={{width:16,height:11,marginLeft:15,marginRight:9}}/> : <Image source={require("../../../assets/images/GreenTick.svg")} style={{width:16,height:11,marginLeft:15,marginRight:9}}/> } <Text style={{ fontStyle:"normal", fontWeight:"500", fontSize: 16, color: (this.state.itemIndex === index) ? "#FFFFFF" : "#333333", textTransform:"capitalize" }}> {item} </Text> </View> </TouchableOpacity> ) } keyExtractor={item => item} />

Antes de hacer clic

Después de hacer clic

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Prueba de esta manera

 state = { itemIndex: 0 }; componentDidMount(){ this.showDetails(this.state.itemIndex); }
about 4 years ago · Juan Pablo Isaza Report

0

Puede mantener el valor predeterminado de itemIndex en 0, lo que selecciona el primer elemento.

 constructor(props) { super(props); this.state = {itemIndex : 0}; }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!