13

The borderRadius style attribute doesn't change the border of a component correctly.

I would expect to see a green circle on the red background without any white space. Instead, I see this.

enter image description here

class Healthie extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.button} />
      </View>
    );
  }
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'red',
  },
  button: {
    backgroundColor: 'green',
    borderRadius: 50,
    width: 100,
    height: 100,
    textAlign: 'center'
  }
});

react-native version: 0.17.0.

2 Answers 2

23

no need to wrap button or text inside views, just put this on your style

overflow: hidden

it works for me

1
  • 2
    This works on ios, but not on android. At least as of RN 0.25. The correct answer is the accepted answer. Commented Jun 5, 2016 at 15:49
9

To get what you're looking for, you're going to have to wrap the Text box inside another View. The View will not default to another BG color when the borderRadius is changed:

<View style={styles.container}>
  <View style={styles.button}>
    <Text style={{ backgroundColor: 'transparent' }}>Text</Text>
  </View>
</View>

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'red',
  },
  button: {
    backgroundColor: 'green',
    borderRadius: 50,
    width: 100,
    height: 100,
    textAlign: 'center',
    flexDirection:'row', 
    alignItems:'center', 
    justifyContent:'center'
  }
});

Check out this demo.

1
  • 1
    It worked! Thanks! Even without {{ backgroundColor: 'transparent' }}. Commented Jan 12, 2016 at 19:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.