Unable to create curved view in react-native - react-native

<View style={{
width: window.width,
height: window.width / 7,
backgroundColor: colors.white}}>
<View style={{
backgroundColor: colors.primary,
borderBottomLeftRadius: 80,
borderBottomRightRadius: 80,
height: window.width / 7,
width: window.width,
flex: 1,
}}>
<View style={{
backgroundColor: '#000',
height: window.width / 7,
width: window.width / 3,
borderRadius: 100,
alignSelf: 'center',
position: 'absolute',
bottom: 0,
overflow: 'hidden',
}}>
</View>
</View>

Check the below solution
import * as React from "react";
import { View, StyleSheet } from "react-native";
export default function Curve() {
return (
<View style={{ margin: 50 }}>
<View style={styles.squreStyle} />
<View style={styles.arcStyle} />
</View>
);
}
const styles = StyleSheet.create({
squreStyle: {
width: "100%",
height: 75,
borderRadius: 12,
backgroundColor: "black",
},
arcStyle: {
width: "20%",
height: 70,
position: "absolute",
bottom: -25,
left: "40%",
borderRadius: 35,
backgroundColor: "black",
transform: [{ scaleX: 5 }, { scaleY: 1 }],
},
});
Sample image of the working code
Edit - Modified according to the requirements of Scroll & Write content inside header.
import * as React from "react";
import { View, StyleSheet, Text, ScrollView } from "react-native";
export default function Curve() {
return (
<ScrollView>
<View style={{marginVertical: 50}}>
<View style={styles.squreStyle}>
<Text style={{ color: "white", textAlign: "center" }}>Sample Header</Text>
</View>
<View style={styles.arcStyle} />
</View>
<View style={{ height: 500, backgroundColor: "green" }} />
<View style={{ height: 500, backgroundColor: "yellow" }} />
</ScrollView>
);
}
const styles = StyleSheet.create({
squreStyle: {
width: "100%",
height: 75,
borderRadius: 12,
backgroundColor: "black",
zIndex: 1,
},
arcStyle: {
width: "20%",
height: 70,
position: "absolute",
bottom: -25,
left: "40%",
borderRadius: 35,
backgroundColor: "black",
transform: [{ scaleX: 5 }, { scaleY: 1 }],
},
});
Hope this helps you. Feel free for doubts.

