React-Navigation-Tab无法正常工作

时间:2019-12-19 19:06:46

标签: react-native react-navigation

所以我在我的本机项目中使用了反应导航。 因此,我可能无法完全解释自己到底在经历什么,所以我制作了同样的youtube视频。

https://www.youtube.com/watch?v=6xf06-O_bcI

@ 0:05因此,一旦用户单击损益表,他便导航到ProfitAndLossScreenClass。到目前为止,一切似乎都还不错。

@ 0:19现在,一旦用户单击列表中的项目之一,他就会导航到新屏幕(ProfitAndLossListItemScreenClass)。

@ 0:21当用户单击返回时,这就是问题所在,选项卡导航器似乎停止工作。尽管在导航器底部多次单击,但屏幕没有改变。

@ 0:38我们正在重新执行此过程,并遇到相同的问题。

所以这是一些看起来像这样的代码。

const getViewScreenTabNavigator = () => {
    const viewScreenNavigationRouteConfigMap = 
['ViewScreenTab1', 'ViewScreenTab2',].reduce((navigationRouteConfigMap, routeKey) => {
        navigationRouteConfigMap[routeKey] = {
            screen: (props) => {
                const { screenProps, ...propsWoScreenProps } = props;
                return <ViewScreenNav {...propsWoScreenProps} screenProps={screenProps[routeKey]} />
            },
            navigationOptions: ViewScreenNav.navigationOptions,
        };
        return navigationRouteConfigMap;
    }, {});
    return createBottomTabNavigator(
        viewScreenNavigationRouteConfigMap,
        {
            lazy: false,
            initialRouteName: 'ViewScreenTab1',
        }
    );
};

/////////////////////

Profit and Loss Screen


const ViewScreenTabNavigators = getViewScreenTabNavigator();

class ProfitAndLossScreenClass extends React.Component {

    static router = ViewScreenTabNavigators.router;

    render() {
        const { navigation, } = this.props;
        return <ViewScreenTabNavigators navigation={ navigation } screenProps = { ...screenProps } />;
    }
}

On Item Press Navigate To ProfitAndLossListItemScreenClass

/////////////////////

Profit And Loss List Item Class.

const ViewScreenTabNavigators = getViewScreenTabNavigator();

class ProfitAndLossListItemScreenClass extends React.Component {

    static router = ViewScreenTabNavigators.router;

    render() {
        const { navigation, } = this.props;
        return <ViewScreenTabNavigators navigation={ navigation } screenProps = { ...screenProps } />;
    }
}

所以我不确定是否从每个类中调用getViewScreenTabNavigator是导致此问题的原因。 我还猜想'ViewScreenTab1', 'ViewScreenTab2',屏幕键是反复创建的,所以有问题吗?。

在此方面的任何帮助将不胜感激。

阿莫尔

0 个答案:

没有答案