android - 在 React-Native 中从 Android 上的 Drawer 引用 Navigator

标签 android react-native drawerlayout navigator

我试图从抽屉按钮推送到导航器以更改 View ,但 react 给了我以下错误:

undefined is not an object (evaluating 'this.refs['NAV'].push')

这是同时具有 Navigator 和 DrawerLayoutAndroid 的代码

    _renderScene(route, navigator) {
        if(route.id === 1){
            return <Checklist checklist={this.props.checklist}/>
        }else if(route.id === 2){
            return <Documents documents={this.props.documents}/>
        }else if(route.id === 3){
            return <Help refs={this.refs}  questions={this.props.questions} faqs={this.props.faqs}/>
        }else if(route.id === 4){
            return <Hospitals refs={this.refs}  hospitals={this.props.hospitals}/>
        }else if(route.id === 5){
            return <Profile refs={this.refs}  logout={this.props.logout} profile={this.props.profile} guarantor={this.props.guarantor}/>
        }
    },


    render() {

        console.log(this.refs)

        var navigationView = (
            <View style={{flex: 1, backgroundColor: '#fff'}}>
                <TouchableOpacity onPress={this.refs['NAV'].push({id: 2})}>
                    <Text style={{margin: 10, fontSize: 15, textAlign: 'left'}}>Checklist</Text>
                </TouchableOpacity>
                <TouchableOpacity >
                    <Text style={{margin: 10, fontSize: 15, textAlign: 'left'}}>Documents</Text>
                </TouchableOpacity>
            </View>
        );

        return (
            <DrawerLayoutAndroid
            drawerWidth={300}
            ref={'DRAWER_REF'}
            drawerPosition={DrawerLayoutAndroid.positions.Left}
            renderNavigationView={() => navigationView}>
                <Navigator
                initialRoute={{id: 1}}
                renderScene={this._renderScene}
                ref={'NAV'}
                />
            </DrawerLayoutAndroid>
        );

    }

最佳答案

问题是我需要在创建引用后调用函数。

<TouchableOpacity onPress={this._change.bind(this, 2)}>

功能:

_change(route){
    this.refs.ref1.push({id: route})
},

关于android - 在 React-Native 中从 Android 上的 Drawer 引用 Navigator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34343879/

相关文章:

android - 保存和恢复控制命令的最佳方法是什么

react-native - 不在视野范围内时暂停平面列表中的视频

json - React Native 打包器找不到 package.json

android - 具有完全透明状态栏的 DrawerLayout

java - 如何在按钮内使用静态和动态文本

android - 如何在 firebase(android 应用程序)中为用户分配角色?

android - 从 react-native-static-server : undefined is not an object (evaluating 'this.staticServer.start' ) 启动 StaticServer 时出错

java - onSwipe 事件未在 ViewPager 内触发

android - DrawerLayout 中的 EditText

android - 停止在恢复后重新创建 fragment ?