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

212
Views
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
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!