change to dynamic position CSS - css

I have created a box modal but in that all the width, height, position is given by static numbers. I tried giving dynamic(like using percentage) values so that it can adjust in any screen type. But not able to that.
Doing this for mobile app.
Doing this for mobile app.
Can someone please help me in this. Thanks in advance
Code:
import React from "react";
import { Button, Image, StyleSheet, Text, View } from "react-native";
function App() {
return (
<View style={styles.app}>
<View style={styles.box}>
<View style={styles.lcircle}></View>
<View style={styles.rcircle}></View>
<View style={styles.selectSquare}>SELECT</View>
</View>
</View>
);
}
const styles = StyleSheet.create({
app: {
marginHorizontal: "auto",
// maxWidth: 500,
paddingTop: 100
},
box: {
borderColor: "#B9EBC8",
height: 160,
width: 180,
borderWidth: 2
},
lcircle: {
height: 15,
width: 30,
borderWidth: 2,
// borderRadius: 30 30 0 0,
transform: [{ rotate: "90deg" }],
borderTopRightRadius: 40,
borderTopLeftRadius: 40,
borderRightColor: "#B9EBC8",
borderTopColor: "#B9EBC8",
borderLeftColor: "#B9EBC8",
borderBottomColor: "#FFFFFF",
backgroundColor: "#FFFFFF",
position: "absolute",
top: "50%",
left: -10
},
rcircle: {
height: 15,
width: 30,
borderWidth: 2,
// borderRadius: 30 30 0 0,
transform: [{ rotate: "-90deg" }],
borderTopRightRadius: 40,
borderTopLeftRadius: 40,
borderRightColor: "#B9EBC8",
borderTopColor: "#B9EBC8",
borderLeftColor: "#B9EBC8",
borderBottomColor: "#FFFFFF",
backgroundColor: "#FFFFFF",
position: "absolute",
top: "50%",
left: 155.5
},
selectSquare: {
height: 40,
width: 100,
borderWidth: 2,
borderColor: "#B9EBC8",
backgroundColor: "#FFFFFF",
position: "absolute",
left: 40,
top: 135,
display: "flex",
justifyContent: "center",
alignItems: "center",
color: "#008C00"
}
});
export default App;

Related

How can i increase height of my content view without messing with message button?

How can i make my view long? i want that the content view increases its height till the Message button
So how can i do that? you can see the image how its currenlty looking i tried to increase paddingVertical but than message button is also going down side and not even visible, i want that view make its height still the message button without messing with message button how to do that?
import { StyleSheet, Text, View, Image } from 'react-native'
import React from 'react'
import { formHead } from '../CommonCss/FormCss'
const GetUser = () => {
const data = [
{
username: 'hello',
image: 'img',
}
]
return (
<View style={styles.container}>
<View style={styles.content}>
<Image source={{ uri: data[0].image }} style={styles.userimg} />
<Text style={styles.namesty}>{data[0].username}</Text>
</View>
<Text style={styles.formbtn}>Message</Text>
<Text style={styles.formbtn2}>Message</Text>
</View>
)
}
export default GetUser
const styles = StyleSheet.create({
container: {
width: '100%',
height: '100%',
backgroundColor: 'black'
},
formbtn: {
width: '80%',
backgroundColor: 'white',
borderRadius: 10,
borderColor: 'white',
borderWidth: 1,
fontSize: 25,
color: 'black',
textAlign: 'center',
paddingVertical: 10,
marginVertical: 10,
fontWeight: "bold",
top: '50%',
marginLeft: 35
},
formbtn2: {
width: '80%',
backgroundColor: 'white',
borderRadius: 10,
borderColor: 'white',
borderWidth: 1,
fontSize: 25,
color: 'black',
textAlign: 'center',
paddingVertical: 10,
marginVertical: 10,
fontWeight: "bold",
top: '30%',
marginLeft: 35
},
namesty: {
color: 'white',
fontWeight: 'bold',
fontSize: 30,
margin: 10,
backgroundColor: '#111111',
paddingVertical: 10,
paddingHorizontal: 20,
borderRadius: 20,
},
userimg: {
width: 150,
height: 150,
borderRadius: 75,
},
content: {
backgroundColor: '#111111',
paddingVertical: 20,
paddingHorizontal: 20,
borderRadius: 20,
width: '100%',
alignItems: 'center',
}
})
I hope this will work for you, update this stylesheet:
const styles = StyleSheet.create({
container: {
width: '100%',
height: '100%',
backgroundColor: 'black'
},
formbtn: {
width: '80%',
backgroundColor: 'white',
borderRadius: 10,
fontSize: 25,
color: 'black',
textAlign: 'center',
height: 50,
paddingVertical: 10,
fontWeight: "bold",
// top: '50%',
position: 'absolute',
marginLeft: 35,
bottom: 15+50+15
},
formbtn2: {
width: '80%',
backgroundColor: 'white',
borderRadius: 10,
fontSize: 25,
color: 'black',
textAlign: 'center',
height: 50,
paddingVertical: 10,
fontWeight: "bold",
// top: '30%',
position: 'absolute',
marginLeft: 35,
bottom: 15
},
namesty: {
color: 'white',
fontWeight: 'bold',
fontSize: 30,
margin: 10,
backgroundColor: '#111111',
paddingVertical: 10,
paddingHorizontal: 20,
borderRadius: 20,
},
userimg: {
width: 150,
height: 150,
borderRadius: 75,
},
content: {
backgroundColor: '#444',
paddingVertical: 20,
paddingHorizontal: 20,
borderRadius: 20,
width: '100%',
alignItems: 'center',
height: height-50-50-15-15-15
}
})
In content and container style add flex:1
return (
<View style={styles.container}>
<View style={styles.content}>
<ScrollView>
<Image source={{ uri: data[0].image }} style={styles.userimg} />
<Text style={styles.namesty}>{data[0].username}</Text>
</ScrollView>
</View>
<View>
<Text style={styles.formbtn}>Message</Text>
<Text style={styles.formbtn2}>Message</Text>
</View>
</View>
)
content: {
flex:1,
backgroundColor: '#111111',
paddingVertical: 20,
paddingHorizontal: 20,
borderRadius: 20,
width: '100%',
alignItems: 'center',
}

