How to change the TouchableOpacity image on press - react-native

import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity, Image } from 'react-native';
import check from './assets/icons/covid.png'
import pill from './assets/icons/pill.png'
export default function App() {
return (
<View style={styles.container}>
<View style={styles.containerone}>
<TouchableOpacity style={{borderRadius: 100, height: 150, width: 150, backgroundColor: '#fff', marginTop: 80}}>
<Image source={pill} style={styles.pillButton}/>
<Image source={check} style={styles.checkButton}/>
</TouchableOpacity>
</View>
<View style={styles.containertwo}>
<Text style={{color:'#982fc2', fontWeight:'bold', fontSize:20}}>Text b</Text>
<Text style={{color:'#982fc2', fontWeight:'bold', fontSize:20}}>Text a</Text>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#982fc2'
},
containerone: {
flex: 1,
alignItems: 'center'
},
containertwo: {
flex: 1,
backgroundColor: '#fff',
borderTopRightRadius: 60,
borderTopLeftRadius: 60,
padding: 40
},
button: {
backgroundColor: '#fff',
borderRadius: 100,
height: 150,
width: 150,
marginTop: 100,
alignItems:'center',
justifyContent: 'center'
},
checkButton: {
height: 130,
width: 130,
display:'none'
},
pillButton: {
height: 130,
width: 130,
display: 'flex',
marginTop: 10
}
});
I have a simple question, how can I change the style of two buttons in press the first:
I created one style for each button, the first button is visible, and the second is hidden, so, I want to, when I press the first button, I change it style to display: 'none', and in the second, to display:'flex', can you guys help me?

Ciao, you colud use state to alternate Image visibility avoding to use css. Something like:
export default function App() {
const[alternateImage, setAlternateImage] = useState(true);
const changeImage = () => {
setAlternateImage(alternateImage => !alternateImage);
}
return (
<View style={styles.container}>
<View style={styles.containerone}>
<TouchableOpacity style={{borderRadius: 100, height: 150, width: 150, backgroundColor: '#fff', marginTop: 80}} onPress={changeImage}>
{alternateImage && <Image source={pill} style={styles.pillButton}/>}
{!alternateImage && <Image source={check} style={styles.checkButton}/>}
</TouchableOpacity>
</View>
<View style={styles.containertwo}>
<Text style={{color:'#982fc2', fontWeight:'bold', fontSize:20}}>Text b</Text>
<Text style={{color:'#982fc2', fontWeight:'bold', fontSize:20}}>Text a</Text>
</View>
</View>
);
}
and you could remove display: 'none' from Image css.

Related

react-native-awesome-gallery shows only one image without gesture possible

related to : https://github.com/Flair-Dev/react-native-awesome-gallery
I tried many things, but nothing is working.
I made the gesture and reanimation installation as wanted.
what I have :
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import Gallery from 'react-native-awesome-gallery';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
const ModalInfos = (props) => {
const [showMenu, setShowMenu] = useState(false)
return (
<View style={style.centeredView}>
<View style={style.modalView}>
<Text>{props.infos.name}</Text>
<Text> lots of infos here</Text>
....
....
....
<Text style={{ fontWeight: 'bold' }}> check menu </Text>
<TouchableOpacity
onPress={() => setShowMenu(true)}
>
<MaterialCommunityIcons name="book-open-variant" size={20} color={'#fff'} />
</TouchableOpacity>
</View>
{
showMenu &&
<View style={style.gallery}>
<GestureHandlerRootView style={{ flex: 1 }}>
<Gallery
data={["http://10.0.2.2:8080/images/menu/" + props.infos.barInfos.photomenu1, "http://10.0.2.2:8080/images/menu/" + props.infos.barInfos.photomenu2]}
onIndexChange={(newIndex) => {
console.log(newIndex);
}}
/>
</GestureHandlerRootView>
</View>
}
</View>
)
}
const style = StyleSheet.create({
centeredView: {
flex: 1,
justifyContent: "center",
alignItems: "center",
marginTop: 22,
},
modalView: {
width: '95%',
margin: 20,
backgroundColor: "white",
borderRadius: 20,
padding: 35,
alignItems: "center",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5
},
gallery: {
flex: 1,
width: "100%",
height: "100%",
position: 'absolute',
zIndex: 10,
backgroundColor: '#202124e6',
}
});
export default ModalInfos;
With or without the GestureHandlerRootViewits the same result, i can see only the first image, and I can't do anything, no swipe, no zoom, not gesture.
I switched to react-native-image-viewing
works more than perfectly

