我创建了Custom DrawerNavigator。一切都到位了。但是,我无法在屏幕之间导航。我不知道如何导航,所以我按照说明进行操作 https://github.com/kakulgupta/CustomDrawer/tree/master/app。但这没有任何帮助
import React,{Component} from 'react'
import {Text,View,StyleSheet,Image,NavigationActions} from 'react-native'
import {Icon,Container,Header,Content,Left} from 'native-base'
export default class Head extends Component{
navigateToScreen = (route) =>()=>{
const navAction = NavigationActions.navigate({
routeName:route
})
this.props.navigation.dispatch(navAction)
}
render(){
return (
<View>
<View style={styles.image}>
<Image
style={{height:200,
width:90,
marginLeft:'30%',
marginRight:'30%',
marginTop:'15%',
alignContent:'center',
alignItems:'center'
}}
source={require('./../images/logo.png')}
/>
</View>
<View style={styles.menu}>
<View style={styles.box} >
<Icon name="person" />
<Text style={styles.boxText} onPress={this.navigateToScreen("Login")}>Login</Text>
</View>
</View>
</View>
)
}
}
我的app.js是
import React, {Component} from 'react';
import {DrawerNavigator} from 'react-navigation'
import Login from './src/Login/login.js'
export default class App extends Component{
render(){
return(
<Links />
)
}
}
const Links = DrawerNavigator({
Login:{screen:Login},
},{contentComponent:props => <Slider {...props}/>
})
的package.json
"dependencies": {
"native-base": "^2.8.0",
"react": "^16.4.1",
"react-native": "^0.55.4",
"react-navigation": "^2.12.1"
},
错误是
undefined不是对象(评估'_reactNative.NavigationActions.navigate')
请帮忙。
你从错误的地方导入了NavigationActions
,你需要从react-navigation
导入它
import {NavigationActions} from 'react-navigation'