Can you have a parent allow one absolutely positioned child to overflow and one to not overflow in React Native?

I have a parent element with 2 absolutely positioned children inside. I want one of the children's overflow to be visible and the other's overflow to be hidden. Like so:
Adding overflow: 'hidden to the parent hides the overflow of both the coin image and the 'most popular' sash but I want the coin image overflow to be visible.
container: {
width: 155,
height: 145,
backgroundColor: Colours.white,
borderRadius: 10,
borderColor: Colours.borderTwo,
borderWidth: 1,
alignItems: 'center',
justifyContent: 'flex-end',
margin: 10,
marginBottom: 25,
paddingBottom: 10,
overflow: 'hidden',
},
mostPopularSash: {
position: 'absolute',
top: 2,
right: -30,
backgroundColor: Colours.yellow,
width: 100,
height: 40,
alignItems: 'center',
justifyContent: 'center',
transform: [{rotate: '40deg'}],
},
imageContainer: {
position: 'absolute',
top: -22,
width: 52,
height: 52,
borderRadius: 100,
backgroundColor: Colours.white,
borderColor: Colours.pageColour,
borderWidth: 1,
justifyContent: 'center',
alignItems: 'center',
shadowColor: '#171717',
shadowOffset: {width: 0, height: 3},
shadowOpacity: 0.2,
shadowRadius: 2,
elevation: 5,
},
image: {
width: 40,
height: 40,
},
I've tried adding zIndex: 2 to the image container and then zIndex: 1 to the parents parent but it didn't work..
Can't find much online to solve this problem as most queries related to 'overflow' are requesting the opposite effect.
Any help would be much appreciated!
In iOS you can play with the zIndex
You can create a prop or a state that tells you which one is active.
For instance,
<View style={{zIndex:2}}>
{data.map(item => <CustomComp active={item.active} /> )}
</View>
In customcomp, you can set the parent style such as
style={{ props.active ? 3 : 1 }}
Make sure you have assign the zIndex to the container view
Manage to get the desired effect by wrapping the container that uses overflow: 'hidden' inside an outer container and then moving the imageContainer out of the container and into the outer container giving it zIndex: 1 and keeping it absolutely positioned as well as giving it alignSelf: 'center'
Like so:
outerContainer: {
width: '45%',
margin: 10,
},
container: {
height: 145,
width: '100%',
backgroundColor: Colours.white,
borderRadius: 10,
borderColor: Colours.borderTwo,
borderWidth: 1,
alignItems: 'center',
justifyContent: 'flex-end',
marginBottom: 25,
paddingBottom: 10,
overflow: 'hidden',
},
mostPopularSash: {
position: 'absolute',
top: 2,
right: -30,
backgroundColor: Colours.yellow,
width: 100,
height: 40,
alignItems: 'center',
justifyContent: 'center',
transform: [{rotate: '40deg'}],
},
imageContainer: {
zIndex: 1,
position: 'absolute',
top: -22,
alignSelf: 'center',
width: 52,
height: 52,
borderRadius: 100,
backgroundColor: Colours.white,
borderColor: Colours.pageColour,
borderWidth: 1,
justifyContent: 'center',
alignItems: 'center',
shadowColor: '#171717',
shadowOffset: {width: 0, height: 3},
shadowOpacity: 0.2,
shadowRadius: 2,
elevation: 5,
},
image: {
width: 40,
height: 40,
},
<View style={styles.outerContainer}>
<View style={styles.imageContainer}>
<Image source={image} style={styles.image} />
</View>
<View style={styles.container}>
{mostPopular && (
<View style={styles.mostPopularSash}>
<Text style={styles.mostPopularText}>Most</Text>
<Text style={styles.mostPopularText}>Popular</Text>
</View>
)}
<View style={styles.contentContainer}>
<View style={styles.textContainer}>
<Text style={styles.amountText}>£{amount}</Text>
<Text style={styles.bonusGemsText}>+{gemsBonus} NGems Bonus</Text>
</View>
<Button
text="Deposit"
backgroundColor={Colours.primary}
fontWeight="400"
fontColour={Colours.white}
fontSize={14}
style={{marginBottom: 0, height: 35, marginTop: 10}}
onPress={() => setModalVisible(true)}
/>
</View>
</View>
</View>
Credit to this answer: https://stackoverflow.com/a/67140055/13740590