The thing is react native doesnt let us add border radius to sides unless of same height and width so that it can be a circle. What i did is exactly created a circle and pushed it upwards with top so that it seems like this. You can control the curvature by fixing the height and width and make it dynamic so that in every screen it looks the same.
Please check code below and also the expo snack:
expo-snack
Code:
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
export default function App() {
return (
<View style={styles.container}>
<View style={styles.newD}></View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
newD:{
height:500,
width:500,
backgroundColor:'red',
marginLeft:-70,
borderRadius:500,
top:-280
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});
Hope it helps. feel free for doubts

You can use react-native-canvas for draw it
import {Dimensions} from 'react-native';
import Canvas from 'react-native-canvas';
const {width} = Dimensions.get('window');
...
drawArc = (canvas) => {
const height = 150;
const ctx = canvas.getContext('2d');
context.moveTo(0,height/2);
context.quadraticCurveTo(width/2, height, width, height/2);
};
...
<Canvas
ref={canvas => drawArc(canvas) />
...
Hope this helps to you.

Related

React Navigation (native): Overflow visible not working on custom header

I'm implementing a custom header for #react-navigation/native-stack. Using React Navigation v6.
One of the elements within the custom header has a native shadow on iOS added (via the style prop). The shadow is a tad bigger than the header and unfortunately, I can't get it to display beyond the boundaries of the header. Of course, I've tried using overflow: visible on basically every component in the tree, but no success. The shadow is clipped off:
Here's my custom header:
function CustomHeader(props: NativeStackHeaderProps) {
const { options, route, navigation } = props;
const insets = useSafeAreaInsets();
const headerHeight = Helpers.getHeaderHeight(insets);
return (
<View style={{
height: headerHeight,
paddingTop: insets.top,
width: '100%',
backgroundColor: Colors.white,
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingLeft: 20,
paddingRight: 20,
overflow: 'visible',
}}
>
<View style={{
flex: 1, display: 'flex', alignItems: 'flex-start',
}}
>
{ options.headerLeft ? options.headerLeft({ canGoBack: false }) : (
<TouchableOpacity
onPress={() => route.name === 'Home'
? null
: navigation.reset({ index: 0, routes: [{ name: 'Home' }] })}
>
<Image
style={{ width: Sizing.logo, height: Sizing.logo }}
source={Logo}
/>
</TouchableOpacity>
)}
</View>
<Text style={{
textAlign: 'center', color: Colors.purple,
}}
>
{(options.title || route.name).toUpperCase()}
</Text>
<View style={{
flex: 1, display: 'flex', alignItems: 'flex-end', overflow: 'visible',
}}
>
{ options.headerRight ? options.headerRight({ canGoBack: false }) : null}
</View>
</View>
);
}
The button on the right with the shadow is passed in through the headerRight option and contains this shadow style:
nativeShadow: {
shadowColor: Colors.gray,
shadowOffset: { width: 0, height: 8 },
shadowRadius: Colors.shadows.gray.distance,
shadowOpacity: 0.5,
},
Any idea what I could try next? I don't want to increase the headers' height since this would break the layout elsewhere.
I had a similar problem with the menu. I think i was taking another way and maybe you should try it.
Be sure that all the parent elements has at least the same height than the navmenu's height.
import React, { Component } from 'react';
import { TouchableOpacity, StyleSheet, Image, View, Text } from 'react-native';
const styles = StyleSheet.create({
menuParent: {
marginLeft: 30,
justifyContent: "flex-start",
alignItems: "flex-end",
flex: 1,
height: 250
},
btnContainer: {
width: 40,
height: 40,
elevation: 50,
zIndex: 50,
marginTop: 5
},
image: {
width: 40,
height: 40,
},
menuContainer: {
position: "absolute",
top: 5,
left: -5,
right: -5,
padding: 20,
borderRadius: 10,
elevation: 10,
zIndex: 10,
flex: 1,
height: 230,
backgroundColor: "#fff",
}
});
export default class DefaultHeaderMenu extends Component {
state = {
menuVisible: false
};
constructor(props) {
super(props);
}
render() {
return (
<View style={ styles.menuParent }>
{this.state.menuVisible ? <View style={ styles.menuContainer }></View> : null }
<TouchableOpacity
style={ styles.btnContainer }
onPress={ () => this.setState({ menuVisible: !this.state.menuVisible }) }
>
<Image
source={ require('#/assets/img/menu.png') }
style={ styles.image }
/>
</TouchableOpacity>
</View>
);
}
}
This is the component i used and the passed it to nav as headerRight element.
In my case, the problem was that height: 250 was missing in menuParent.
I hope it helps you and good luck
I had a problem like this once and fixed it by using 'zIndex'. Try setting it as the* max index in your project. Hope it helps

Elevation doesn't work properly react native

I am trying to give shadow to my custom card component but the shadow cuts down the view like this:
Here is my code
import React from 'react'
import { View, StyleSheet, Text, Image, Dimensions } from 'react-native'
const { width } = Dimensions.get('window')
export default function CardCus() {
return (
<View style={{
justifyContent: 'center', alignItems: 'center', padding: 10
}}>
<View style={styles.container}>
<View style={{ width: 110, borderTopLeftRadius: 10, borderBottomLeftRadius: 10, }}>
<Image style={{ width: '100%', height: '100%', borderTopLeftRadius: 10, borderBottomLeftRadius: 10 }} source={{ uri: 'https://images.pexels.com/photos/6231818/pexels-photo-6231818.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940' }} />
</View>
<View style={{ margin: 10, padding: 5 }}>
<Text style={styles.title}>Title</Text>
<Text>Separator</Text>
<Text>Title</Text>
<Text>Title</Text>
</View>
</View>
</View>
)
}
const styles = StyleSheet.create(
{
container: {
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.5,
shadowRadius: 2,
elevation: 2,
flexDirection: 'row',
borderRadius: 10,
borderColor: 'black',
borderWidth: 1,
height: 110,
width: width - 10,
},
title: {
fontWeight: 'bold'
}
}
)
I have tried many different style settings but none of them work. Is there a way to solve this issue? Thanks in advance.
So related to your question, it was hard to understand at first.
I just added the properties zIndex and backgroundColor to the container style and increased the value of the elevation and now it looks better. Also improved the readability.
See the comments in the improved code below:
import React from 'react';
import { View, StyleSheet, Text, Image, Dimensions } from 'react-native';
export default function CardCus() {
const imgUri =
'https://images.pexels.com/photos/6231818/pexels-photo-6231818.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940';
return (
<View style={styles.main}>
<View style={styles.container}>
<View style={styles.imageContainer}>
<Image style={styles.image} source={{ uri: imgUri }} />
</View>
<View style={styles.textContainer}>
<Text style={styles.title}>Title</Text>
<Text>Separator</Text>
<Text>Title</Text>
<Text>Title</Text>
</View>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.5,
shadowRadius: 2,
elevation: 10, // changed to a greater value
flexDirection: 'row',
borderRadius: 10,
borderColor: 'black',
borderWidth: 1,
height: 110,
width: Dimensions.get('window').width - 10,
zIndex: 99, // added zIndex
backgroundColor: 'white', // added a background color
},
title: {
fontWeight: 'bold',
},
imageContainer: {
width: 110,
borderTopLeftRadius: 10,
borderBottomLeftRadius: 10,
backgroundColor: 'white',
},
image: {
width: '100%',
height: '100%',
borderTopLeftRadius: 10,
borderBottomLeftRadius: 10,
},
textContainer: {
margin: 10,
padding: 5,
backgroundColor: 'white',
},
main: {
justifyContent: 'center',
alignItems: 'center',
padding: 10,
},
});
You can adjust the values to make the shadow darker. And this is how it looks:

React Native - Android position absolute buttons are untappable

I have a react native component that handles comunication between two peers using WebRTC.
Everything works perfectly on ios but on android the buttons are unclickable and i am pretty sure its because of the position:absolute, the buttons rendering somewhere behind a element and because of that they are untappable.
My question is ... what am i doing wrong? Why are they rendering but they are untappable on android?
The buttons are: End call positioned center bottom and switch camera positioned right bottom.
PS: I removed most of the component logic as it was irelevant to the question.
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { RTCView } from 'react-native-webrtc';
import WebSocketWrapper from '../components/generic/WebSocketWrapper/WebSocketWrapper';
import { Image, StyleSheet, View, Text, Platform, ActivityIndicator, Dimensions } from 'react-native';
import RNSecureStorage, { ACCESSIBLE } from 'rn-secure-storage';
import WebRtcPeer from 'react-native-kurento-utils';
import { COLORS } from '../styles/colors';
import { SafeAreaView } from 'react-navigation';
import axios from 'axios';
import Toast from 'react-native-root-toast';
import Icon from 'react-native-vector-icons/MaterialIcons';
import IconIonicons from 'react-native-vector-icons/Ionicons';
import { TouchableOpacity } from 'react-native-gesture-handler';
import logger from '#/logging.service';
import utils from '#/utils.service';
const BTN_CIRCLE_SIZE = 60;
const ICON_CIRCLE_SIZE = BTN_CIRCLE_SIZE / 2;
const styles = StyleSheet.create({
rtcViewsContainer: {},
remoteView: {
alignSelf: 'center',
top: 0,
right: 0,
bottom: 0,
left: 0,
backgroundColor: '#000000'
},
selfView: {
position: 'absolute',
alignSelf: 'flex-start',
width: 150,
height: 150,
left: 16,
bottom: 32,
borderWidth: 0.5
},
textContainer: {
flex: 1,
padding: 32,
width: '100%',
alignItems: 'center',
justifyContent: 'center'
},
introductionText: {
justifyContent: 'center',
alignItems: 'center',
fontSize: 13,
lineHeight: 22,
textAlign: 'center'
},
logo: {
alignSelf: 'center',
height: 70,
width: 150
},
logoContainer: {
height: 70,
position: 'absolute',
top: 0,
left: 0,
right: 0,
justifyContent: 'center',
alignItems: 'center'
},
endCallIconContainer: {
position: 'absolute',
zIndex: 100,
bottom: 32,
width: BTN_CIRCLE_SIZE,
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row'
},
endCallIconTouchable: {
width: BTN_CIRCLE_SIZE,
height: BTN_CIRCLE_SIZE,
borderRadius: BTN_CIRCLE_SIZE / 2,
alignSelf: 'center',
zIndex: 110,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'red'
},
switchCameraIconTouchable: {
width: BTN_CIRCLE_SIZE,
height: BTN_CIRCLE_SIZE,
borderRadius: BTN_CIRCLE_SIZE / 2,
alignSelf: 'flex-end',
zIndex: 110,
justifyContent: 'center',
alignItems: 'center'
},
switchCameraIcon: {
width: BTN_CIRCLE_SIZE,
height: BTN_CIRCLE_SIZE
},
endCallIcon: {
alignSelf: 'center'
}
});
export default class VideoCallIdentification extends Component {
static navigationOptions = {
header: null
};
displayRTCViews() {
return !!(this.state.remoteURL && this.state.videoURL);
}
getText() {
if (this.state.CALL_STATE === this.CALL_STATES.FINISHED_CALL) {
return 'Please wait ...';
} else if (this.state.REGISTERED_STATE === this.CALL_STATES.REGISTERED) {
return 'An agent will be with you soon. You will be prompted to give access to your microphone and camera in order for the video call to proceed!';
}
}
componentWillUnmount() {
this.stopCommunication();
}
getRemoveViewDimensions() {
return {
width: Dimensions.get('window').width,
height: Dimensions.get('window').height
};
}
onSocketError(e) {
logger.log('!!!!!!!!!!!!!!! Socket Erorr!', e);
utils.toast('An unexpected error has ocurred!');
this.stopWebRtc();
this.props.navigation.navigate('CompleteAccountPage');
}
getEndCallBarSize() {
return {
left: Dimensions.get('window').width / 2 - BTN_CIRCLE_SIZE / 2,
height: BTN_CIRCLE_SIZE
};
}
getSwitchCameraBarSize() {
return {
right: 32,
height: BTN_CIRCLE_SIZE
};
}
changeCamera() {
this.webRtcConnection.toggleCamera();
}
render() {
return (
<View
style={{ marginTop: 0, paddingLeft: 0, paddingRight: 0, marginBottom: 0, flex: 1, width: '100%', ...this.getRemoveViewDimensions() }}
containerStyle={{ flex: 1, width: '100%', ...this.getRemoveViewDimensions() }}
>
<SafeAreaView style={{ ...this.getRemoveViewDimensions(), position: 'absolute', top: 0, left: 0, right: 0, bottom: 0 }}>
{this.displayRTCViews() ? (
<View>
<View style={{ ...styles.rtcViewsContainer, ...this.getRemoveViewDimensions() }}>
<RTCView streamURL={this.state.remoteURL} style={{ ...styles.remoteView, ...this.getRemoveViewDimensions() }} />
<RTCView streamURL={this.state.videoURL} style={styles.selfView} />
</View>
<View style={{ ...styles.endCallIconContainer, ...this.getEndCallBarSize() }}>
<TouchableOpacity style={styles.endCallIconTouchable} onPress={() => this.stopCommunication(true).bind(this)}>
<Icon style={styles.endCallIcon} size={ICON_CIRCLE_SIZE} name="call-end" color="#ffffff" />
</TouchableOpacity>
</View>
<View style={{ ...styles.endCallIconContainer, ...this.getSwitchCameraBarSize() }}>
<TouchableOpacity style={styles.switchCameraIconTouchable} onPress={() => this.changeCamera(true)}>
<IconIonicons style={styles.endCallIcon} size={BTN_CIRCLE_SIZE} name="ios-reverse-camera" color="#ffffff" />
</TouchableOpacity>
</View>
</View>
) : (
<View style={styles.textContainer}>
<View style={styles.logoContainer}>
<Image source={require('../assets/images/logoAndNameColored.png')} style={styles.logo} resizeMode="contain" />
</View>
<Text style={styles.introductionText}>{this.getText()}</Text>
<ActivityIndicator style={{ marginTop: 22 }} size="large" color={COLORS.APP_PURPLE} />
</View>
)}
<WebSocketWrapper
ref={ref => {
if (!this.state.socket) {
this.setState({ socket: ref });
}
}}
onError={this.onSocketError.bind(this)}
onOpen={this.onSocketOpen.bind(this)}
url={this.state.socketUrl}
onMessage={this.onmessage.bind(this)}
/>
</SafeAreaView>
</View>
);
}
}
VideoCallIdentification.propTypes = {
navigation: PropTypes.object
};

Can I the View of images be display in React-Native?

I have just stared react-native.
I got a strange situation.
In simulator's iOS, it's well. (like below)
But, In device's Android, it's not.
I set the margin to minus but it's cut in Android.
And images are just all black.
Entire code.
import React from 'react';
import {
ActivityIndicator,
Platform,
StyleSheet,
Text,
TouchableOpacity,
View,
Dimensions
} from 'react-native';
import Image from 'react-native-scalable-image';
import resolveAssetSource from 'resolveAssetSource';
// import FastImage from 'react-native-fast-image'
import {scale, moderateScale, verticalScale} from '../utils/scaling';
export default class MeuScreen extends React.Component {
static navigationOptions = {
header: null,
title: null
};
render() {
let meuBg = require('../assets/images/meu_home_bg.jpg');
let meuBgSource = resolveAssetSource(meuBg);
const bgImg = <Image width={Dimensions.get('window').width} source={meuBg} style={styles.topBg}/>;
return (
<View style={styles.container}>
{bgImg}
<View style={styles.boxWrap}>
<View style={styles.roundBox}>
<View style={styles.guys}>
<Image resizeMode="cover" style={styles.me} width={60} height={60}
source={{uri: 'https://static.pexels.com/photos/213117/pexels-photo-213117.jpeg'}}/>
<Image resizeMode="cover" style={styles.you} width={60} height={60}
source={{uri: 'https://static.pexels.com/photos/213117/pexels-photo-213117.jpeg'}}/>
</View>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'rgba(239, 244, 255, 0.36)',
position: 'relative',
alignItems: 'center'
},
topBg: {
position: 'absolute', top: 0,
zIndex: 1
},
roundBox: {
width: Dimensions.get('window').width - 60,
minHeight: 300,
borderWidth: 1,
borderColor: '#e5e5e5',
borderRadius: 30,
backgroundColor: '#fff',
marginTop: verticalScale(165),
zIndex: 2
},
guys: {
flex: 1,
marginTop: verticalScale(-25),
flexDirection: 'row',
zIndex: 3
},
me: {
borderWidth: 4,
borderColor: '#fff',
borderRadius: 30,
position: 'absolute',
top: 0, left: scale(46)
},
you: {
borderWidth: 4,
borderColor: '#fff',
borderRadius: 30,
position: 'absolute',
top: 0, right: scale(46)
},
category: {},
location: {},
dates: {}
});
First, I had to think like the web. (position and z-index)
But RN is not supported 'z-index'.
How do I work?
Please help..
please specify Image width and height, inside an Image style.
<Image resizeMode="cover" style={[styles.me,{width:60,height:60}]} source={{uri: 'https://static.pexels.com/photos/213117/pexels-photo-213117.jpeg'}}/>

In React Native, how do I put a view on top of another view, with part of it lying outside the bounds of the view behind?

I'm trying to make a layout as per below with React Native.
How do I specify the position of B relative to A?
With iOS Interface Builder and autoconstraints, this can very explicitly be done and is a breeze. It's not so obvious how one might achieve this with React Native.
Add the following style to the "floating" view:
position: 'absolute'
You may also need to add a top and left value for positioning.
The above solutions were not working for me. I solved it by creating a View with the same background colour as the parent and added negative margin to move the image upwards.
<ScrollView style={{ backgroundColor: 'blue' }}>
<View
style={{
width: '95%',
paddingLeft: '5%',
marginTop: 80,
height: 800,
}}>
<View style={{ backgroundColor: 'white' }}>
<Thumbnail square large source={{uri: uri}} style={{ marginTop: -30 }}/>
<Text>Some Text</Text>
</View>
</View>
</ScrollView>
and I got the following result.
You can use zIndex for placing a view on top of another. It works like the CSS z-index property - components with a larger zIndex will render on top.
You can refer: Layout Props
Snippet:
<ScrollView>
<StatusBar backgroundColor="black" barStyle="light-content" />
<Image style={styles.headerImage} source={{ uri: "http://www.artwallpaperhi.com/thumbnails/detail/20140814/cityscapes%20buildings%20hong%20kong_www.artwallpaperhi.com_18.jpg" }}>
<View style={styles.back}>
<TouchableOpacity>
<Icons name="arrow-back" size={25} color="#ffffff" />
</TouchableOpacity>
</View>
<Image style={styles.subHeaderImage} borderRadius={55} source={{ uri: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/14/Albert_Einstein_1947.jpg/220px-Albert_Einstein_1947.jpg" }} />
</Image>
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "white"
},
headerImage: {
height: height(150),
width: deviceWidth
},
subHeaderImage: {
height: 110,
width: 110,
marginTop: height(35),
marginLeft: width(25),
borderColor: "white",
borderWidth: 2,
zIndex: 5
},
You can use this OverlayContainer. The trick is to use absolute with 100% size. Check below an example:
// #flow
import React from 'react'
import { View, StyleSheet } from 'react-native'
type Props = {
behind: React.Component,
front: React.Component,
under: React.Component
}
// Show something on top of other
export default class OverlayContainer extends React.Component<Props> {
render() {
const { behind, front, under } = this.props
return (
<View style={styles.container}>
<View style={styles.center}>
<View style={styles.behind}>
{behind}
</View>
{front}
</View>
{under}
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
height: '100%',
justifyContent: 'center',
},
center: {
width: '100%',
height: '100%',
alignItems: 'center',
justifyContent: 'center',
},
behind: {
alignItems: 'center',
justifyContent: 'center',
position: 'absolute',
left: 0,
top: 0,
width: '100%',
height: '100%'
}
})
import React, {Component} from 'react';
import {StyleSheet, View} from 'react-native';
export default class App extends Component {
render() {
return (
<View>// you need to wrap the two Views an another View
<View style={styles.box1}></View>
<View style={styles.box2}></View>
</View>
);
}
}
const styles = StyleSheet.create({
box1:{
height:100,
width:100,
backgroundColor:'red'
},
box2:{
height:100,
width:100,
backgroundColor:'green',
position: 'absolute',
top:10,
left:30
},
});
You can use react-native-view-overflow plugin for placing a view on top of another. It works like the CSS z-index property.
import ViewOverflow from 'react-native-view-overflow';
<ViewOverflow />
<View style={[styles2.cardBox, { marginTop: 50 }]}>
<View style={[styles2.cardItem]} >
<Text style={styles2.cardHeader}>userList</Text>
</View>
<View style={[styles2.cardContent]}>
<Text style={styles2.text}>overflow: "visible"</Text>
</View>
<View style={[styles2.cardItemFooter]} >
<Text style={styles2.cardTextFooter}>...</Text>
</View>
</View>
</ViewOverflow>
const styles2 = StyleSheet.create({
cardBox: {
borderLeftWidth: 0,
borderTopWidth: 0,
backgroundColor: "transparent",
borderWidth: 1,
borderColor: "#d0d0d0",
width: '94%',
alignSelf: 'center',
height: 200,
position: "relative",
borderRadius: 15,
overflow: "visible" // doesn't do anything
},
cardContent: {
textAlign: "right",
backgroundColor: "transparent",
marginTop: 15,
alignSelf: 'flex-end',
padding: 5,
},
cardHeader: {
color: '#fff',
fontFamily: 'Vazir',
fontSize: 12
},
cardItem: {
backgroundColor: "#3c4252",
borderRadius: 3,
position: "absolute",
top: -10,
right: -5,
width: 50,
height: 20,
paddingRight: 5,
},
})
The easiest way to achieve this is with a negative margin.
const deviceWidth = RN.Dimensions.get('window').width
a: {
alignItems: 'center',
backgroundColor: 'blue',
width: deviceWidth,
},
b: {
marginTop: -16,
marginStart: 20,
},
You can use elevation property for Android if you don't mind the shadow.
{
elevation:1
}
Try this:
style = {{position: 'absolute', bottom: 20, left: 20, elevation: 100}}
Based on the example above i've created a component which stacks all childeren on top of each other. You could even nest OverlayContainers inside OverlayContainers.
Usage:
<OverlayContainer>
<View style={{backgroundColor:'red', width:150, height: 150}}></View>
<View style={{backgroundColor:'yellow', width:50, height: 50}}></View>
<Text>Just some text</Text>
</OverlayContainer>
Output:
import React, { FC, PropsWithChildren } from 'react'
import { StyleSheet, View } from 'react-native'
export const OverlayContainer: FC<PropsWithChildren<unknown>> = (props) => {
return (
<View style={styles.container}>
{props.children.map((child, index) => (
<View style={styles.child} key={index}>
{child}
</View>
))}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
height: '100%',
},
child: {
position: 'absolute',
left: 0,
top: 0,
width: '100%',
height: '100%'
}
})
<SafeAreaView style={{ flex: 1 }} >
<View style={{ height: Dimensions.get('window').height / 2, backgroundColor: 'blue', justifyContent: 'center' }}>
<Text style={{ fontSize: 25, alignSelf: 'center' }} >A</Text>
<View style={{ justifyContent: 'center', height: 100, width: 100, backgroundColor: 'yellow', position: 'absolute', left: 20, top: Dimensions.get('window').height / 2 - 70 }}>
<Text style={{ fontSize: 22, alignSelf: 'center' }} >B</Text>
</View>
</View>
</SafeAreaView>