I am trying to implement text change and edit ends in TextInput using react-native but it's not quite working. Can any one help me?

I am trying to implement text change and edit ends in TextInput using react-native but it's not quite working.
See the Screenshot Here
Currently, when changing the price by touch input, the price is not affected when click off.
Here are my files
CartItem.js:
import React from "react";
import {
View,
TextInput,
Image,
TouchableOpacity,
StyleSheet,
Platform,
Alert,
} from "react-native";
//Colors
import Colors from "../../../utils/Colors";
//NumberFormat
import NumberFormat from "../../../components/UI/NumberFormat";
//Icon
import { MaterialCommunityIcons } from "#expo/vector-icons";
import CustomText from "../../../components/UI/CustomText";
//PropTypes check
import PropTypes from "prop-types";
export class CartItem extends React.PureComponent {
render() {
const { item, onAdd, onDes, onRemove } = this.props;
const AddItemHandler = async () => {
await onAdd();
};
const sum = +item.item.price * +item.quantity;
const checkDesQuantity = async () => {
if (item.quantity == 1) {
Alert.alert(
"Clear cart",
"Are you sure you want to remove the product from the cart?",
[
{
text: "Cancel",
},
{
text: "Yes",
onPress: onRemove,
},
]
);
} else {
await onDes();
}
};
return (
<View style={styles.container}>
<View style={styles.left}>
<Image
style={{
width: "100%",
height: 90,
resizeMode: "stretch",
borderRadius: 5,
}}
source={{ uri: item.item.thumb }}
/>
</View>
<View style={styles.right}>
<View
style={{ flexDirection: "row", justifyContent: "space-between" }}
>
<CustomText style={styles.title}>{item.item.filename}</CustomText>
<View>
<TouchableOpacity onPress={onRemove}>
<MaterialCommunityIcons name='close' size={20} color='#000' />
</TouchableOpacity>
</View>
</View>
<CustomText style={{ color: Colors.grey, fontSize: 12 }}>
Provided by Brinique Livestock LTD
</CustomText>
<NumberFormat price={sum.toString()} />
<View style={styles.box}>
<TouchableOpacity onPress={checkDesQuantity} style={styles.boxMin}>
<MaterialCommunityIcons name='minus' size={16} />
</TouchableOpacity>
Code that I would like to be fixed starts here.
<View>
<TextInput
keyboardType='numeric'
onEndEditing={AddItemHandler}
style={styles.boxText}>{item.quantity}</TextInput>
</View>
Code that I would like to be fixed ends here.
<TouchableOpacity
onPress={AddItemHandler}
style={styles.boxMin}>
<MaterialCommunityIcons name='plus' size={16} />
</TouchableOpacity>
</View>
</View>
</View>
);
}
}
CartItem.propTypes = {
item: PropTypes.object.isRequired,
onAdd: PropTypes.func.isRequired,
onRemove: PropTypes.func.isRequired,
onDes: PropTypes.func.isRequired,
};
const styles = StyleSheet.create({
container: {
flex: 1,
marginHorizontal: 10,
height: 110,
borderBottomWidth: 1,
borderBottomColor: Colors.light_grey,
flexDirection: "row",
paddingVertical: 10,
alignItems: "center",
backgroundColor: "#fff",
paddingHorizontal: 10,
borderRadius: 5,
marginTop: 5,
},
left: {
width: "35%",
height: "100%",
alignItems: "center",
},
right: {
width: "65%",
paddingLeft: 15,
height: 90,
// overflow: "hidden",
},
title: {
fontSize: 14,
},
box: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
height: Platform.OS === "ios" ? 30 : 25,
backgroundColor: Colors.grey,
width: 130,
borderRadius: 5,
paddingHorizontal: 15,
marginTop: 5,
},
boxMin: {
width: "30%",
alignItems: "center",
},
boxText: {
fontSize: 16,
backgroundColor: Colors.white,
padding: 5,
},
});
Use onBlur instead of onEndEditing.
How should the input end triggered?
After a time?
When user hits enter?
When user taps anywhere to close software keyboard?
Instead of
onEndEditing={AddItemHandler}
Use:
onBlur={(e) => {AddItemHandler(e.nativeEvent.text)}}
And ensure that AddItemHandler can handle the value in e.nativeEvent.text.

How can I get a popup and type in image link in there and make my image appear on the box below?