Cross button react-native

I thought this would be simple to produce but I can't seem to get it looking right, I just want an X button - created 2 Views with 45deg rotation but for some reason they dont look equal length.
Header.js
<View style={styles.hamburgerContainer}>
<View style={[styles.hamburgerLine, styles.crossLine1]}></View>
<View style={[styles.hamburgerLine, styles.crossLine2]}></View>
</View>
const styles = StyleSheet.create({
hamburgerContainer: {
width: 40,
height: 40,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'transparent',
},
hamburgerLine: {
height: 3,
width: 30,
marginVertical: 3,
backgroundColor: Colors.primary,
},
crossLine1: {
marginVertical: 0,
transform: [{rotate: '45deg'}],
},
crossLine2: {
marginVertical: 0,
transform: [{rotate: '-45deg'}],
},
})
Result:
Appreciate any help here
Make the position absolute for the lines so they start on the same axis and can overlap:
hamburgerLine: {
height: 10,
width: 300,
marginVertical: 3,
backgroundColor: Colors.primary,
position: 'absolute' //add this
},

React Native translate text with percentage values not working

I have a react native project where I want to orientate a element verticaly and center the text.
Now I want to use percentages so it is centered width wise which would be the height of the parent element. Also the text should wrap it gets to big.
The problem is I can not use percentage because it get always converted to px inside the browser.
Can someone help me out?
I appreciate your help.
The text on the left side should always be centered like it is in this screenshot. It behaves so weird, if the width is changing the text moves around.
type TeamsProps = {
name: string,
}
const TeamCard = (props: TeamsProps) => {
const [showOptions, setShowOptions] = useState<Boolean>(false)
const toggleOptions = () => {
setShowOptions(!showOptions)
}
return (
<View style={[styles.container, { height: (Dimensions.get("window").width - 3 * 15) / 2 }]}>
<TouchableOpacity onLongPress={toggleOptions} style={styles.card}>
<View style={styles.nameFlag}>
<Text style={styles.name}>{props.name}</Text>
</View>
<View style={styles.member}>
</View>
</TouchableOpacity>
{ showOptions ?
<TouchableOpacity onPress={toggleOptions} style={styles.options}>
<TextInput style={styles.input} value="Team Name"></TextInput>
<View style={styles.buttons}>
<TouchableOpacity style={[styles.button, styles.delete]}>
<Delete style={{ fontSize: 20, color: "white", margin: "auto" }} />
</TouchableOpacity>
<TouchableOpacity style={[styles.button, styles.confirm]}>
<Check style={{ fontSize: 20, color: "white", margin: "auto" }} />
</TouchableOpacity>
</View>
</TouchableOpacity>
: <></>
}
</View>
)
}
const styles = StyleSheet.create({
container: {
flexBasis: "calc(50% - 7.5px)"
},
card: {
backgroundColor: constants.mainColor,
borderRadius: 15,
shadowOpacity: 0.6,
shadowRadius: 10,
flex: 1,
flexDirection: "row",
alignItems: "center"
},
nameFlag: {
backgroundColor: constants.mainColorLight,
height: "calc(100% - 30px)",
width: "15%",
marginVertical: 15,
borderTopRightRadius: 30,
borderBottomRightRadius: 30,
justifyContent: "center"
},
name: {
position: "absolute",
// TODO: translateX needs to use -50%, translateY needs to use 50% of parent width
transform: [{ rotate: "-90deg" }, { translateX: -33 }, { translateY: 13 }],
transformOrigin: "left",
width: "max-content",
fontFamily: constants.fontFamilyHeader,
fontSize: constants.fontSizeHeader
},
member: {
backgroundColor: constants.mainColorLight,
height: "calc(100% - 30px)",
width: "calc(85% - 30px)",
margin: 15,
borderRadius: 30,
padding: 15,
flex: 1,
flexDirection: "row",
flexWrap: "wrap",
gap: 15,
justifyContent: "space-around",
alignItems: "center"
},
options: {
backgroundColor: constants.shadowColor,
position: "absolute",
top: 0,
left: 0,
zIndex: 100,
width: "100%",
height: "100%",
borderRadius: 15,
padding: 15,
flex: 1,
justifyContent: "center",
alignItems: "center",
gap: 25
},
input: {
backgroundColor: "white",
width: "100%",
borderRadius: 50,
padding: 5,
fontFamily: constants.fontFamilySubheader,
fontSize: constants.fontSizeHeader,
textAlign: "center"
},
buttons: {
flexDirection: "row",
gap: 25
},
button: {
borderRadius: 50,
width: 40,
height: 40
},
delete: {
backgroundColor: constants.alertColor
},
confirm: {
backgroundColor: constants.accentColor
}
})
Return to post

