无法在嵌套路由React Native中设置参数

时间:2018-07-20 09:55:42

标签: react-native react-navigation

堆栈路由器中的屏幕:

const componentDidMount = props => {
const { navigation } = props;
handleExperienceTabFocus = () => {
    return Alert.alert(
        // Shows up the alert without redirecting anywhere
        "Confirmation required",
        "Do you really want to logout?",
        [{ text: "Accept" }, { text: "Cancel" }]
    );
};
InteractionManager.runAfterInteractions(() => {
    navigation.setParams({
        onExperienceTabFocus: this.handleExperienceTabFocus
    });
});
};

const methods = {
componentDidMount
};

const LeTueEsperienzeLavorative = props => {
const { navigation } = props;
console.log("props in LeTueEsperienzeLavorative", props);

return (<View></View>)
}
export default lifecycle(methods)(LeTueEsperienzeLavorative);

我将堆栈路由器附加在选项卡导航器的一个选项卡中

  tabBarOnPress: (scene, jumpToIndex) => {
        const { params } = navigation.state;
  console.log("Scene", scene, routeName);
  console.log("Params", params);
        const {
            scene: {
                index,
                route: { routeName }
            }
        } = scene;

        if (routeName == "Richiesta") {
            scene.jumpToIndex(index);
        } 
        else if (routeName == "Disponibilità") {
            scene.jumpToIndex(index);
        } 
        else if (routeName == "Esperienza") {
          scene.jumpToIndex(index);
          params.onExperienceTabFocus();
        } 
        else if (routeName == "Profilo") {
            scene.jumpToIndex(index);
            params.onProfileTabFocus();
        }       
    }

我正在为“ Esperienza”路线设置参数,但是无法在tabBarOnPress方法中访问它。

反应导航版本:1.0.0-beta.21 React Native版本:0.51.0

我们非常感谢您的帮助。预先感谢。

0 个答案:

没有答案