import React, {useState} from "react";
import {StyleSheet, Text, View, StatusBar, Dimensions, TextInput, Platform, ScrollView,TouchableOpacity, Button } from 'react-native';
import { AppLoading } from "expo";
import { createStackNavigator } from '#react-navigation/stack';
import { NavigationContainer } from '#react-navigation/native';
const { height, width } = Dimensions.get("window");
import Display from "./display";
import Modal from "react-native-modal";
const Stack = createStackNavigator();
function HomeScreen({ navigation }) {
return(
<View style={styles0.container}>
<StatusBar barStyle= "light-content" />
<Text style={styles0.title}>Junior Facebook</Text>
<View style={styles0.mainwhite}>
<View style={styles0.first}>
<TextInput
style={styles0.input1}
placeholder = "Enter your email"
/>
<TextInput
style={styles0.input1}
placeholder = "Enter your password"
/>
</View>
<View style={styles0.second}>
<TouchableOpacity
style={styles0.button}
onPress={()=>navigation.navigate("Newsfeed")}
>
<Text>SignUp</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text>Log In</Text>
</TouchableOpacity>
</View>
</View>
</View>
)
}
function Member({navigation}) {
return (
<View style={{alignItems: "center", backgroundColor: "lightgreen", flex: 1}}>
<Text>Junior Facebook</Text>
<TextInput placeholder="Email" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<TextInput placeholder="Password" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<TextInput placeholder="Confirm Password" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<TextInput placeholder="Name" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<TextInput placeholder="Gender" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<TextInput placeholder="Location" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<TextInput placeholder="Alma Mater" style={{width: 200, height: 60, borderStyle: "solid", borderWidth: 2}}/>
<Button style={{width: 100, height: 30}}title="Meeting"
onPress={()=>navigation.navigate("Meeting")}
>Meeting</Button>
</View>
);
}
export default class App extends React.Component{
render(){
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Member" component={Member} />
<Stack.Screen name="Newsfeed" component={Newsfeed} />
</Stack.Navigator>
</NavigationContainer>
)
}
}
const styles0 = StyleSheet.create({
container:{
flex:1,
backgroundColor : "#FFD6ED",
alignItems : "center"
},
title: {
color: "white",
marginTop : 100,
fontSize : 30,
fontWeight: "bold"
},
mainwhite:{
backgroundColor : "white",
width : width -65,
marginTop : 50,
borderRadius: 20
},
input1:{
borderStyle: "solid",
borderWidth: 2,
width: 300,
height: 50,
padding: 10,
marginVertical: 25,
},
input2:{},
first:{
marginVertical: 40,
alignItems : "center"
},
second: {
alignItems : "center",
marginVertical: 20,
},
button : {
marginBottom : 30
}
})
class Newsfeed extends React.Component{
render(){
return(
<View style={styles1.container}>
<StatusBar barStyle= "light-content" />
<View style={styles1.title}>
<Text style={styles1.title}>Junior Facebook</Text>
</View>
<View style={styles1.first}>
<TouchableOpacity style={styles1.profile}>
<Text>프로필</Text>
</TouchableOpacity>
<View style={styles1.allinput}>
<TouchableOpacity>
<TextInput
style={styles1.input}
placeholder = "글 입력"
/>
</TouchableOpacity>
<View style={styles1.button}>
<TouchableOpacity >
<Text style={styles1.picturebutton}>사진</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text style={styles1.pushbutton}>입력</Text>
</TouchableOpacity>
</View>
</View>
</View>
<View style={styles1.second}>
<ScrollView>
<Display/>
</ScrollView>
</View>
</View>
)
}
}
const styles1 = StyleSheet.create({
container:{
flex:1,
backgroundColor : "#FFD6ED",
alignItems:"center",
},
title: {
color: "white",
marginTop : 5,
fontSize : 18,
fontWeight: "bold",
marginBottom : 5,
alignItems:"center",
},
first :{
flex:1,
flexDirection : "row",
borderBottomWidth : StyleSheet.hairlineWidth,
marginLeft: 40
},
second:{
flex:3,
},
profile:{
backgroundColor : "white",
borderStyle: "solid",
borderWidth: 2,
width: 90,
height : 110,
marginTop : 3
},
allinput: {
flexDirection : "column",
alignItems:'flex-end',
borderBottomColor: "black",
padding : 3,
},
input:{
borderStyle: "solid",
borderWidth: 2,
width: 200,
height: 110,
padding: 10,
marginLeft : 5,
backgroundColor : "white",
},
button:{
flexDirection : "row"
},
picturebutton:{
fontSize: 24,
width: 60,
height:40,
borderStyle: "solid",
borderWidth: 1,
backgroundColor : "white",
marginVertical : 10,
marginHorizontal : 0
},
pushbutton:{
fontSize: 24,
width: 60,
height:40,
borderStyle: "solid",
borderWidth: 1,
marginLeft : 5,
backgroundColor : "white",
marginVertical : 10
}
})
and my Display component is as follows
import React from "react";
import {View, Text, TextInput, Button, StyleSheet, ScrollView, TouchableOpacity} from "react-native";
export default class Display extends React.Component{
render(){
const {text} = this.props;
return (
<View style={styles.pushtext}>
<Text>일단 한개</Text>
</View>
)
}
}
const styles = StyleSheet.create({
pushtext: {
backgroundColor : "white",
width: 300,
height: 50,
marginTop: 30
}
})
When I click the "Enter" TouchableOpacity, a popup should appear. And I should be able to type in an image link in the popup. And when I type in image link in there and click the "enter" text, an image from that link should appear below. How can I do so?
Please help me out here
Thank you so much!
According to your requirements, I made below sample
import React, { Component } from 'react';
import { View, StyleSheet, Button, Modal, TextInput, Image, } from 'react-native';
export default class App extends Component {
state = {
modalVisible: false,
link: '',
};
setModalVisible = () => {
this.setState({ modalVisible: !this.state.modalVisible });
};
onChangeText = text => {
this.setState({
link: text,
});
};
render() {
return (
<View style={styles.container}>
<Button title='Enter' onPress={this.setModalVisible} />
{
this.state.modalVisible &&
<Modal
visible={this.state.modalVisible}
transparent={true}
animationType="slide"
onRequestClose={this.setModalVisible}>
<View style={styles.modelStyle}>
<View style={styles.modelWrapperStyle}>
<TextInput
style={styles.inputStyle}
onChangeText={this.onChangeText}
value={this.state.link}
/>
<Button title='Enter' onPress={this.setModalVisible} />
</View>
</View>
</Modal>
}
{
!this.state.modalVisible && !!this.state.link &&
<Image
source={{ uri: this.state.link }}
style={{ width: 200, height: 200 }}
/>
}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
modelStyle: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
modelWrapperStyle: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-around',
backgroundColor: '#ffffff',
padding: 10,
width: '90%',
},
inputStyle: {
height: 40,
width: '80%',
borderColor: 'gray',
borderWidth: 1,
}
});
Hope this helps you. Feel free for doubts.

