Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a transparent circle on top of an Overlay in react-native

enter image description here

Source: https://github.com/amlcurran/ShowcaseView By checking source code, it has some png.

Setting a backgroundColor rgba(0, 0, 0, 0.8) and creating a circle view on top of this simply doesn't work.

How do I create an Overlay like this in react-native?

like image 730
dragfire Avatar asked Oct 24 '16 14:10

dragfire


People also ask

How do you make a transparent view in React Native?

Use rgba value for the backgroundColor . This sets it to a grey color with 80% opacity, which is derived from the opacity decimal, 0.8 . This value can be anything from 0.0 to 1.0 .

How do you make a circle in React Native?

To create CSS circles in React Native, we can set the borderRadius style to '50%' . to set the width and height of the View . Then we set borderRadius to '50%' to make it a circle.

How do you add color to opacity in React Native?

Specify Opacity of a Color in React If you want to specify the opacity of background color, you should use the rgba() , which is slightly different from rgb() function. The decimal value can be anything from 0 to 1 . In this case, our background will be 30% colored and 70% transparent .


1 Answers

yes can use react-native-svg for this purpose.

you can get your solution from my code. i hope this will 100% work for you.

enter image description here

import { Svg, Defs, Rect, Mask, Circle } from 'react-native-svg';
const WrappedSvg = () => (
    <View style={{ aspectRatio: 1 }}>
        <Svg height="100%" width="100%" viewBox="0 0 100 100">
            <Defs>
                <Mask id="mask" x="0" y="0" height="100%" width="100%">
                    <Rect height="100%" width="100%" fill="#fff" />
                    <Circle r="45" cx="50" cy="50" />
                </Mask>
            </Defs>
            <Rect height="100%" width="100%" fill="rgba(0, 0, 0, 0.5)" mask="url(#mask)" fill-opacity="0" />
        </Svg>
    </View>
);

export class index extends Component {
    render() {
        return (
            <View style={{ backgroundColor: '#FFFFFF', flex: 1, justifyContent: 'center', alignItems: 'center' }}>

                <View style={{ width: Dimensions.get('window').width, height: 300, position: 'absolute' }}>
                    <WrappedSvg />
                </View>
            </View>
        );
    }
}

export default index;
like image 115
Muhammad Numan Avatar answered Oct 10 '22 21:10

Muhammad Numan