How to center this container on React Native - css

How can I center this container
I would like to center de performContainer style
Center like the width
Will it be that only with marginLeft or have some flexbox properties to Do this?
Can you give me positioning tips on react native too?
Code Bellow:
return (
<View style={styles.container}>
<View style={styles.welcomeContainer}>
<View style={styles.photo} />
<Text style={styles.welcome}>Bem vindo(a), Carlos</Text>
</View>
<View style={styles.location}>
<MaterialIcons
style={styles.locationIcon}
name="location-on"
size={26}
color="#707070"
/>
<Text style={styles.locationText}>São Paulo</Text>
<View style={styles.active}>
<MaterialIcons
style={styles.doneIcon}
name="done"
size={22}
color="#707070"
/>
<Text style={styles.activeText}>Ativo</Text>
</View>
</View>
<View style={styles.performContainer}>
<Text style={styles.performTitle}>Desempenho hoje</Text>
<View
style={{
borderBottomColor: '#8CC63F',
borderBottomWidth: 1,
}}
/>
<Text style={styles.earnText}>
Voce ganhou: <Text style={styles.value}>R$ 85,20</Text>
</Text>
<View style={styles.ordersAceptedContainer}>
<MaterialIcons
style={styles.iconDelivery}
name="check-circle"
color="#707070"
size={26}
/>
<Text style={styles.ordersAcepted}>
Pedidos entregues: <Text style={styles.value}>0</Text>
</Text>
</View>
<View style={styles.ordersRejectedContainer}>
<MaterialIcons
style={styles.iconDeliveryRejected}
name="cancel"
color="#707070"
size={26}
/>
<Text style={styles.ordersRejected}>
Pedidos recusados: <Text style={styles.value}>0</Text>
</Text>
</View>
<TouchableOpacity
style={styles.completePerformButton}
onPress={() => {}}>
<Text style={styles.completePerformButtonText}>
Ver desempenho completo
</Text>
</TouchableOpacity>
</View>
</View>
);
Style Code Bellow:
import {StyleSheet} from 'react-native';
export default StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
welcomeContainer: {
flexDirection: 'row',
padding: 20,
},
photo: {
width: 50,
height: 50,
borderRadius: 50,
borderWidth: 2,
borderColor: '#8CC63F',
},
welcome: {
fontWeight: 'bold',
fontSize: 18,
padding: 10,
},
performContainer: {
width: 283,
height: 305,
backgroundColor: '#f5f5f5',
marginTop: 20,
borderRadius: 5,
},
performTitle: {
fontSize: 18,
color: '#707070',
fontWeight: 'bold',
borderBottomWidth: 1,
borderColor: '#8CC63F',
padding: 15,
},
earnText: {
fontSize: 16,
padding: 15,
marginBottom: 10,
},
ordersAcepted: {
fontSize: 16,
marginLeft: 10,
marginBottom: 20,
},
ordersRejected: {
fontSize: 16,
marginLeft: 10,
},
completePerformButton: {
alignItems: 'center',
marginTop: 40,
},
completePerformButtonText: {
fontSize: 16,
fontWeight: 'bold',
color: '#8CC63F',
textTransform: 'uppercase',
},
value: {
fontWeight: 'bold',
},
ordersAceptedContainer: {
flexDirection: 'row',
marginBottom: 10,
},
ordersRejectedContainer: {
flexDirection: 'row',
marginTop: 10,
},
iconDelivery: {
width: 26,
height: 26,
marginLeft: 15,
marginBottom: 10,
},
iconDeliveryRejected: {
width: 26,
height: 26,
marginLeft: 15,
marginBottom: 10,
},
location: {
flexDirection: 'row',
marginBottom: 30,
justifyContent: 'center',
},
locationIcon: {
marginRight: 10,
marginTop: 16,
},
locationText: {
fontSize: 14,
marginRight: 60,
marginTop: 20,
fontWeight: 'bold',
color: '#707070',
},
active: {
backgroundColor: '#f5f5f5',
paddingHorizontal: 30,
width: 108,
height: 32,
marginTop: 16,
borderRadius: 15,
flexDirection: 'row',
alignItems: 'center',
},
activeText: {
color: '#8CC63F',
fontSize: 14,
fontWeight: 'bold',
alignItems: 'center',
},
doneIcon: {
flexDirection: 'row',
justifyContent: 'center',
right: 15,
},
});
sssss ssssss. sdvdsnicnciicscoicnci

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',
}

