Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用react native scrollable tab view从其他组件切换选项卡_Javascript_Reactjs_React Native - Fatal编程技术网

Javascript 如何使用react native scrollable tab view从其他组件切换选项卡

Javascript 如何使用react native scrollable tab view从其他组件切换选项卡,javascript,reactjs,react-native,Javascript,Reactjs,React Native,第二天使用React-Native,所以我不知道我在做什么,但如何使用React-Native可滚动选项卡视图从另一个组件中切换选项卡 我在一个按钮页面中有一个菜单按钮,我正试图使用onPress切换选项卡。但是,当我点击它时,我得到: undefined is not an object (evaluating 'this.props.tabView.goToPage') 我得到的是这个 导出默认类主扩展组件{ render(){ 返回( {this.tabView=tabView}}>

第二天使用React-Native,所以我不知道我在做什么,但如何使用React-Native可滚动选项卡视图从另一个组件中切换选项卡

我在一个按钮页面中有一个菜单按钮,我正试图使用onPress切换选项卡。但是,当我点击它时,我得到:

undefined is not an object (evaluating 'this.props.tabView.goToPage')
我得到的是这个

导出默认类主扩展组件{
render(){
返回(
{this.tabView=tabView}}>
)
}

}
您不需要一直向下查看tabview ref。只用

export default class MenuButton extends Component {

render() {
    return (
        <Indicator
            position='left top'
            value='3'
            type='warning'>
            <TouchableHighlight
            onPress={() => this.props.onPress && this.props.onPress()}
            underlayColor='#ed8600'
            style={styles.touchable}>
                <Image source={require('./resources/menuicon.png')} style={styles.image} />
            </TouchableHighlight>
        </Indicator>
    )
}}

export default class ButtonPage extends Component {
render() {
    return (
    <View style={styles.container}>

        <View style={styles.buttonsContainer}>
            <HangoutsButton/>
            <View style={styles.spacer}/>
            <MenuButton onPress={ () => this.props.goToPage && this.props.goToPage() }/>
        </View>

    </View>)
}}
导出默认类菜单按钮扩展组件{
render(){
返回(
this.props.onPress&&this.props.onPress()}
参考底色='#ed8600'
style={style.touchable}>
)
}}
导出默认类按钮页面扩展组件{
render(){
返回(
this.props.goToPage&&this.props.goToPage()}/>
)
}}
最后

export default class Home extends Component {
  goToPage(pageId) {
    this.tabView.goToPage(pageId);
  }
  render() {
    return (
      <View style={{flex: 1}}>
        <StatusBar
        barStyle='light-content'/>
        <ScrollableTabView initialPage={1} renderTabBar={false}
        ref={(tabView) => { this.tabView = tabView}}>
          <FriendsPage tabView={this.tabView} tabLabel="Friends" />
          <ButtonPage tabView={this.tabView} tabLabel="Button" goToPage={ () => this.goToPage(1) } />
          <HangoutsPage tabView={this.tabView} tabLabel="Hangouts" />
        </ScrollableTabView>
      </View>
    )
  }
}
导出默认类主扩展组件{
goToPage(pageId){
this.tabView.goToPage(pageId);
}
render(){
返回(
{this.tabView=tabView}}>
this.goToPage(1)}/>
)
}
}