Calling an event when touching a ScrollView item

Is there a way to call an event when I press on an item inside this ScrollView?
let notes = this.state.noteArray.map((val, key)=>{
return <Note key={key} keyval={key} val={val}
deleteMethod={()=>this.deleteNote(key)}
editMethod={()=> this.editMethod(key, val)} />
});
<ScrollView style={styles.scrollContainer}> {notes} </ScrollView>
Note:
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
TouchableOpacity,
} from 'react-native';
export default class Note extends Component {
render() {
return (
{this.props.val.date}
{this.props.val.note}
<TouchableOpacity onPress={this.props.deleteMethod} style={styles.noteDelete}>
<Text style={styles.noteDeleteText}>Del</Text>
</TouchableOpacity>
<TouchableOpacity onPress={this.props.editMethod} style={styles.editNote}>
<Text style={styles.noteDeleteText}>Edit</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
note: {
position: 'relative',
padding: 20,
paddingRight: 100,
borderBottomWidth:2,
borderBottomColor: '#ededed'
},
noteText: {
paddingLeft: 20,
borderLeftWidth: 10,
borderLeftColor: '#0000FF'
},
noteDelete: {
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#2980b9',
padding: 10,
top: 10,
bottom: 10,
right: 10
},
editNote: {
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#2980b9',
padding: 10,
top: 10,
bottom: 10,
right: 70
},
noteDeleteText: {
color: 'white'
},
});
You need to add your all items under TouchableOpacity in which you like to get an event:
<TouchableOpacity
onPress={() => {
alert('Pressed')
}}>
// Keep your element which you like to tap
</TouchableOpacity>
You can refer the react-native doc for more reference.
You can use like this
let notes = this.state.noteArray.map((val, key)=>{
return <Note key={key} keyval={key} val={val}
deleteMethod={()=>this.deleteNote.bind(key)}
editMethod={()=> this.editMethod.bind(key, val)} />
});

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>