How can we design Arrow card in react-native

I am developing one sample application, in this application need to require Arrow card it is used to offer's showing cards.
I tried react-native shapes based , but i didn't get the out put.
Suppose if offered text increased automatically the arrow design shape also incremented
Here this is my Code:
<View style={styles.container}>
<View style={{ flex: 0.1, backgroundColor: "blue" }} />
<View
style={{
flex: 0.9,
backgroundColor: "green",
justifyContent: "center",
alignItems: "center"
}}
>
<View style={styles.baseTop} />
<View style={styles.baseBottom} />
</View>
</View>
baseTop: {
borderBottomWidth: 35,
borderBottomColor: "red",
borderLeftWidth: 50,
borderLeftColor: "transparent",
borderRightWidth: 50,
borderRightColor: "transparent",
height: 0,
width: 0,
left: 0,
top: -35,
position: "absolute"
},
baseBottom: {
backgroundColor: "red",
height: 55,
width: 100
}
This I need like this type of image here this is referenced Image:
That is how I implemented nearly same like as your image.
import React, { Component } from 'react';
import { Text, View,StyleSheet } from "react-native";
export default class App extends Component {
render() {
return (
<View style={{flex:1}}>
<View
style={styles.wrapper}>
<View style={styles.rectangle}><Text>6</Text> <Text>tens</Text> </View>
<View style={styles.rectangle}><Text>6</Text> <Text>ones</Text> </View>>
<View style={styles.triangle}></View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
wrapper: {
flexDirection: "row",
justifyContent: "flex-start",
flex: 0.2,
alignItems: "center",
paddingLeft: 29,
paddingTop: 0,
marginTop: 0
},
rectangle: {
width: 50,
backgroundColor: "yellow",
margin: 0,
justifyContent: "center",
alignItems: "center",
height: 52,
borderColor:"black"
},
triangle: {
width: 0,
height: 0,
backgroundColor: 'transparent',
borderStyle: 'solid',
borderLeftWidth: 27,
borderRightWidth: 27,
borderBottomWidth: 43,
borderLeftColor: 'transparent',
borderRightColor: 'transparent',
borderBottomColor:"yellow",
transform: [
{ rotate: '90deg' }
],
margin: 0,
marginLeft: -6,
borderWidth: 0,
borderColor:"black"
}
});
Expo link https://snack.expo.io/rycpKiAe7
You could make a flex square, rotate it using Transform, and absolute position it to the proper place.
Or you can use react-native-svg and create an SVG, then position it accordingly.

Resources