Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add borderRadius to ImageBackground?

Tags:

react-native

The React Native ImageBackground component is supposed to accept the same prop signature as Image. However, it doesn't seem to accept borderRadius.

This has no affect.

<ImageBackground   style={{height: 100, width: 100, borderRadius: 6}}   source={{ uri: 'www.imageislocatedhere.com }} > 

How do you change the border radius of an ImageBackground?

like image 916
GollyJer Avatar asked Mar 23 '18 04:03

GollyJer


People also ask

How do you set border radius in react native?

Border Radius in React Native The borderRadius property can be set as the style attribute to any element. It takes a value in pixels and assigns that value to the overall border radius of that UI element. By default, the border radius of any element is 0 if you haven't added that style attribute to that element.

How do I change the opacity of the background image in react native?

create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'white', }, image: { height: 250, width: 250, opacity: 0.5, }, }); export default Home; The output will be as given in the screenshot below. That's how you increase or reduce transparency of image in react native.


1 Answers

This took some digging so posting Q&A for others to find.

ImageBackground is basically a <View> wrapping an <Image>.
The style prop only passes height and width to the <Image>.

To pass other style props use imageStyle.

<ImageBackground   style={{height: 100, width: 100}}   imageStyle={{ borderRadius: 6}}   source={{ uri: 'www.imageislocatedhere.com }} > 

The details are documented in the source code.

like image 102
GollyJer Avatar answered Sep 20 '22 06:09

GollyJer