Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Border Radius with background color

In React Native, borderRadius is working but the background color given to the button stays a square. What is going on here?

JS

<TouchableHighlight   style={styles.submit}   onPress={() => this.submitSuggestion(this.props)}   underlayColor='#fff'>     <Text style={[this.getFontSize(),styles.submitText]}>Submit</Text> </TouchableHighlight> 

Style

... submit:{     marginRight:40,     marginLeft:40,     marginTop:10, }, submitText:{     paddingTop:20,     paddingBottom:20,     color:'#fff',     textAlign:'center',     backgroundColor:'#68a0cf',     borderRadius: 10,     borderWidth: 1,     borderColor: '#fff' }, ... 

enter image description here

like image 776
Chipe Avatar asked Jan 27 '16 07:01

Chipe


People also ask

How to set border radius of image in React Native?

We will set the border radius of the Image using StyleSheet element borderRadius. Step 1: First create the new reactive project. Step 2 : Create the "images" folder inside the react native project structure and refer the below screenshot. Step 4: Open App.js File in your favorite code editor and erase all code and follow this tutorial.

How to make corner rounded in React Native?

To make corner rounded, React Native provide below props and we are going to learn with example. React Native provide borderRadius prop to make all corners rounded and borderRadius prop only accept number between 1 to 100 or if you put more then 100 value it should same output of 100 value let understand with example.

What happens when you apply border radius to the same element?

When we apply border radius to the same element, the border gets thicker to accommodate for the increased radius. So far so good. Unfortunately if we then apply the opacity to the parent, the background color of the element gets semitransparent, making the border visible and creating an ugly effect.

How does elevation work with border radius?

The way elevation works is that it creates a border around the element that is then shifted to the bottom. The background color of the element then hides the inside part of the border. When we apply border radius to the same element, the border gets thicker to accommodate for the increased radius.


2 Answers

Try moving the button styling to the TouchableHighlight itself:

Styles:

submit: {   marginRight: 40,   marginLeft: 40,   marginTop: 10,   paddingTop: 20,   paddingBottom: 20,   backgroundColor: '#68a0cf',   borderRadius: 10,   borderWidth: 1,   borderColor: '#fff', }, submitText: {   color: '#fff',   textAlign: 'center', } 

Button (same):

<TouchableHighlight   style={styles.submit}   onPress={() => this.submitSuggestion(this.props)}   underlayColor='#fff'>     <Text style={[this.getFontSize(),styles.submitText]}>Submit</Text> </TouchableHighlight> 

enter image description here

like image 153
Nader Dabit Avatar answered Sep 18 '22 13:09

Nader Dabit


You should add overflow: hidden to your styles:

Js:

<Button style={styles.submit}>Submit</Button> 

Styles:

submit {    backgroundColor: '#68a0cf';    overflow: 'hidden'; } 
like image 22
Hossein Avatar answered Sep 20 '22 13:09

Hossein