I have try many times, stills can not find the solution.
In a screen, I have so many components. I separated in header and content views components.
In content components, there has map component (image), and there has other components like a people component (image).
In the map component, I want to have a transparent overlay with full screen but it only overlay with map component. In react native, there are no z-index. How can I do it?
<View>
<View style={styles.header}>
.....
</View>
<View style={styles.content}>
<Image style={styles.map}>
<View style={styles.overlay}>
<Image style={styles.people} />
<Image style={styles.destination} />
</View>
</Image>
</View>
</View>
like this example which can not overlay the full screen: https://rnplay.org/apps/wHCi_A
To set Alpha of an image or view component in React Native based application, style's property opacity is used. Developers can make the shape or image background transparent according to his requirement in a fixed manner; in a fixed percentage, the view is made transparent by setting alpha.
'use strict'; var React = require('react-native'); var { AppRegistry, StyleSheet, Text, View, } = React; var SampleApp = React. createClass({ render: function() { return ( <View style={styles. container}> <View style={styles. avatar} /> <View style={styles.
zIndex is the Expo and React Native analog of CSS's z-index property which lets the developer control the order in which components are displayed over one another.
Move the overlay View to the view to the root View and make sure to add it as the last child. Set position to absolute. Something like this
const styles= StyleSheet.create({
overlay:{
position: 'absolute',
top: 0,
bottom: 0,
left: 0,
right: 0,
backgroundColor: 'rgba(0,0,0,0.2)'
});
<View>
<View style={styles.header}>
.....
</View>
<View style={styles.content}>
<Image style={styles.map}>
</Image>
</View>
<View style={styles.overlay}>
<Image style={styles.people} />
<Image style={styles.destination} />
</View>
</View>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With