反应原生自定义抽屉导航

问题描述 投票:1回答:1

我创建了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')

请帮忙。

react-native react-navigation
1个回答
1
投票

你从错误的地方导入了NavigationActions,你需要从react-navigation导入它

import {NavigationActions} from 'react-navigation'

© www.soinside.com 2019 - 2024. All rights reserved.