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

213
Views
Alternar botón de grupo Color React Native

Quiero cambiar el color de los botones en caso de onPress. Aquí, le doy al código lo que puedo cambiar para alternar el color. Por ejemplo, al hacer clic primero se vuelve rojo y otro blanco y viceversa.

 const Button = (props) => { let bgcolor = false; alert(props.id,'Hello'); return ( <> <TouchableOpacity onPress={() => { navigate(props.action); }} style={[styles.topleftcolor,{ flex: 1, backgroundColor: (props.id==1)?'red':'transparent', borderRadius: 0 }, (props.x === "left")?((props.y === "top")?styles.bordertopleft:styles.borderbottomleft):((props.y === "top")?styles.bordertopright:styles.borderbottomright)]}> <Icon name='hands' style={{ alignSelf: 'center', fontSize: 30, top: '50%' }} /> </TouchableOpacity> </> ); }

Hoja de estilo

 const styles = StyleSheet.create({ topleftcolor: { backgroundImage: 'linear-gradient(red, white)', }, bordertopright: { borderTopRightRadius: 200, }, bordertopleft: { borderTopLeftRadius: 200, }, borderbottomright: { paddingBottom: 30, paddingRight: 15, borderBottomRightRadius: 200, }, borderbottomleft: { paddingBottom: 30, paddingLeft: 15, borderBottomLeftRadius: 200, }, })

Composición de botones

 const HomePage = () => { <View style={{ flex: 1, flexDirection: 'row' }}> {/* { state.map( btn => <Button key={btn.id} btn={btn} x={btn.x} y={btn.y} color={btn.color} action={btn.action} /> ) } */} <Button id={1} x={'left'} y={'top'} color={'red'} action='Friends' ></Button> <Button id={2} x={'right'} y={'top'} color={'green'} action='Coins' ></Button> </View> <View style={{ flex: 1, flexDirection: 'row' }}> <Button id={3} x={'left'} y={'bottom'} color={'lightblue'} action='Photos' /> <Button id={4} x={'right'} y={'bottom'} color={'blue'} action='Badges' /> </View> };
about 4 years ago · Santiago Gelvez
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!