【问题标题】:I tried React Native Tab View. Route navigation not working in renderScene components我尝试了 React Native 选项卡视图。路线导航在 renderScene 组件中不起作用
【发布时间】:2020-02-25 21:35:30
【问题描述】:

我已经使用 React native 实现了一个标签视图,但是我需要从子屏幕导航到另一个父屏幕。

查看此图片:My UI

在上图中,当我单击“下一步”按钮时,我可以在选项卡之间导航,但我需要导航到另一个主视图。我该怎么做?

找到下面的代码:

MainScreen.js

class MainTabView extends Component {
    state ={
      index: 0,
      routes: [
          { key: 'offers', title: 'Offers'},
          { key: 'ternding', title: 'Trending'},
          { key: 'retails', title: 'Retails'}
      ]
    }
    
    _updateRoute(newIdx) {
        this.setState({index: newIdx})
        }

    render() {
        return(
            <View style={styles.scene}>
                <Button title={'Main'} onPress={() => { this.props.navigation.navigate('Splash')}}></Button>
                 <TabView
                    navigationState={this.state}
                    renderScene={SceneMap({
                        offers: Offers,
                        ternding: Retails,
                        retails: Trending,
                    })}
                    onIndexChange={index => this.setState({ index })}
                    initialLayout={{ width: Dimensions.get('window').width }}
                    indicatorStyle={{ backgroundColor: 'pink' }}
                    useNativeDriver
                />  
            </View>
        )
    }
}

Offers.js

class Offers extends Component {

    state = {
        title: 'Next Screen'
    }
    componentDidMount() {

    }
    render() {
        return (
            <View style={styles.background}>
                <Button title={'Next'} onPress={() => {
                    this.props.navigation.navigate('Splash')
                }}></Button>
            </View>
        );
    }
}

【问题讨论】:

  • 嗨 Ravi,欢迎来到 stackoverflow!你应该看看how to ask 一个好问题。特别是,几乎总是有必要在您的问题中包含源代码,以便我们可以看到您尝试帮助获得答案的内容。
  • 嗨 Robsiemb,我已经更新了我的代码。所以请检查并告诉我解决方案。

标签: react-native navigation tabview


【解决方案1】:

我遇到了同样的问题,我能够使用

在子标签中获取导航对象
import { withNavigation } from 'react-navigation';

https://reactnavigation.org/docs/en/with-navigation.html 引用自本期https://github.com/react-native-community/react-native-tab-view/issues/907

【讨论】:

    猜你喜欢
    • 2018-04-03
    • 1970-01-01
    • 1970-01-01
    • 2018-05-05
    • 1970-01-01
    • 1970-01-01
    • 2018-08-26
    • 2022-01-15
    • 1970-01-01
    相关资源
    最近更新 更多