Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Overlay Transparent

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

like image 828
kenny Avatar asked Jun 14 '16 17:06

kenny


People also ask

How do you make a transparent view in React Native?

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.

How do you overlap images in React Native?

'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.

What is zIndex in React Native?

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.


1 Answers

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>
like image 170
agenthunt Avatar answered Nov 09 '22 15:11

agenthunt