React Native: Component occuping 100% width of his parent container

Good morning everyone, I wanted to ask you about this problem I'm having with my React Native App. Basically it treats that my StatusComponent occupies 100% of the width of its container. I tried in many ways but I can't make its width independent. I share some images and part of my code so it is easier to understand.
In this case the width of the status component its okey because the name of the Event, is smaller than the width of the status component:
Link to Image
MatchComponent Code:
<TouchableOpacity
onPress={() => console.log('Test')})
}>
<LinearGradient
start={{x: 0, y: 0}}
end={{x: 1, y: 2}}
colors={['#FE7062', '#FE8762']}
style={styles.matchContainer}>
<View style={styles.subContainer}>
<View
style={[
styles.footballContainer,
{
backgroundColor: '#4D6FE2',
},
]}>
<Text
style={[
styles.footballText,
{color: 'white'},
]}>
F5
</Text>
</View>
<View>
<Text
style={[
styles.matchTitle,
{color: 'white'},
]}>
Partido 2
</Text>
<Text
style={[
styles.matchField,
{color: 'white'},
]}>
Cancha
</Text>
<StatusComponent
/>
</View>
</View>
<View
style={{
alignItems: 'center',
width: 110,
}}>
<Text style={styles.dateText}>27/08/22</Text>
<View style={{flexDirection: 'row'}}>
<Text
style={[
styles.dateText,
{color: 'white'},
]}>
10:00
</Text>
</View>
</View>
</LinearGradient>
</TouchableOpacity>
);
};
MatchComponent Style:
matchContainer: {
position: 'relative',
height: 95,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
paddingHorizontal: 15,
borderRadius: 20,
marginBottom: 15,
},
subContainer: {
flexDirection: 'row',
alignItems: 'center',
},
footballContainer: {
backgroundColor: '#4D6FE2',
height: 43,
width: 43,
justifyContent: 'center',
alignItems: 'center',
borderRadius: 10,
marginRight: 15,
},
footballText: {
color: 'white',
fontFamily: 'OpenSans-SemiBold',
fontSize: 18,
},
matchTitle: {
fontFamily: 'OpenSans-Bold',
color: 'white',
fontSize: Platform.OS === 'ios' ? 19 : 18,
},
matchField: {
fontFamily: 'OpenSans-Regular',
color: 'white',
fontSize: 14,
},
dateText: {
fontFamily: 'Inter-Medium',
fontSize: 14,
color: 'white',
},
joinContainer: {
backgroundColor: 'orange',
height: 28,
justifyContent: 'center',
borderRadius: 30,
paddingHorizontal: 5,
marginBottom: 4,
},
joinText: {
color: 'white',
fontFamily: 'Inter-Bold',
fontSize: Platform.OS === 'ios' ? 16 : 14,
},
StatusComponent
<View
style={[
styles.matchStatusContainer,
{
backgroundColor: 'red'
},
]}>
<Text
style={[
styles.matchStatusText,
{
color: 'white'
},
]}>
RESER
</Text>
)}
</View>
StatusComponent Style
matchStatusContainer: {
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 8,
marginVertical: 5,
borderRadius: 30,
height: 18,
},
matchStatusText: {
fontFamily: 'Inter-Medium',
fontSize: 12,
marginLeft: 4,
},

Center react native view

