Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating CSS circles in react-native

Tags:

react-native

I'm having some trouble creating CSS circles in react-native. The following works in iPhone 6 Plus but in all the other iPhones, they become diamonds.

circle: {   height: 30,   width: 30,   borderRadius: 30, } 

Now if I use PixelRatio on borderRadius it works in everything but iPhone 6 plus. iPhone 6 plus renders it as boxes with rounded corners.

circle: {   height: 30,   width: 30,   borderRadius: 30 / PixelRatio.get(), } 
like image 542
cgarvis Avatar asked May 22 '15 19:05

cgarvis


People also ask

How do you make a perfect circle in React Native?

I've been using the styled-components package to style my React Native components and the easiest solution I've found is to set the border radius to a size in px larger than half of the width that the circle will ever have. It'll then default to the equivalent of a 50% border-radius for any size smaller than that.

How do I make a circular Image in React Native?

To add a rounded image with a border with React Native, we can set the borderRadius and overflow styles. to set borderRadius to '50%' to make the Image round. And we set the width and height of the Image to set the dimensions. We set overflow to 'hidden' so the Image stays in the circle.

Can you create a circle using CSS?

To create a circle we can set the border-radius on the element. This will create curved corners on the element. If we set it to 50% it will create a circle. If you set a different width and height we will get an oval instead.

How do you make a circle react?

Just add border-radius to create a circle.


1 Answers

Your border radius should be a half of width and your height. like below:

circle: {    width: 44,    height: 44,    borderRadius: 44/2 } 
like image 155
jsina Avatar answered Sep 23 '22 05:09

jsina