我遵循了本文档http://facebook.github.io/react-native/docs/navigation,我想做一个简单的启动画面之类的事情。屏幕将从图像屏幕导航并进入登录屏幕
现在,我执行类似npm install --save react-navigation
的操作,并添加其他库并导入它们。
现在在我的代码中,我将其命名为Index.js
/**
* @format
*/
import {AppRegistry} from 'react-native';
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
//import App from './components/Splashscreen';
import Splashscreen from './components/Splashscreen';
import Home from './components/Home'
import {name as appName} from './app.json';
const Navigation = StackNavigator({
Home:{
screen:Home,
},
Login:{
screen:Home
}
})
AppRegistry.registerComponent(appName, () => App);
这就是启动画面
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, Image } from 'react-native';
export default class Home extends Component{
componentWillMount()
{
setInterval(() => {
this.props.navigation.navigate('Home')
}, 4000);
}
render(){
return(
<View style={styles.container}>
<Image
source={{uri: 'http://peopleweb.freeasphost.net/d4b0e7d1-6c0e-4e48-a4cb-0f1c26af81fe_200x200.png'}}
style={styles.logo} />
</View>
);
}
}
const styles = StyleSheet.create({
container:{
flex: 1,
justifyContent :"center",
alignItems:"center"
},
logo:{
width:150,
height:150
},
});
这是从登录屏幕重定向的主要登录页面
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
export default class Home extends Component{
render(){
return(
<View style={styles.container}>
<TextInput
placeholder = "Username"
style={styles.input}
/>
<TextInput
placeholder = "Password"
style={styles.input}
/>
<TouchableOpacity style={styles.button} onPress={this.login}>
<Text style={styles.loginbtn}> Login </Text>
<TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container:{
flex: 1,
justifyContent :"center",
alignItems:"center"
},
input:{
width:200,
margin:10
},
button:{
width:200,
padding:10,
backgroundColor:#009999,
alignItems: 'Center'
},
loginbtn:{
color:#ffff
}
});
现在,它不会重定向,而是完全静止的白色屏幕。我该怎么办我想念的?
我遇到此错误:加载依赖关系图已完成。
错误:捆绑失败:错误:无法从react-navigation
解析模块index.js
:在项目中找不到反应导航。