很显然,我是React Native的新手。我正在使用世博会。我创建了该项目,添加了一个初始屏幕(顺便说一句,看起来不错),并且向App.js中添加了一些代码来登录用户。问题是:它不会退出构建。我不知道它叫什么,但是当我在命令行(Windows)中对项目进行“ expo start”时,它按预期方式打开了选项卡,并提供了QR码。但是当前的版本号是950(并且还在不断增加),而我已经工作了45分钟。在我的iPhone上,该应用在构建时会在初始屏幕和App.js(登录屏幕)之间切换。在项目目录中,唯一的其他.js文件是Home.js和一个旧文件AppOLD.js,该文件未在任何地方引用。在/ screens中,仅存在默认文件。谢谢您能给我的帮助!
App.js
import React, { Component } from 'react'
import { View, Text, Alert, Button, TextInput, TouchableOpacity } from 'react-native';
import Home from './Home';
export default class App extends Component{
state = {
email: '',
pwd: '',
auth_token: '',
userID: ''
}
Signup = async () => {
fetch('https://myxyzwebsite.com/webuser_register', {
method: 'post',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"provider": "email",
"data": {
"email": this.state.email,
"pwd": this.state.pwd
}
})
}).then((response) => response.json())
.then((res) => {
if(typeof(res.message) != "undefined"){
Alert.alert("Error signing up", "Error: "+ res.message);
}
else{
this.setState({ auth_token: res.auth_token });
Alert.alert("Success", "You have succesfully signed up");
}
}).catch((error) => {
console.error(error);
});
}
Login = async () => {
var request = new XMLHttpRequest();
var params = "email=" + this.state.email + "&pwd=" + this.state.pwd;
request.onreadystatechange = (e) => {
if (request.readyState !== 4) {
return;
}
if (request.status === 200) {
console.log('success', request.responseText);
Alert.alert(request.responseText);
if(request.responseText != "ERROR"){
this.setState({ userID: request.responseText });
Alert.alert("Welcome", " You have succesfully logged in");
}else{
Alert.alert("Oh, no!", " There was a problem");
}
} else {
console.warn('error');
}
};
request.open('POST', 'https://myxyzsite.com/wLoginCE');
request.send(params);
}
render(){
//If auth token is not present
if(this.state.userID==''){
return(
<View style={{
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'stretch',
}}>
<TextInput
placeholder="Enter User name"
onChangeText={ TextInputValue =>
this.setState({email : TextInputValue }) }
underlineColorAndroid='transparent'
style={
{
textAlign: 'center',
width: '90%',
marginBottom: 7,
height: 40,
borderRadius: 5 ,
fontSize: 20,
}
}
/>
<TextInput
placeholder="Enter password"
onChangeText={ TextInputValue =>
this.setState({pwd: TextInputValue }) }
underlineColorAndroid='transparent'
secureTextEntry={true}
style={
{
textAlign: 'center',
width: '90%',
marginBottom: 7,
height: 40,
borderRadius: 5 ,
fontSize: 20,
}
}
/>
<TouchableOpacity onPress={this.Login.bind(this)}>
<View style={{height: 50, backgroundColor:
'#cc0066',justifyContent: 'center',
alignItems: 'center',}}>
<Text style={{
fontSize: 20,
color: '#FFFFFF',
}}>
Login </Text>
</View>
</TouchableOpacity>
<TouchableOpacity onPress={this.Signup.bind(this)}>
<View style={{height: 50, backgroundColor:
'#5da423',justifyContent: 'center',
alignItems: 'center',}}>
<Text style={{
fontSize: 20,
color: '#FFFFFF',
}}>
Signup</Text>
</View>
</TouchableOpacity>
</View>
);
}
/* Checking if the auth token is not empty directly sending the user to Home screen */
else{
return(
<Home />
);
}
}
}
的Home.js为空。