I'm creating a component to show the flag and country name. I'll like that view (image + text) centered in the available space.
So if the width of parent is all the screen, there will be space in the left and same in the right. If the parent is only 50% of the screen will be then left space on the sides...
What I've done:
<View style={styles.mainContainer} >
<View >
<TouchableOpacity
disabled={this.props.disablePicker}
onPress={() => this.setState({ modalVisible: true, dataSource: this.props.dataSource })}
activeOpacity={0.7}
>
<View>
<View style={[pickerStyle,{ flexDirection:'row'}]} >
<Image style={{}} source={selectedLabel.image} />
<Text style={}>{selectedLabel.name}</Text>
{dropDownImage ? <Image
style={dropDownImageStyle}
resizeMode="contain"
source={dropDownImage}
/> : null}
</View>
</View>
</TouchableOpacity>
</View>
</View>
const CountryPickerStyles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center"
},
itemSeparatorStyle:{
height: 1,
width: "90%",
alignSelf: "center",
backgroundColor: "#D3D3D3"
},
searchBarContainerStyle: {
marginBottom: 10,
flexDirection: "row",
height: 40,
shadowOpacity: 1.0,
shadowRadius: 5,
shadowOffset: {
width: 1,
height: 1
},
backgroundColor: "rgba(255,255,255,1)",
shadowColor: "#d3d3d3",
borderRadius: 10,
elevation: 3,
marginLeft: 10,
marginRight: 10
},
selectLabelTextStyle: {
color: "#000",
fontSize:16,
flexDirection: "row",
marginLeft: 100,
marginRight: 100
},
placeHolderTextStyle: {
color: "#757575",
padding: 10,
textAlign: "left",
width: "99%",
fontStyle: 'italic',
fontSize:12,
flexDirection: "row"
},
dropDownImageStyle: {
marginLeft: 10,
color: "#757575",
width: 10,
height: 10,
alignSelf: "center"
},
listTextViewStyle: {
color: "#000",
alignItems: "center",
justifyContent: "center",
marginLeft: 20,
marginHorizontal: 10,
textAlign: "left"
},
pickerStyle: {
elevation:0,
paddingRight: 10,
paddingLeft: 10,
marginRight: 10,
marginLeft: 10,
width:"90%",
borderWidth:0 ,
flexDirection: "row"
}
});
here's what I got:
https://pasteboard.co/JG5Rx9P.png
and also https://pasteboard.co/JG5Tthie.png

iFrame Border Showing in WebView React Native

