I need to create the background view like this -
The background view with border must have up-arrow triangle.
This is my current code snippet -
<View style={{ width: '100%', paddingLeft: basePadding, paddingRight: basePadding }}>
<View style={{width: '100%', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-start', flex: 1}}>
<View style={{
marginTop: 10,
width: horizScale(30),
borderBottomWidth: StyleSheet.hairlineWidth,
borderColor: Colors.fire,
height: 1
}}/>
<View style={{
flex: 1,
marginTop: 10,
marginLeft: horizScale(20),
borderBottomWidth: StyleSheet.hairlineWidth,
borderColor: Colors.fire,
height: 1
}}/>
</View>
<View style={{width: '100%', borderLeftWidth: StyleSheet.hairlineWidth, borderRightWidth: StyleSheet.hairlineWidth, borderBottomWidth: StyleSheet.hairlineWidth, borderColor: Colors.fire, backgroundColor: '#FEF6F7', padding: horizScale(20)}}>
<Text style={{color: '#403F41'}}>
{' Test Test Test Test test'}
</Text>
<View style={{ flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'flex-start',
marginTop: horizScale(10),
width: '100%'}}>
<TouchableOpacity onPress={() => {
}}
style={{
backgroundColor: Colors.fire,
flex: 1,
alignItems: 'center',
justifyContent: 'center',
height: horizScale(40),
borderRadius: 3,
marginRight: horizScale(10)
}}>
<HeavyText style={{ fontSize: horizScale(14), color: '#FFF' }}>{'CANCEL'}</HeavyText>
</TouchableOpacity>
<TouchableOpacity onPress={() => {
}}
style={{
backgroundColor: primaryColor,
flex: 1,
alignItems: 'center',
marginLeft: horizScale(10),
justifyContent: 'center',
height: horizScale(40),
borderRadius: 3
}}>
<HeavyText style={{ fontSize: horizScale(14), color: '#FFF' }}>{'RE-BOOK'}</HeavyText>
</TouchableOpacity>
</View>
</View>
</View>
Add 2 triangle one for background color and one for border color
Complete code
import React, { Component } from "react";
import { View, StyleSheet } from "react-native";
export default class Dashboard extends Component {
render() {
return (
<View style={styles.box}>
<View style={styles.triangle} />
<View style={styles.triangle2} />
</View>
);
}
}
const styles = StyleSheet.create({
box: {
width: 300,
height: 100,
backgroundColor: "#fef6f7",
position: "relative",
margin: 50,
borderColor: "red",
borderWidth: 1
},
triangle: {
width: 10,
height: 10,
position: "absolute",
top: -10,
left: 20,
borderLeftWidth: 10,
borderLeftColor: "transparent",
borderRightWidth: 10,
borderRightColor: "transparent",
borderBottomWidth: 10,
borderBottomColor: "red"
},
triangle2: {
width: 10,
height: 10,
position: "absolute",
top: -10,
left: 21,
borderLeftWidth: 9,
borderLeftColor: "transparent",
borderRightWidth: 9,
borderRightColor: "transparent",
borderBottomWidth: 9,
borderBottomColor: "#fef6f7"
}
});
JSX:
<View style={styles.box}>
<View style={styles.triangle}>
</View>
Styling:
box:{
width:100,
height:100,
backgroundColor:"lightblue",
position:"relative"
},
triangle:{
width:10,
height:10,
position:"absolute",
top:-10,
left:20,
borderLeftWidth:10,
borderLeftColor:"transparent",
borderRightWidth:10,
borderRightColor:"transparent",
borderBottomWidth:10,
borderBottomColor:"red"
}
Here is the result:
You can change size of the triangle by playing with width and height. Also, if you want to change location, try playing with top and left properties of triangle.
Here are examples for top, right, bottom and left arrows in css. To convert to react native css, just change the properties to camel case. If you are using styled-components, you can use it as is.
Top Arrow:
.topArrow {
border-top-width: 0px;
border-top-color: transparent;
border-right-width: 80px;
border-right-color: transparent;
border-bottom-width: 160px;
border-bottom-color: green;
border-left-width: 80px;
border-left-color: transparent;
border-style: solid;
height: 0px;
width: 0px;
}
<div class="topArrow"></div>
Right Arrow:
.rightArrow {
border-top-width: 80px;
border-top-color: transparent;
border-right-width: 0px;
border-right-color: transparent;
border-bottom-width: 80px;
border-bottom-color: transparent;
border-left-width: 160px;
border-left-color: green;
border-style: solid;
height: 0px;
width: 0px;
}
<div class="rightArrow"></div>
Bottom Arrow:
.bottomArrow {
border-top-width: 160px;
border-top-color: green;
border-right-width: 80px;
border-right-color: transparent;
border-bottom-width: 0;
border-bottom-color: transparent;
border-left-width: 80px;
border-left-color: transparent;
border-style: solid;
height: 0px;
width: 0px;
}
<div class="bottomArrow"></div>
Left Arrow:
.leftArrow {
border-top-width: 80px;
border-top-color: transparent;
border-right-width: 160px;
border-right-color: green;
border-bottom-width: 80px;
border-bottom-color: transparent;
border-left-width: 0px;
border-left-color: transparent;
border-style: solid;
height: 0px;
width: 0px;
}
<div class="leftArrow"></div>
Related
I want to align all view and text parts like the above image. if the number may be big or small but the upper title should be in the middle of the value.
same alignment for the right side views also.
and the view and alignment should be responsive for every ios and android.
I have tried:
<ZekifutSchumView>
<ZekifutSchumText>סה”כ</ZekifutSchumText>
</ZekifutSchumView>
<HefreshimForLoTashlumView>
<HefreshimForLoTashlumText>
{props.hefreshimTotalForLoTashlum}
</HefreshimForLoTashlumText>
</HefreshimForLoTashlumView>
const ZekifutSchumText = styled(Text)``;
const ZekifutSchumView = styled(View)`
right: 2px;
`;
const HefreshimForLoTashlumView = styled(View)`
top: 15px;
${Platform.select({
ios: `
right: 30px;
`,
android: `
right: 26px;
`,
})};
border-right-width: 1px;
border-color: #ddd;
height: 18px;
`;
const HefreshimForLoTashlumText = styled(Text)`
${Platform.select({
ios: `
right: 20px;
`,
android: `
right: 21px;
`,
})};
`;
The same code is for the right side view also.
How can I align these view??
<View style={styles.app}>
<View style={{flexDirection: 'row', justifyContent: 'space-evenly'}}>
<View style={{alignItems: 'center'}}>
<Text>$</Text>
<Text>123,345,77</Text>
</View>
<View style={{
height: '50%',
width: 1,
backgroundColor: 'grey',
position: 'absolute',
bottom: 0}}/>
<View style={{alignItems: 'center'}}>
<Text>$</Text>
<Text>123,345,77</Text>
</View>
</View>
</View>
Note: pls do not use inline styles, just added them here for easy viewing
import React from "react";
import { StyleSheet,Text,Image,TextInput,TouchableOpacity, View, Dimensions } from 'react-native';
var width = Dimensions.get('window').width;
var height = Dimensions.get('window').height;
export default function login() {
return (
<View style={styles.container}>
<Image source={require('../components/assets/login/logo.jpg')} style={styles.logo} />
<TextInput style={styles.ButtonEmail} placeholder='Email' />
<TextInput style={styles.ButtonPassword} placeholder='Password'/>
<View style={styles.forgotContainer}>
<TouchableOpacity>
<Text style={styles.forgotText}>Esqueceu-se da senha?</Text>
</TouchableOpacity>
</View>
<TouchableOpacity style={styles.ButtonLogin}>
<Text style={styles.loginText}>Login</Text>
</TouchableOpacity>
<View style={styles.divisor}>
<View style={styles.divisorLine}></View>
<Text style={{marginHorizontal: '3%'}}>OU</Text>
<View style={styles.divisorLine}></View>
</View>
<TouchableOpacity style={styles.ButtonGoogle}>
<Text style={styles.GoogleText}>Login com a conta Google</Text>
</TouchableOpacity>
<Image source={require('../components/assets/login/google.jpg')} style={styles.logoGoogle} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
logo: {
width: 200,
height: 200,
position: 'relative',
top: height*0.17,
},
ButtonEmail: {
position: 'absolute',
top: height*0.35,
height: height*0.08,
width: width*0.85,
borderRadius: 50,
padding: 20,
backgroundColor: '#D6ECF3',
},
ButtonPassword: {
position: 'absolute',
top: height*0.45,
height: height*0.08,
width: width*0.85,
borderRadius: 50,
padding: 20,
backgroundColor: '#D6ECF3',
},
forgotContainer: {
position: 'absolute',
left: width*0.55,
top: height*0.55,
},
forgotText: {
color: '#399fff',
},
ButtonLogin: {
position: 'absolute',
top: height*0.63,
height: height*0.08,
width: width*0.425,
borderRadius: 50,
padding: 20,
backgroundColor: '#399fff',
},
loginText: {
textAlign: 'center',
color: 'white',
},
divisor: {
position: 'absolute',
top: height* 0.75,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
},
divisorLine: {
width: width*0.3,
height: height*0.005,
borderRadius: 5,
backgroundColor: '#EFEDED',
},
ButtonGoogle: {
position: 'absolute',
top: height*0.8,
height: height*0.08,
width: width*0.77,
borderRadius: 50,
padding: 20,
paddingRight: 50,
backgroundColor: '#399fff',
},
GoogleText: {
textAlign: 'center',
color: 'white',
},
logoGoogle: {
position: 'absolute',
top: height*0.82,
left: width* 0.72,
height: 30,
width: 28,
}
});
I have created a component VeiwImageScreen and i imported in App.js I want this picture in mid of the screen that the two div above it can clearly be seen I have given width 80% its working height do not
I want to decrease its height and align it in center I have given align-items center but due to height it not coming in middle here is my code
<View style={styles.Container}>
<View style={styles.closeIcon}></View>
<View style={styles.deleteIcon}></View>
<View></View>
<Image
style={styles.VeiwImage}
source={require("../assets/horror-background.jpg")}
/>
</View>
this is my styling I want this picture in mid of the screen I have given width 80% and height 80%
const styles = StyleSheet.create({
Container: {
justifyContent: "center",
alignItems: "center",
height: "100%",
width: "100%",
},
VeiwImage: {
flex: 1,
width: "80%",
height: 10,
},
closeIcon: {
width: 50,
height: 50,
backgroundColor: colors.red,
position: "absolute",
zIndex: 1,
top: 20,
left: 20,
},
deleteIcon: {
zIndex: 1,
width: 50,
height: 50,
backgroundColor: colors.black,
position: "absolute",
top: 20,
right: 20,
},
});
Remove flex:1 from VeiwImage and add it to container
const styles = StyleSheet.create({
Container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
height: "100%",
width: "100%",
},
VeiwImage: {
width: "80%",
height: 10,
},
closeIcon: {
width: 50,
height: 50,
backgroundColor: colors.red,
position: "absolute",
zIndex: 1,
top: 20,
left: 20,
},
deleteIcon: {
zIndex: 1,
width: 50,
height: 50,
backgroundColor: colors.black,
position: "absolute",
top: 20,
right: 20,
},
});
I want to put the string 'example' in the middle of the header.
Code:
<View style={viewStyle}>
<ImageButton
imageUrl={require('./assets/icons/Back-25.png')}
onPress={props.onPressPhone}
/>
<Text>{props.headerText}</Text>
</View>
viewStyle:
backgroundColor: 'white',
alignItems: 'center',
height: 60,
paddingTop: 15,
shadowColor: '#000000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.2,
elevation: 2,
position: 'relative',
flexDirection: 'row',
justifyContent: 'space-between',
Image Button style:
alignSelf: 'center',
One way to do this is to use a same-size empty .png image on the other side, and space-between in your header styling:
<View style={ styles.header }>
<Button style={{left: 10}} onPress={ () => this.handlePress() }>
<Image source={ require('../images/arrow_back.png') } style={{ width: 50, height: 50 }} />
</Button>
<Text style={styles.header_text} >{this.props.title}</Text>
<Button style={{right: 10}}>
<Image source={ require('../images/no_image.png') } style={{ width: 50, height: 50 }} />
</Button>
</View>
and
header: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
width: width,
backgroundColor: '#09146d',
},
...a bit kludgy, but it has worked for me. Alternatively, you could divide up the header with flex-based views, using flexDirection: 'row' :
<View style={ styles.header }>
<View style={{flex: 1}}>
//Button in here
</View>
<View style={{alignItems: 'center', flex: 6}}>
//Text in here
</View>
<View style={{flex: 1}}>
//Nothing in here
</View>
</View>
Good luck!
Expand on kwishnu's flex idea:
flex: 1; will always allocate only 1/3rd of the width to the title. So use flex: 1 1 auto; instead to allow the title to expand into all available space.
add min-width: fit-content; to the back button (so that the title will never cover the back button).
Add bonus styling in the case where the title is really, really long
span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<div class="header" style="display: flex;">
<span style="flex: 1; background: aqua; min-width: fit-content;">Back Button</span>
<span style="flex: 1 1 auto; text-align: center; background: beige;">Edit title to see behaviour whien title is very long</span>
<span style="flex: 1; background:red;"></span>
</div>
I want to make a button as the below.
Please help me.
Here are two ways to do it:
This one uses skewX:
<View style={{
width: 200,
height: 50,
borderWidth: 4,
borderColor: 'black',
// Uncomment this to see how it looks unclipped
overflow: 'hidden',
borderRadius: 10,
backgroundColor: 'white',
position: 'relative',
// These are to center the text
alignItems: 'center',
justifyContent: 'center',
}}>
<View style={{
width: 120,
height: 70,
position: 'absolute',
// These offsets were required because the transform
// would move them off the edges
right: -10,
top: -10,
backgroundColor: 'yellow',
borderLeftWidth: 5,
borderLeftColor: 'black',
transform: [{
skewX: '-45deg',
}]
}} />
<Text style={{
backgroundColor: 'transparent',
fontSize: 20,
}}>Hello World</Text>
</View>
And here's the other way using rotateX:
<View style={{
width: 200,
height: 50,
borderWidth: 4,
borderColor: 'black',
// Uncomment this to see how it looks unclipped
overflow: 'hidden',
borderRadius: 10,
backgroundColor: 'white',
position: 'relative',
// These are to center the text
alignItems: 'center',
justifyContent: 'center',
}}>
<View style={{
width: 100,
height: 150,
position: 'absolute',
// These offsets were required because the transform
// would move them off the edges
right: 10,
top: -30,
backgroundColor: 'yellow',
borderLeftWidth: 4,
borderLeftColor: 'black',
transform: [{
rotate: '45deg',
}]
}} />
<Text style={{
backgroundColor: 'transparent',
fontSize: 20,
}}>Hello World</Text>
</View>
I prefer the rotation method because the skew will mess with the border width of the diagonal line.