Place View on top of other View in React Native
Ok so I found the problem xD
Apparently the elevation={3}
messes it up. Everything works if I simply remove this prop from the row Views.
how to set view on top of another view (having just borders) in react native
Hre is a sample example. First you need to have a container
with a position: relative
. Then you could position the inner divs with positions absolute
and with a z-index
.
.container {
width: 200px;
height: 200px;
border: 1px solid red;
position: relative;
}
.viewA {
position: absolute;
bottom: 0;
left: 0;
width: 50%;
height: 50%;
z-index: 2;
background: yellow;
opacity: 0.5;
}
.viewB{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: green;
z-index: 1;
}
<div class="container">
<div class="viewA">View B</div>
<div class="viewB">View A</div>
</div>
react native view over a view in top left corner?
You can try this for all screens
import React from 'react';
import {
View,
Text,
TouchableOpacity,
ImageBackground,
StyleSheet,
SafeAreaView,
} from 'react-native';
const width = 200;
const height = width / 5;
const top = width / Math.sqrt(8) - height;
const left = -(width / Math.sqrt(8) - height / 2);
export default function Login() {
return (
<SafeAreaView style={styles.container}>
<ImageBackground
source={{
uri: 'https://i.picsum.photos/id/828/200/300.jpg?hmac=YwDXceJcHQbinJfsIHJgrD8NakhtHzBMH-vD4aNcPo4',
}}
style={styles.poster}>
<TouchableOpacity style={styles.premiumWrapper}>
<Text style={styles.premiumText}>Premium</Text>
</TouchableOpacity>
</ImageBackground>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
poster: {
height: '100%',
width: '100%',
backgroundColor: 'magenta',
},
premiumWrapper: {
height: height,
width,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#ffa604',
transform: [{rotate: '-45deg'}],
top,
left,
},
premiumText: {
color: 'white',
fontWeight: 'bold',
fontSize: 20,
},
});
React Native How can I put one view in front of the other
You can do it using zIndex for example:
<View id="top" style={{width: 100, height: 100, zIndex:2, backgroundColor: 'white'}} />
<View id="bottom" style={{width: 100, height: 100, zIndex:1, backgroundColor: 'black'}} />
By running this the white View with id="top" will be in the front. Now you can use this zIndex style property in your code.
React Native: component on top of another component
Add position styles to the react-native-google-places-autocomplete
style property:
styles={{
container:{
position: 'absolute',
top: 0
},
description: {
fontWeight: 'bold',
},
.....
Related Topics
How to Add Shimmer Effect in CSS
How to Position Element in The Correct 3D Position with CSS Perspective
Vuejs-Datepicker Change Styles Doesn't Work
Command-Line Argument as Var in Sass, for Hardcoded Cdn Url's on Compile
How to Use Nth-Child Correctly
Anyone Know What The Purpose of Tagging a Class with *[Class]
Only First Media Query Working
What Is Wrong with My CSS? Active Links Not Changing Color
CSS Attribute Selector Class Starts with But Not Equals To
PHPstorm Less Watcher Configuration
Exclude Menu Item from Collapsing Bootsrap
How to Animate an Ellipsis with CSS Animations
Modify Alpha Opacity of Less Variable
Twitter Bootstrap 3 Modal with Scrollable Body