A few issues with my visualization:
The text on my first button appears on the right end of the button, even though I have aligned it to the center. How can I shift the text 'login' to the center?
Currently, the 'Sign Up Here' text appears in the mid of the screen. I want it towards the end. However, when I increase the value for marginTop, the text disappears. For instance if I change it to 20, I can see only half of it (in the middle of the screen). If I increase it further it just disappears.
The Forgot Password text also appears on the left side even though I have aligned it.
The title 'My App' does not appear at all.
How can I fix these minor issues?
<Container View style={styles.container}>
<Text View style={styles.title}>
Instaride</Text>
<View style={{flex:1}}></View>
<Form View style={styles.formInput}>
<Item floatingLabel>
<Label View style={styles.labelText}>Username</Label>
<Input
View style={styles.textInput}
onChangeText={(textUname) => uname(textUname)}
value={textUname}
placeholder={'Username'}
/>
</Item>
<Item floatingLabel >
<Label View style={styles.labelText}>Password</Label>
<Input
View style={styles.textInput}
onChangeText={(textPassword) => password(textPassword)}
value={textPassword}
placeholder={'Password'}
secureTextEntry={true}
/>
</Item>
</Form>
<Button View style={styles.button}
onPress={() => navigation.navigate("Details")}>
<Text>Login</Text>
</Button>
<Text View style={styles.forgotText}>
Forgot Password?</Text>
<Right>
<Button hasText transparent onPress={() => navigation.navigate('Registration')}>
<Text View style={styles.signupText}>
Don't have an account? Sign Up Here</Text>
</Button>
</Right>
</Container>
);
}
);
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#242625',
paddingTop: getStatusBarHeight(),
},
title: {
textAlign: 'center',
fontSize: 22,
color: 'white',
},
textInput: {
color: 'white',
},
button: {
marginTop: 15,
backgroundColor: '#65c756',
width: '70%',
height: '6%',
justifyContent: 'center',
alignSelf: 'center'
},
forgotText: {
marginTop: 15,
justifyContent: 'center',
textAlign: 'center',
color: 'white',
},
signupText: {
marginTop: 16,
justifyContent: 'center',
color: 'white',
},
labelText: {
fontSize : 14,
},
formInput: {
borderBottomWidth: 1,
marginLeft: 20,
marginRight: 20,
marginTop: 40,
},
});
UPDATE:
You don't need to use Input View, as that's not the right way.
The below code works and you can check in the Expo demo, you need to add full in the Button.
Answers to the points:
You don't need Left/Right, you can simply put it in View, Left was causing the issue.
Use flex:1 on the Middle Part, so it will grow and occupy the screen and will push your Sign Up here at the bottom
Forget password is pushed to the center
We used getStatusBarHeight and have padding equal to the statusBarHeight
import * as React from "react";
import {
Text,
View,
StyleSheet,
Container,
Form,
Item,
Label,
Input,
Left,
Right,
Button,
Content
} from "native-base";
import { SafeAreaView } from "react-native";
import Constants from "expo-constants";
import { getStatusBarHeight } from "react-native-status-bar-height";
// You can import from local files
import AssetExample from "./components/AssetExample";
// or any pure javascript modules available in npm
import { Card } from "react-native-paper";
export default class App extends React.Component {
render() {
return (
<Container
View
style={Object.assign(
{ ...styles.container },
{ marginTop: getStatusBarHeight() }
)}
>
<Content contentContainerStyle={{ flex: 1 }}>
<View>
<Text style={styles.title}>Instaride</Text>
</View>
<View style={{ flex: 1 }}>
<Form style={Object.assign({ ...styles.formInput }, { flex: 1 })}>
<Item floatingLabel>
<Label style={styles.labelText}>Username</Label>
<Input style={styles.textInput} placeholder={"Username"} />
</Item>
<Item floatingLabel>
<Label style={styles.labelText}>Password</Label>
<Input
View
style={styles.textInput}
placeholder={"Password"}
secureTextEntry={true}
/>
</Item>
<Button
full
style={styles.button}
onPress={() => navigation.navigate("Details")}
>
<Text>Login</Text>
</Button>
</Form>
</View>
<View>
<Text View style={styles.forgotText}>
Forgot Password?
</Text>
<Button
hasText
transparent
onPress={() => navigation.navigate("Registration")}
style={{ justifyContent: "center" }}
>
<Text style={styles.signupText}>
Don't have an account? Sign Up Here
</Text>
</Button>
</View>
</Content>
</Container>
);
}
}
const styles = {
container: {
flex: 1,
backgroundColor: "#242625",
borderWidth: 2,
borderColor: "red"
},
title: {
textAlign: "center",
fontSize: 22,
color: "white"
},
textInput: {
color: "white"
},
button: {
marginTop: 15,
backgroundColor: "#65c756"
},
forgotText: {
marginTop: 15,
justifyContent: "center",
textAlign: "center",
color: "white"
},
signupText: {
textAlign: "center",
justifyContent: "center",
color: "white"
},
labelText: {
fontSize: 14
},
formInput: {
borderBottomWidth: 1,
marginLeft: 20,
marginRight: 20
}
};
Temporary Link to Expo: https://snack.expo.io/#dhavaljardosh/8af9d3
Related
I have an issue with the text of the TabBar that is not written on same line like shown in the photo. On small screen (Iphone 12) it works perfectly but when i changed to big screen of (Ipad 12.9 inch) How can i prevent that?
I have my code:
<Tab.Screen
name="Shop"
component={ShopNavigator}
options={(navigation, route) => ({
title: 'Shop',
tabBarVisible: false,
tabBarIcon: ({ props, focused }) => (
<View {...props} >
<View style={{flex: 2, alignItems: 'center'}}>
<Image source={SHOP} resizeMode="contain" style={[styles.imgSize, focused && { opacity:1 }]} />
<Text style={[styles.label, focused && { opacity:1, textDecorationLine: 'underline' }]}>Vente en ligne</Text>
</View>
</View>
)
})}
/>
imgSize: {
height: 30,
width: 30,
padding: 15,
opacity: 0.8,
},
label: {
color: '#FFF',
fontSize: 10,
textAlign: 'center',
fontFamily: 'Barlow-Bold',
opacity: 0.8,
}
Just give it more space:
label: {
color: '#FFF',
fontSize: 10,
textAlign: 'center',
fontFamily: 'Barlow-Bold',
opacity: 0.8,
width: "100%" //should take. 100% of the available space
}
I would also add the numberOfLines = 1 prop to the Text component to prevent incredibly small screens
Nothing works except returning empty function for renderLabel then having renderIcon display icon and text (placed side by side)
here is the code for more understanding
const renderTabBar = props => {
return <TabBar
{...props}
indicatorStyle={{ backgroundColor: 'grey' }}
style={{ backgroundColor: '#fff' }}
renderIcon={({ route, focused, color }) => {
return <Text style={{ color: '#000', margin: 8 }}><AntIcon
size={13}
name={route?.icon}
color={'#000'}
/>
{" "} {route.title}
</Text>}
}
renderLabel={({ route, focused, color }) => {}}
/>
}
In a React project, I've create a Recharge Wallet page, which has Recharge button to recharge coins. A new page is created by overriding on another page. All the elements are created in Material UI. For some reason, all elements are overflowing through the components. Its probably CSS issue. What could be the best solution to prevent overflowing.
Following is the code reference
const navScrollStyle = makeStyles((theme) => ({
root: {
marginTop: '70px',
display: 'table',
overflowY: 'hidden',
maxWidth: 'auto',
display: 'flex',
justifyContent: 'center',
}
}));
const navBodyStyle = makeStyles((theme) => ({
root: {
flexGrow: 1,
top: "0px",
position: "absolute",
width: "100%",
height: '100vh',
textAlign: 'center',
background: 'white',
zIndex: '9',
height: '100%',
overflowY: 'auto'
},
menuButton: {
marginRight: theme.spacing(2),
color: "purple"
},
title: {
flexGrow: 1,
textAlign: "center",
color: "black"
}
}));
const gridClassStyle = makeStyles((theme) => ({
root: {
flexGrow: 1,
position: 'fixed',
top: '0px',
background: 'white',
flexWrap: "nowrap",
boxShadow: '5px 10px 18px #888888',
},
paper: {
padding: theme.spacing(2),
textAlign: 'center',
color: theme.palette.text.secondary,
},
menuButton: {
marginRight: theme.spacing(2),
color: "purple"
},
title: {
flexGrow: 1,
textAlign: "center",
color: "black"
}
}));
const useStyles5 = makeStyles((theme) => ({
root: {
'& > *': {
margin: theme.spacing(1),
},
textAlign: 'center',
width: '100%'
},
}));
const NewPage = () => {
const navBody = navBodyStyle()
const navScroll = navScrollStyle()
const gridClass = gridClassStyle()
const classes5 = useStyles5()
const NavPart = () => (
<Grid className={gridClass.root} container spacing={3}>
<Grid item xs={4} style={{ textAlign: 'left' }}>
<IconButton
edge="start"
className={gridClass.menuButton}
color="inherit"
aria-label="menu"
>
<Link to="/">
<ArrowBackIcon />
</Link>
</IconButton>
</Grid>
<Grid item xs={4} style={{ textAlign: 'center', justifyContent: 'center' }}>
<Typography variant="h6" className={gridClass.title}>
<h2>Wallet</h2>
</Typography>
</Grid>
<Grid item xs={4} style={{ textAlign: 'right', marginTop: '2%' }}>
<IconButton
aria-label="account of current user"
aria-controls="menu-appbar"
aria-haspopup="true"
>
<AccountCircle style={{ fontSize: "30px" }} />
</IconButton>
</Grid>
</Grid>
)
return (
<div className={navBody.root}>
{NavPart()}
<div className={navScroll.root}>
<div className={classes5.root}>
<Button variant="contained" color="secondary">
<Link to="/purchaseCoins">
Recharge Wallet
</Link>
</Button>
<br />
<Button variant="contained" color="secondary">
<Link to="/purchaseCoins">
Recharge Wallet
</Link>
</Button>
<br />
</div>
</div>
</div>
)
}
I have purposefully added recharge wallet button to test the overflowing.
Here is the codesandbox link for much clarity: https://codesandbox.io/s/react-material-forked-71op5.
Please click on 'WALLET' button when page loads
I changed the marginTop of navScrollStyle, overflowY to auto, and assigned a zIndex to the gridClassStyle. I think it's what you were looking for. Please check the online version here on sandbox
You gave 70px to the Wallet component, and I think you can give the height value of calc (100% - 70px). You must adjust the height as much as the margin-top px.
I am trying to center the content in the center of the page. There is a block where the height is only going to the bottom of the content. (Acting like height: "auto"). I want the height of the tan block to be 100%. I have tried using justifyContent: "center" and nothing works. The top portion is also scrollable and I want no scrolling. enter image description here
import {StyleSheet, TouchableOpacity, Text, View, Button} from 'react-native';
import {NativeRouter, Route, Link} from 'react-router-native';
import {TextInput} from 'react-native-paper';
import {mdiArrowRightCircleOutline} from '#mdi/js';
class Register extends Component {
state = {
email: '',
password: '',
confirmPassword: '',
};
render() {
return (
<View style={styles.root}>
<View style={styles.wrapper}>
<Text style={{marginBottom: 8, fontSize: 20}}>Welcome,</Text>
<Text style={{marginBottom: 12, fontSize: 20}}>
sign up to continue
</Text>
<TextInput
label="Email"
value={this.state.email}
onChangeText={email => this.setState({email})}
style={styles.form}
underlineColor="#eb0091"
/>
<TextInput
label="Password"
value={this.state.email}
onChangeText={password => this.setState({password})}
style={styles.form}
underlineColor="#eb0091"
/>
<TextInput
label="Confirm Password"
value={this.state.email}
onChangeText={confirmPassword => this.setState({confirmPassword})}
style={styles.form}
underlineColor="#eb0091"
/>
<Text
style={{fontSize: 20, color: '#eb0091'}}
onPress={() => this.props.history.push('/')}>
Sign Up
</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
root: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
//backgroundColor: '#ffffff', uncomment this once height issue is better
},
wrapper: {
width: '80%',
},
form: {
marginBottom: 20,
},
footer: {
position: 'absolute',
bottom: 0,
},
});
export default Register;
I don't see any problem in the code so the problem must me in the component which contain , can you share the rest of the code.
I have a component with TextInput and another component which is called CompanyAddress. Each company can have many addresses, therefore I have to have "plus" button.
There are container styles
const AppStyles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#ffffff",
alignItems: "center",
justifyContent: "center"
},
inputStyle: {
height: 40,
width: '80%',
borderColor: '#28c9d9',
textAlign: 'center',
borderWidth: 1,
marginBottom: 20,
fontSize: 16
}
});
there is main component
<KeyboardAvoidingView behavior="padding" style={AppStyles.container}>
<TextInput
autoCompleteType="name"
placeholder="organization"
maxLength={30}
style={AppStyles.inputStyle}
onChangeText={(text) => { this.setState({name: text})} }
/>
<CompanyAddress/>
</KeyboardAvoidingView>
and there is CompanyAddress
class CompanyAddress extends React.Component<any, any> {
render() {
return (
<View style={styles.container}>
<TextInput
autoCompleteType="name"
placeholder="address"
maxLength={30}
style={[AppStyles.inputStyle, styles.textInput]}
/>
<AntDesign style={styles.plus} name="plus" size={24} color="black" />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
width: '100%',
flexDirection: 'row'
},
textInput: {
width: '70%',
},
plus: {
width: '30%'
}
});
but my CompanyAddress now looks like that
but I want to change styles for achieve that
you can add justifyContent:center to the container and for the children alignSelf:Center
ex:
<View style={{justifyContent : center,flexDirection:row}}>
<View style={{alignSelf:Center}}><View>
<View style={{alignSelf:Center}}><View>
</View>
I'm setting up some screens for an app using React-Native, and I want to fully understand how Flexbox works.
I'm trying to set the marginHorizontal property in style of textinput and button, but nothing happens.
If I set the specific value of width I do not have any problem.
Why marginHorizontal does not work properly?
The first image is what I get using marginHorizontal (the size of the button doesn't change and the margin from board is not 10);
The second image is what I get when I use width prop (the button size changes according the value of width).
I just wonder why with the marginHorizontal prop, nothing happens.
import React, { Component } from 'react'
import {Text, StyleSheet, View, TextInput, TouchableOpacity} from 'react-native'
import Swiper from 'react-native-swiper';
import {Button} from 'react-native-elements'
const formInputColor = 'rgba(255, 255, 255, 0.2)'
const formInputPlaceholderColor = 'rgba(255, 255, 255, 0.7)'
export default class RegisterFormComponent extends Component{
render(){
return(
<Swiper
style={styles.wrapper}
loop = {false}
>
<View style={styles.slide1}>
<View style={styles.topContainer1}>
<Text
style={styles.text}>What's you mail?
</Text>
<TextInput
placeholder = "Email"
placeholderTextColor = {formInputPlaceholderColor}
returnKeyType = "next"
style = {styles.formInput}
/>
<Text
style={styles.underText}
multiline={true}>blablablablablablablablablablablablablablablablablablablablablablablablablablablablablablabla
</Text>
<Button
style={styles.buttonStyle}
//textStyle = {styles.buttonTextStyle}
//loading={false}
>
</Button>
</View>
<View style={styles.bottomContainer1}>
</View>
</View>
<View style={styles.slide2}>
<View style={styles.topContainer1}>
<Text
style={styles.text}>Choose your password
</Text>
<TextInput
placeholder = "Password"
placeholderTextColor = {formInputPlaceholderColor}
secureTextEntry
returnKeyType = "go"
style = {styles.formInput}
/>
</View>
<View style={styles.bottomContainer1}>
</View>
</View>
<View style={styles.slide3}>
<Text style={styles.text}>And simple</Text>
</View>
</Swiper>
)
}
}
const styles = StyleSheet.create({
wrapper: {
flex: 1
},
slide1: {
flex: 1,
backgroundColor: '#3498db',
},
buttonStyle: {
backgroundColor: '#2980b9',
marginTop: 10,
height: 25,
marginHorizontal: 10
},
buttonTextStyle: {
fontSize: 10
},
topContainer1: {
flex: 1,
alignItems: 'center',
justifyContent: 'center'
},
logoStyle: {
width: 100,
height: 100,
},
bottomContainer1: {
flex: 1,
},
formInput:{
height: 40,
backgroundColor: formInputColor,
color: '#FFF',
marginHorizontal: 10,
paddingHorizontal: 10,
textAlignVertical: 'top'
},
slide2: {
flex: 1,
backgroundColor: '#97CAE5'
},
slide3: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#92BBD9'
},
text: {
color: '#000',
fontSize: 20,
padding: 10,
fontWeight: 'bold'
},
underText: {
color: 'black',
fontSize: 12,
marginTop: 8,
textAlign: 'center',
width: 300
}
})