I keep getting the error:
"Unexpected token, expected "," (101: 93)
I have been looking through every line of my code for a couple hours now and cannot wrap my head around the issue.
It was working completely fine and when I exited the application (because the app was frozen) and ran the project again (react-native run-ios) it threw this error.
Here is my code. Please excuse the styling/organization since I am a complete beginner. Also - there is a lot of styling that I haven't used.
import React, {Component} from 'react'
import {StyleSheet, Text, View, Image, TouchableWithoutFeedback, StatusBar, TextInput, SafeAreaView, Keyboard, TouchableOpacity, KeyboardAvoidingView} from 'react-native'
import {createStackNavigator} from 'react-navigation'
import LinearGradient from 'react-native-linear-gradient'
export default class MainScreen extends Component {
constructor(props) {
super(props);
this.state={
username: '',
email: '',
name: '',
password: '',
User: this.props.navigation.state.params.username,
Email: this.props.navigation.state.params.email,
Name: this.props.navigation.state.params.name,
Password: this.props.navigation.state.params.password
}
}
render() {
const { navigation } = this.props;
const {state} = this.props.navigation;
return(
<SafeAreaView style={styles.container} >
<StatusBar barStyle="light-content"/>
<View style = {styles.container}>
<View style = {styles.topContainer}>
<TouchableOpacity onPress={() => navigation.navigate('Help')}>
<Image style = {styles.questionMark}
source ={require('../images/questionWhite.png')}>
</Image>
</TouchableOpacity>
<View style={styles.logoContainer}>
<Image style = {styles.logo}
source ={require('../images/white.png')}>
</Image>
<Image style = {styles.logoTwo}
source ={require('../images/whitetext.png')}>
</Image>
</View>
</View>
<View style={styles.middleContainer}>
<View style={styles.textContainer}>
<Text style={styles.textStyle}>
Earn points
</Text>
<Text style={styles.lowerTextStyle}>
for recommending
</Text>
</View>
<View style={styles.exclusiveButtonContainer}>
<TouchableOpacity onPress={() => navigation.navigate('PurchaseScreenOne')}>
<View style = {{backgroundColor: 'white', alignItems: 'center', justifyContent: 'center', borderRadius: 30, height: 50, width: 330, marginLeft: 0, marginTop:35}}>
<Text style = {styles.exclusiveButton}>Get Deals </Text>
</View>
</TouchableOpacity>
<Image style = {styles.templateLayout}
source ={require('../images/template.png')}>
</Image>
<Image style = {{marginTop: -210, marginLeft: 0, height: 81, width: 81}}
source = {{uri: 'https://imagesource.com/8346278432'}}/>
<TouchableOpacity onPress={() => navigation.navigate('Edit', {username: this.state.User, email: this.state.Email, name: this.state.Name, password: this.state.Password})}>
<Image style = {{marginTop: -90, marginLeft: 300, height: 41, width: 41}}
source ={require('../images/editProfile.png')}>
</Image>
</TouchableOpacity>
<TextInput style={{fontWeight: '700', fontSize: 22, marginTop: 5, color: '#d0011b'}} value={this.state.User}/>
<Text style={{fontWeight: '700', fontSize: 22, marginTop: 40, color: '#d0011b', marginLeft: 180}}>
0
</Text>
<Text style={{fontWeight: '700', fontSize: 22, marginTop: 5, color: '#d0011b', marginTop: -30, marginRight: 180}}>
$0
</Text>
<View style={{flexDirection: 'row', marginTop: 30, marginBottom: 90}}>
<TouchableOpacity onPress={() => navigation.navigate('History')}>
<View style = {{backgroundColor: 'white', alignItems: 'center', justifyContent: 'center', borderRadius: 30, height: 50, width: 171, marginLeft: 0, marginBottom: 15}}>
<Text style = {styles.loginButton}>View Purchases</Text>
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => navigation.navigate('GetFreeMoney', {username: this.state.User})}>
<View style = {{backgroundColor: 'white', alignItems: 'center', justifyContent: 'center', borderRadius: 30, height: 50, width: 171, marginLeft: 10}}>
<Text style = {styles.loginButton}>Invite Friends</Text>
</View>
</TouchableOpacity>
</View>
</View>
</View>
</View>
</SafeAreaView>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#D0011B',
flexDirection: 'column'
},
topContainer: {
alignItems: 'center',
justifyContent: 'center',
marginTop: 90,
flex: 1
},
logo: {
width: 168,
height: 61,
resizeMode: 'contain'
},
logoTwo: {
width: 238,
height: 39,
resizeMode: 'contain'
},
logoContainer: {
alignItems: 'center',
justifyContent: 'center',
marginTop: 90
},
questionMark: {
width: 37,
height: 37,
resizeMode: 'contain',
marginLeft: 320,
marginBottom: 50,
marginTop: -20
},
textStyle: {
color: 'white',
fontSize: 20,
width: 186,
height: 27,
alignItems: 'center',
justifyContent: 'center'
},
lowerTextStyle: {
color: 'white',
fontSize: 20,
width: 244,
height: 27,
alignItems: 'center',
justifyContent: 'center',
},
textContainer: {
alignItems: 'center',
justifyContent: 'center',
marginBottom: 20
},
exclusiveButtonContainer: {
alignItems: 'center',
justifyContent: 'center',
marginBottom: 200
},
exclusiveButton: {
width: 311,
height: 50,
alignItems: 'center',
justifyContent: 'center',
resizeMode: 'contain',
},
middleContainer: {
alignItems: 'center',
justifyContent: 'center',
marginTop: 200
},
textTemplateFormat: {
color: '#D0011B',
fontSize: 22,
fontWeight: 'bold'
},
profileTemplateContainer: {
marginLeft: 13,
width: 351,
height: 209,
alignItems: 'center',
justifyContent: 'center',
resizeMode: 'contain',
marginTop: -280
},
displayPictureStyle: {
marginLeft: 13,
alignItems: 'center',
justifyContent: 'center',
resizeMode: 'contain',
marginTop: -200
},
lowerContainer: {
alignItems: 'center',
justifyContent: 'center',
marginBottom: 1000,
marginLeft: -10
},
groundContainer: {
alignItems: 'center',
justifyContent: 'center',
},
textTemplateFormat: {
alignItems: 'center',
justifyContent: 'center',
flex: 1,
marginTop: -110,
fontSize: 20,
fontWeight: 'bold',
marginLeft: 15,
color: '#D0011B'
},
savingsStyle: {
width: 120,
height: 20,
alignItems: 'center',
justifyContent: 'center',
marginRight: 160,
marginBottom: 200
},
buttonContainer: {
alignItems: 'center',
justifyContent: 'center'
},
templateLayout: {
width: 370,
height: 230,
resizeMode: 'contain',
marginTop: 20
},
loginButton: {
fontSize: 16,
fontWeight: "700",
textAlign: "center",
color: '#d0011b'
},
exclusiveButton: {
fontSize: 22,
fontWeight: "700",
textAlign: "center",
color: '#d0011b'
}
})
Note that I've deleted major areas of code and the error still shows up in the same line location which is making me think this is a glitch of some sort?
Related
React Native alert defaults to showing up at the center of the screen. I've been trying to style it so that it shows up at the bottom of the screen - with no success. Does anyone know how I would go about this? I tried position: absolute and bottom: 0 but it still shows up in the center.
I have tried this out let me know if it helps also have designed according to the image.
Copy Paste the code and try.
import React, { useState } from 'react';
import {
StyleSheet,
View,
Text,
TextInput,
Pressable,
Modal,
Dimensions,
Button,
} from 'react-native';
const App = () => {
const [showWarning, SetshowWarning] = useState(false);
const onPressHandler = () => {
SetshowWarning(true);
}
return (
<View style={styles.body}>
<Modal
visible={showWarning}
transparent
onRequestClose={() =>
SetshowWarning(false)
}
animationType='slide'
hardwareAccelerated
>
<View style={styles.centered_view}>
<View style={styles.warning_modal}>
<View style={styles.warning_title}>
<Text style={{
color: '#000000',
fontSize: 25,
fontWeight:'700',
textAlign: 'center',
}}>Unsaved Changes</Text>
<Text style={styles.text}>Are you sure you want to continue?</Text>
</View>
<Pressable
onPress={() => SetshowWarning(false)}
style={styles.warning_button1}
android_ripple={{ color: '#fff' }}
>
<Text style={styles.textKE}>Keep Editing</Text>
</Pressable>
<Pressable
onPress={() => SetshowWarning(false)}
style={styles.warning_button}
android_ripple={{ color: '#fff' }}
>
<Text style={styles.textDC}>Discard Changes</Text>
</Pressable>
</View>
</View>
</Modal>
<Button onPress={() =>onPressHandler()} title="Text This"></Button>
{/* Add Here full code */}
</View >
);
};
const styles = StyleSheet.create({
body: {
flex: 1,
backgroundColor: '#ffffff',
alignItems: 'center',
},
centered_view: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#00000099',
},
warning_modal: {
width: Dimensions.get('window').width,
height: 200,
backgroundColor: '#eeff0f0',
borderRadius: 20,
top:"31%"
},
warning_title: {
height: 100,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#eff0f0',
borderTopRightRadius: 20,
borderTopLeftRadius: 20,
borderBottomWidth:1,
borderColor:'grey'
},
warning_body: {
height: 100,
justifyContent: 'center',
alignItems: 'center',
},
textKE: {
marginTop:20,
color: '#1485fe',
fontSize: 20,
margin: 5,
textAlign: 'center',
},
textDC: {
marginTop:20,
color: 'red',
fontSize: 20,
margin: 5,
textAlign: 'center',
},
warning_button1: {
height:70,
backgroundColor: '#efeff0',
borderBottomWidth:1,
borderColor:'grey'
},
warning_button: {
height:70,
backgroundColor: '#efeff0',
borderBottomLeftRadius: 20,
borderBottomRightRadius: 20,
}
});
export default App;
Hi while uploading the picture from iPhone using react-native-fs in my react-native app. I am getting below error.
How to fix this above issue.
I fixed the above issue by adding this captureTarget={Camera.constants.CaptureTarget.disk} line of code in my file.
import React, {Component} from 'react';
import {
StyleSheet,
Text,
View
} from 'react-native';
import Camera from 'react-native-camera';
import RNFS from 'react-native-fs';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<View style={styles.titlebar}>
<Text style={styles.title}>Welcome {this.props.navigation.getParam('FirstName', '')}</Text>
</View>
<Camera
ref={(cam) => {
this.camera = cam;
}}
type={'front'}
style={styles.preview}
aspect={Camera.constants.Aspect.fill}
captureQuality={Camera.constants.CaptureQuality.low}
captureTarget={Camera.constants.CaptureTarget.disk}
>
<View>
<View style={styles.buttoncontainer}>
{
this.props.navigation.getParam('LogType', '') &&
<Text style={styles.in} onPress={this.takePicture.bind(this)}>IN</Text>
}
{!this.props.navigation.getParam('LogType', '') &&
<Text style={styles.out} onPress={this.takePicture.bind(this)}>OUT</Text>
}
</View>
</View>
</Camera>
</View>
);
}
takePicture() {
this.camera.capture()
.then((data) =>
this.ServiceCall(data)
)
.catch(err => console.error(err));
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'white'
},
title: {
flex: 1,
alignSelf: 'center',
fontSize: 30,
color: 'black',
backgroundColor: 'white'
},
titlebar: {
flexDirection: 'row',
backgroundColor: 'white',
paddingTop: 10,
paddingBottom: 10,
paddingLeft: 5
},
buttoncontainer: {
flexDirection: 'row',
},
preview: {
flex: 1,
justifyContent: 'flex-end',
alignItems: 'center'
},
in: {
fontSize: 30,
backgroundColor: 'green',
marginBottom: 20,
padding: 20,
color: 'white',
borderRadius: 10,
textAlign: 'center'
},
out: {
fontSize: 30,
padding: 20,
backgroundColor: 'red',
marginBottom: 20,
color: 'white',
borderRadius: 10,
textAlign: 'center'
},
});
strong text
I am trying to use the KeyboardAvoidingView with behavior="padding".
When I am trying to enter any text in TextInput, the TextInput field is not moving up. I have added a small view in the end which is moving up but the the view above it.
I have also with KeyboardAvoidingView height property with offset. It was working few components like 2 TextInputs. But when I add all the components the UI goes insane and behave jumbled up.
Any any idea whats happening over here?
Here the link of tutorial which I have followed.
render() {
return (
<View style={styles.backgroundContainer}>
<Loader
loading={this.state.isLoading} />
<KeyboardAvoidingView
keyboardVerticalOffset={10}
style={styles.mainContainer}
behavior='padding' >
<View style={styles.formContainer}>
<View style={[styles.centerContainer, { marginTop: 40 }]}>
<Image source={require('./../../Resources/logo.png')} />
<Text style={{ fontWeight: 'bold', color: 'gray', fontSize: 25 }}>AppName</Text>
<Text style={styles.loginMsg}> Login to your Account </Text>
</View>
<View style={styles.inputFieldsContainer}>
<Image style={{ width: 30, height: 30, margin: 5 }} source={require('./../../Resources/logo.png')} />
<TextInput
placeholder='Email'
returnKeyType='next'
keyboardType='email-address'
onChangeText={(value) => this.setState({ userEmail: value })}
onSubmitEditing={() => this.passwordInput.focus()}
style={styles.inputFields} />
</View>
<View style={styles.inputFieldsContainer}>
<Image style={{ width: 30, height: 30, margin: 5, }} source={require('./../../Resources/logo.png')} />
<TextInput
returnKeyType='go'
secureTextEntry
placeholder='Password'
ref={(input) => this.passwordInput = input}
onChangeText={(value) => this.setState({ password: value })}
style={styles.inputFields} />
</View>
<View style={styles.buttonContainer}>
<Button
fontSize='8'
color='gray'
title='Remember Me'
onPress={() => {
console.log('Remember Me Clicked');
}} />
<Button
color='gray'
title='Forgot Password?'
onPress={() => {
console.log('Forgot Password Clicked');
}} />
</View>
<TouchableOpacity
style={styles.buttonLogin}
onPress={() => {
console.log('Login Clicked');
}}
>
<Text style={{ fontSize: 20, fontWeight: 'bold', color: 'white' }}>Login</Text>
</TouchableOpacity>
<View style={{ height: 1, backgroundColor: 'gray', marginTop: 20, marginBottom: 1 }}>
</View>
<View style={[styles.centerContainer, { marginBottom: 10 }]}>
<Text style={styles.loginMsg}>Don't have a Account</Text>
<TouchableOpacity
style={styles.buttonRegister}
onPress={() => navigate('Register')} >
<Text style={styles.buttonRegisterText}>REGISTER NOW</Text>
</TouchableOpacity>
</View>
</View>
<View style={{ height: 10, backgroundColor: '#628499', }}>
</View>
</KeyboardAvoidingView>
</View>
);
}
const styles = StyleSheet.create({
backgroundContainer: {
flex: 1, backgroundColor: 'green'
},
mainContainer: {
flex: 1, margin: 25,
borderWidth: 1, borderRadius: 5, borderColor: 'gray',
backgroundColor: 'white',
justifyContent: 'space-between'
},
formContainer: {
flex: 1, paddingLeft: 25, paddingRight: 25
},
centerContainer: {
alignItems: 'center', marginBottom: 10,
},
loginMsg: {
margin: 10,
fontSize: 20, color: 'gray'
},
inputFieldsContainer: {
flexDirection: 'row', margin: 10,
borderWidth: 1, borderRadius: 5, borderColor: 'gray',
},
inputFields: {
flexGrow: 1,
marginTop: 5, marginBottom: 5,
height: 30,
backgroundColor: 'rgba(255,255,255,0.4)',
paddingHorizontal: 10,
},
buttonContainer: {
flexDirection: 'row',
justifyContent: 'space-between'
},
buttonLogin: {
alignItems: 'center', height: 40, marginTop: 10, marginLeft: 50, marginRight: 50, padding: 5,
backgroundColor: '#2980b9',
borderWidth: 1, borderRadius: 5, borderColor: 'gray'
},
buttonRegister: {
alignItems: 'center', height: 40,
marginLeft: 50, marginRight: 50
},
buttonRegisterText: {
fontSize: 20, fontWeight: 'bold', color: 'gray'
},
loading: {
position: 'absolute',
left: 0, right: 0, top: 0, bottom: 0,
alignItems: 'center', justifyContent: 'center'
}, });
I used KeyboardAvoidingView, it also doesn't work.
I found this solution, You can take the base code.
Installation
npm i react-native-keyboard-aware-scroll-view --save
Usage
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
<KeyboardAwareScrollView>
<View>
<TextInput />
</View>
</KeyboardAwareScrollView>
You can find it here
The way it worked for me was to use position as behavior and -70 as vertical offset. Any non negative integer was creating a huge unused space when the keyboard pops up.
<KeyboardAvoidingView
style={styles.container}
behavior={Platform.OS === 'ios' ? 'position' : 'height'}
keyboardVerticalOffset={Platform.OS === 'ios' ? -70 : 70}
enabled>
<ScrollView>
...
</ScrollView>
</KeyboardAvoidingView>
<KeyboardAvoidingView
style={styles.mainContainer}
behavior="padding"
enabled
>
<View>.......................</View>
</KeyboardAvoidingView>
'Enabled or disabled KeyboardAvoidingView' should be add.
Keep in mind is always your top Parent with flex:1 then the child is then you text input container
<KeyboardAvoidingView style={{ flex: 1 }}
behavior={Platform.OS === "ios" ? "position" : null} enabled>
<ScrollView>
<View>
<View >
<Text maxFontSizeMultiplier={1.5} >
Sign in to your account{" "}
</Text>
<View
behavior="padding"
enabled
>
<TextInput
placeholder="Email address"
placeholderTextColor={Colors.grey}
style={styles.textInput}
onChangeText={(e) => setEmail(e.trim())}
autoCapitalize="none"
returnKeyType={"done"}
/>
</View>
</View>
</ScrollView>
</KeyboardAvoidingView>
// 2nd Solutions use this package
npm i react-native-keyboard-aware-scroll-view --save
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
<KeyboardAwareScrollView>
<View>
<TextInput />
</View>
</KeyboardAwareScrollView>
I'm Trying to input a value using TextInput but the keyboard is blocking the view. I configured KeyboardAvoidingView with padding so the elements are pushed up when the keyboard is active but my input field is still getting blocked entirely by the keyboard. I tried creating a parent view for the entire render method and wrapped my child views with KeyboardAvoidingView however this did not work either. Screenshots show the behavior.
Tested on iOS Emulator.
return (
<KeyboardAvoidingView behavior='padding'>
<View>
<View style={styles.container}>
<View style={styles.header}>
{jsonData}
<TouchableHighlight
underlayColor='transparent'
style={styles.btn}
onPress={this.goToAcibtnTwo}>
<Image source={images.prredbtn}></Image>
</TouchableHighlight>
<Text style={styles.textthingsmall}>{'Must be Paid Immediately'}</Text>
{jsonData2}
<TouchableHighlight
underlayColor='transparent'
style={styles.btn}
onPress={this.goToAcibtnTwo}>
<Image source={images.prgreenbtn}></Image>
</TouchableHighlight>
<Text style={styles.textthingsmall}>{'May include next payment or other fees'}</Text>
{jsonData3}
<TouchableHighlight
underlayColor='transparent'
style={styles.btn}
onPress={this.goToAcibtnTwo}>
<Image source={images.prgreenbtn}></Image>
</TouchableHighlight>
{jsonData4}
<View
style={{
flexDirection: 'row',
paddingBottom: 15
}}>
<TouchableHighlight
underlayColor='transparent'
style={styles.btn}
onPress={this.goToAcibtnTwo}>
<Image source={images.prgreenbtn}></Image>
</TouchableHighlight>
<TextInput
style={{
borderColor: 'white',
borderWidth: 2,
height: 40,
width: 100,
fontSize: 17,
marginLeft: 60,
justifyContent: 'center',
alignSelf: 'center',
color: 'white'
}}
keyboardType='numeric'
placeholder='0.00'
returnKeyType="done"
maxLength={10}
placeholderTextColor='ghostwhite'
onChangeText={(valueMoney) => this.setState({valueMoney})}
value={this.state.valueMoney}
onEndEditing={this.formatedMoneyEnd}/>
</View>
</View>
<View>
<Image style={styles.btmicons} source={images.optionsroundbtn}/>
</View>
</View>
</View>
</KeyboardAvoidingView>
);
}
}
export default Profile;
Here's the CSS
header: {
alignSelf: 'center',
height: window.height * 0.7,
backgroundColor: '#0450A1',
width: 400
},
bottom: {
alignSelf: 'center',
width: 400
},
btmicons: {
flexDirection: 'column'
},
headerthing: {
flex: 1,
alignItems: 'center',
paddingTop: 10
},
textthing: {
alignSelf: 'flex-start',
paddingLeft: 35,
fontFamily: 'SFProText-Regular',
fontSize: 17,
color: '#FFFFFF',
flexDirection: 'row'
},
textthingsmall: {
alignSelf: 'flex-start',
paddingLeft: 35,
fontFamily: 'SFProText-Regular',
fontSize: 12,
paddingTop: 3,
color: '#FFFFFF',
flexDirection: 'row'
},
numberthing: {
alignSelf: 'flex-end',
paddingRight: 10,
fontFamily: 'SFProText-Regular',
fontSize: 35,
color: '#FFFFFF'
},
headerthing2: {
alignItems: 'center',
flex: 1,
padding: 1
},
separator: {
alignSelf: 'center'
},
btn: {
alignSelf: 'flex-start',
paddingLeft: 35,
marginBottom: 0,
paddingBottom: 0
},
headerthing3: {
alignItems: 'center',
flex: 1,
flexDirection: 'row'
},
rowLabelnum: {
fontFamily: 'PTSans-Regular',
fontSize: 24,
color: '#FFFFFF'
},
rowLabelnummain: {
fontFamily: 'PTSans-Regular',
fontSize: 36,
color: '#FFFFFF',
alignSelf: 'center'
},
rowLabelText: {
fontFamily: 'PTSans-Bold',
fontSize: 24,
color: '#FFFFFF'
},
rowLabelTextmain: {
fontFamily: 'PTSans-Bold',
fontSize: 30,
color: '#FFFFFF'
},
rowLabelnumbtn: {
fontFamily: 'PTSans-Regular',
fontSize: 20,
color: '#252525'
},
rowLabelTextbtn: {
fontFamily: 'PTSans-Bold',
fontSize: 25,
color: '#252525'
},
separate: {
alignSelf: 'center',
justifyContent: 'center',
width: 2,
height: 100,
backgroundColor: '#FFFFFF',
marginBottom: 20
},
content: {
flexDirection: 'row',
alignSelf: 'center',
justifyContent: 'center',
width: 357,
height: 2,
backgroundColor: '#FFFFFF',
marginBottom: 30
},
rectangleTop: {
marginTop: 80,
padding: 2
},
rectangleText: {
flex: 1,
flexDirection: 'row'
},
rectangleleft: {
flexDirection: 'row',
alignSelf: 'center',
justifyContent: 'center'
},
keyboardview: {
justifyContent: 'center',
paddingHorizontal: 20,
paddingTop: 20
}
I gave you a suggestion in the comment, but here, I am going to give you a demo that shows how to use KeyboardAvoidingView.
<KeyboardAvoidingView behavior="padding" style={styles.bottomcontainer}>
<View style={styles.mobilecontainer}>
<Text style={styles.getmovingtext}>Get ready with BitFamily</Text>
<View style={styles.mobilenumbercontainer}>
<PhoneInput
ref='phone'
onChangePhoneNumber={(text)=> this.setState({phoneNumber:text})}
onPressFlag={this.onPressFlag}
textProps={{placeholder: 'Enter mobile number',autoFocus:false,}}>
</PhoneInput>
<CountryPicker
ref='countryPicker'
onChange={(value)=> this.selectCountry(value)}
translation='eng'
cca2={this.state.cca2}
>
<View></View>
</CountryPicker>
<View style={styles.horizontalLine}/>
<View style={styles.buttoncontainer}>
<Text style={styles.verifytext} onPress={()=>this.callApi()}>Get confirmation code Now.</Text>
</View>
<View style={styles.socialcontainer}>
<Text style={styles.verifytext} onPress={()=>this.gotoSocoalLogin()}>Or Connect using your social account.</Text>
</View>
</View>
</View>
</KeyboardAvoidingView>
I am trying to get a hang of React Native, but for some reason, I can't get the button to centre horizontally in view container.
export default class LoginScreen extends Component {
static navigationOptions = {
header: null,
}
render() {
return (
<View style={styles.container}>
<MKTextField
tintColor={config.colors.accent}
floatingLabelEnabled={true}
autoFocus={true}
textInputStyle={{color: config.colors.primary, height: 32}}
placeholder="Login"
style={styles.loginInput}
onTextChange={(text) => this.setState({text})} />
<MKButton
style={styles.button}
shadowRadius={2}
shadowOffset={{width:0, height:2}}
shadowOpacity={.7}
shadowColor="black"
onPress={() => {
console.log('hi, raised button!');
}}>
<Text pointerEvents="none"
style={{color: 'white', fontWeight: 'bold', alignSelf:'center'}}>
Login
</Text>
</MKButton>
</View>
);
}
}
const styles = StyleSheet.create({
loginInput: {
width: '100%'
},
logo: {
height: '25%'
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
paddingLeft: 16,
paddingRight: 16
},
button: {
backgroundColor: config.colors.primary,
borderWidth: 0,
height: 40,
justifyContent: 'center',
alignItems: 'center',
}
});
And here's what it looks like:
Can't really tell whats going haywire here!
In your style, you need to change alignItems to alignSelf
button: {
backgroundColor: config.colors.primary,
borderWidth: 0,
height: 40,
justifyContent: 'center',
alignSelf: 'center',
}