Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
Toggle group button's Color React Native

I want to change the color of buttons on event of onPress. Here, I give the code what I can change in it to toggle the color. Such as, I click on first it turns red and other white and vice versa.

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>
    </>
  );
}

Style Sheet

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,
  },
})

Button comp

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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda