我尝试了React Native Tab View。路线导航在renderScene组件中不起作用

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

我已经使用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>
        );
    }
}
react-native navigation tabview
1个回答
0
投票

我也遇到过同样的问题,我可以使用以下方式在子选项卡中获得导航对象:>

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

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