In attempts to dynamically add youtube videos to my React Native app, I chose to use a combination of WebView and iFrame since the current react-native-youtube component doesn't work for RN 16^. Ultimately, the solution does work, but the iframe border still shows and will not go away (even with css or frameborder = 0), nor can I change it's color with css. Any ideas? Here's my code:
video-preview component (where users can see video, title, etc before tapping):
module.exports = React.createClass({
render: function() {
return (
<TouchableHighlight
style={styles.touchCard}
underlayColor={'transparent'}
onPress={this.props.onPress} >
<View style={styles.card}>
<WebView
style={styles.videoPreview}
automaticallyAdjustContentInsets={true}
scrollEnabled={false}
style={styles.videoPreview}
html={this.props.source}
renderLoading={this.renderLoading}
renderError={this.renderError}
automaticallyAdjustContentInsets={false} />
<View style={[styles.container, this.border('organge')]}>
<View style={[styles.header, this.border('blue')]}>
<Text style={[styles.previewText]}>{this.props.text}</Text>
</View>
<View style={[styles.footer, this.border('white')]}>
<View style={styles.sourceRow}>
<View style={[this.border('white')]}>
<ImageButton
style={[styles.logoBtn, , this.border('red'), styles.row]}
resizeMode={'contain'}
onPress={this.onHeartPress}
source={this.props.src} />
</View>
<View style={[this.border('white')]}>
<Text style={[styles.rowText, {fontWeight: 'bold'}]}>{this.props.entryBrand}</Text>
<Text style={[styles.rowText]}>{this.props.views}</Text>
</View>
</View>
<View style={[styles.heartRow, this.border('black')]}>
<KeywordBox
style={[styles.category, this.border('blue')]}
key={this.props.key}
text={this.props.category}
onPress={this.props.categoryPress}
selected={this.props.selected} />
</View>
</View>
</View>
</View>
</TouchableHighlight>
);
Which looks like this:
And the input iframe html into the webview looks like this:
<iframe style='border: 0;border-width: 0px;' scrolling='no' frameborder='0' width='320' height='300' src='https://www.youtube.com/embed/2B_QP9JGD7Q'></iframe>
Here's my styling:
var styles = StyleSheet.create({
centerText: {
marginBottom:5,
textAlign: 'center',
},
noResultsText: {
marginTop: 70,
marginBottom:0,
color: '#000000',
},
sourceRow: {
justifyContent: 'space-around',
flexDirection: 'row',
},
rowText: {
textAlign: 'left',
color: 'white',
fontSize: 12,
marginLeft: 5,
fontFamily: 'SFCompactText-Medium'
},
detailText: {
fontFamily: 'SFCompactText-Light',
fontSize: 18,
color: 'white',
textAlign: 'left',
marginTop: 2,
marginLeft: 5,
},
touchCard: {
margin: 3,
width: window.width*0.95,
shadowOffset: {width: 2, height: 2},
shadowOpacity: 0.5,
shadowRadius: 3,
alignSelf:'center',
},
card: {
flex: 1,
width: window.width*0.98,
alignSelf:'center',
},
heartText: {
color: 'white',
fontSize: 12,
fontWeight: 'bold',
alignSelf: 'center',
fontFamily: 'SFCompactText-Medium'
},
heartRow: {
flexDirection: 'row',
justifyContent: 'space-around',
alignSelf: 'center',
justifyContent: 'center',
},
logoBtn: {
height: window.width/10,
width: window.width/10,
alignSelf:'center',
},
heartBtn: {
height: (92/97)*(window.width/13),
width: window.width/13,
alignSelf:'center',
},
category: {
fontFamily: 'Bebas Neue',
fontSize: 10,
fontWeight: 'bold'
},
header: {
flex: 1,
justifyContent: 'space-around',
marginTop: window.height/60,
},
footer: {
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
margin: window.height/80,
},
container: {
flex: 1,
backgroundColor: '#1a1a1a',
},
videoPreview: {
flex: 2,
height: window.width*0.85,
width:window.width*0.98,
flexDirection: 'column'
},
previewText: {
fontFamily: 'Bebas Neue',
fontSize: 23,
color: 'white',
textAlign: 'left',
marginTop: 2,
marginLeft: 5,
},
});

React Native and Flexbox Views

I'm trying to have a TouchableHighlight + View above this list of generated comments. I can't seem to bring the start of the comments closer up to where the TouchableHighlight ends (it ends right after the text, no padding/margin below).
Here's the relevant JSX:
renderListView: function() {
return (
<View style={styles.container}>
<TouchableHighlight onPress={this.onSelect}>
<View style={styles.header}>
<Text style={styles.text}>
Visit Site
</Text>
</View>
</TouchableHighlight>
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderCommentCell}
style={styles.commentListView} />
</View>
)
},
And here's my styles.js:
container: {
flex: 1,
marginTop: 65,
backgroundColor: '#FFFFFD',
flexDirection: 'column',
},
commentListView:{
margin: 0,
marginTop: 10,
marginRight: 15,
padding: 0,
backgroundColor: '#FFFFFD',
},
centering: {
alignItems: 'center',
justifyContent: 'center',
height: 80
},
header: {
alignItems: 'center',
flexDirection: 'row',
flex: 1
},
loadingText: {
fontSize: 75,
textAlign: 'center',
marginTop: 75,
marginBottom: 10,
marginRight: 10,
color: '#D6573D'
},
text: {
textAlign: 'center',
flexDirection: 'row',
justifyContent: 'center',
alignSelf: 'stretch',
fontSize: 40,
flex: 1
}
Additionally, here's a screenshot of what I'm seeing:
Add automaticallyAdjustContentInsets={false} to your ListView

Resources