简体   繁体   English

如何在wix react-native-navigation中使用pop传递参数?

[英]How to pass the parameter with pop in wix react-native-navigation?

how to pass parameters in pop method.如何在pop方法中传递参数。

Requirement: There are two screens, screen 1 has two tabs like this: Address and Billing.要求:有两个屏幕,屏幕 1 有两个这样的选项卡:地址和帐单。 There are two button on each tab layout.每个选项卡布局上有两个按钮。 On click button go to screen 2 after functionality back to screen 1 but now which tab is active.单击按钮后,功能返回屏幕 1 后转到屏幕 2,但现在哪个选项卡处于活动状态。 If go to address tab so back to address tab same as billing tab.如果转到地址选项卡,则返回与帐单选项卡相同的地址选项卡。

Tell me how to do it?告诉我怎么做?

You can pass callback while pushing screen like您可以在推送屏幕时传递回调,例如

Navigation.push(this.props.componentId, {
  component: {
    name: "Your.ScreenName",
    options: {
      callback:this.yourCallBackFun
    }
  }
});

Now while pop you can call that function like现在,在 pop 时,您可以调用该函数,例如

this.props.callback();
Navigation.pop(this.props.componentId);

I think it will help you.我想它会帮助你。

Screen A:屏幕 A:

this.props.navigation.navigate('ScreenB', {func: this.func});
...
func = value => {
  console.log(value);
}

Screen B:屏幕 B:

this.props.navigation.getParam('func')();

You can call ScreenA function like this.您可以像这样调用 ScreenA 函数。

Screen1:屏幕 1:

Write your navigation function and callback function in your first screen.在第一个屏幕中编写导航函数和回调函数。 Pass callback function as a navigation parameter white pushing the screen.将回调函数作为导航参数白色推送屏幕。

const cbFunction = () => new Promise((resolve) => {
  resolve();
});

const navigation = () => {
  const { componentId } = this.props;
  Navigation.push(componentId, {
    component: {
      name: `SCREEN_NAME`,
      options: {
        cbFunction: this.cbFunction
      }
    }
  });
}

Screen2:屏幕2:

Write a function to go back to first screen.编写一个返回第一个屏幕的函数。 And call callback function from navigation parameter.并从导航参数调用回调函数。

const goBack = async () => {
  const { cbFunction, componentId } = this.props;
  await cbFunction();
  Navigation.pop(componentId);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM