React Native错误:undefined不是对象(评估'_this2.props.navigator.push')

[英]React Native error: undefined is not an object (evaluating '_this2.props.navigator.push')


So Basically I am getting error in the title which is related to the navigator. The error pops up when I press on the Icon.

所以基本上我在标题中遇到与导航器相关的错误。按下图标时弹出错误。

What I basically want to do is make a Tab bar at the top that switches between three different views: feed, wiki, and message board

我基本上想要做的是在顶部制作一个Tab栏,在三个不同的视图之间切换:feed,wiki和留言板

Here is my index.android.js: (imports Nav)

这是我的index.android.js :(导入导航)

_renderScene(route, navigator) {
    var globalNavigatorProps = {navigator};

    switch(route.ident) {
        case "FeedView":
            return(
                <Feed
                 {...globalNavigatorProps}
                />
            );

        case "WikiView":
            return(
                <View>
                    <Text>
                        {'Hello'};
                    </Text>
                </View>
            );

        case "BoardView":
            return(
                <View>
                    <Text>
                        {'Hello'};
                    </Text>
                </View>
            );

        default:
            console.log(`Something went wrong ${route}`);
    }
}

render(){
    return(
        <View>
            <Nav />
            <Navigator
                initialRoute={{ident:"Feed"}}
                ref="appNavigator"
                renderScene={ this._renderScene }
            />

        </View>
    );
}

Here is my Nav.js:

这是我的Nav.js:

constructor(props){
    super(props);
}

render(){

    console.log(this.props.navigator);
    return(
        <View style={{flexDirection: "column"}}>
            <View style={styles.nav}>
                <Icon onPress={(event) => this.props.navigator.push({ident: "Feed"})} name="newspaper-o" size={22}/>
                <Icon name="wikipedia-w" size={22}/>
                <Icon name="comments" size={22}/>
            </View>
            <View style={styles.divider}/>
        </View>
    );
}

_changeView(type){

}

3 个解决方案

#1


0  

If you are trying to implement a tabbed view there are better ways of doing it you can always use an open source module such as this one https://github.com/skv-headless/react-native-scrollable-tab-view the developer has made it in such a way that it is easy to use and the example is good enough to get through most of the part.

如果您正在尝试实现选项卡式视图,那么有更好的方法可以使用开源模块,例如https://github.com/skv-headless/react-native-scrollable-tab-view开发人员以这样的方式使它易于使用,并且该示例足以完成大部分内容。

So instead of creating such components yourself what I would suggest is to use the modules made by the community.

因此,我建议不要自己创建这样的组件,而是使用社区制作的模块。

Hope my answer was helpful.

希望我的回答很有帮助。

#2


2  

I dont think this is the issue, but the renderScene function won't be bound to the react component.

我不认为这是问题,但renderScene函数不会绑定到react组件。

Try turning renderScene={ this._renderScene } into renderScene={ this._renderScene.bind(this) }

尝试将renderScene = {this._renderScene}转换为renderScene = {this._renderScene.bind(this)}

#3


0  

this error always occurs when you didnt bind(this),check you Icon module onPress method

当你没有绑定(这个)时总是会发生这个错误,请检查你的图标模块onPress方法


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/06/03/a1caf5ddcda1b4118cb143817edd97ab.html



 
  © 2014-2022 ITdaan.com 联系我们: