Create a transparent circle on top of an Overlay in react-native
background, react-native
Solution
Solution 1:
You can use react-native-hole-view package to achieve this type of hole
import { RNHoleView } from 'react-native-hole-view';
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text style={{ flexGrow: 0, flex: 0, padding: 10 }}>{"Wow! I'm a text inside a hole!"}</Text>
<TouchableOpacity onPress={() => {}} style={{ backgroundColor: 'pink', padding: 10, borderRadius: 5 }}>
<Text>{"Wow! I'm a button inside a hole!"}</Text>
</TouchableOpacity>
<ScrollView style={{ flexGrow: 0, flex: 0, padding: 10 }} horizontal={true}>
<Text numberOfLines={1}>
{
"Wow! I'm a ScrollView inside a hole! Wow! I'm a ScrollView inside a hole! Wow! I'm a ScrollView inside a hole!"
}
</Text>
</ScrollView>
<RNHoleView
style={{ position: 'absolute', width: '100%', height: '100%', backgroundColor: 'rgba(34,146,231,0.4)' }}
holes={[{ x: 150, y: 390, width: 120, height: 120, borderRadius: 60 }]}>
</RNHoleView>
</View>
Solution 2:
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.
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;
Problem
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?