首页 > 解决方案 > React Native Router Flux Actions.currentParams 道具

问题描述

这不是问题,更像是一个奇怪的问题。

一段时间以来,我一直在使用Actions.currentParamsprops 来获取当前屏幕上的对象信息或执行诸如Actions.currentParams.backAndroidHandler()访问我传递给 RNRF 的函数之类的事情Router

我在浏览线程时发现了这个技巧,但没有找到关于它的解释以及它是如何工作的。在 RNRF 的 github 上也找不到任何文档。我现在掌握的任何信息主要是基于将道具打印到控制台并从中剖析和推测答案。我想在没有关于我在代码中使用的东西的具体文档的情况下,像这样盲目地操作只会让我感到困扰。

如果您对此有任何信息,将非常感谢您提供材料阅读的链接,因为它已经困扰我好几天了!哈哈

标签: react-nativereact-native-navigationreact-native-router-flux

解决方案


我在文档中找到了一些东西。

它看起来有一些相关性。希望能帮助到你。

...
onNavigationStateChange = async (prevState, currentState, action) => {
    this.state = currentState;
    this.prevState = prevState;
    const activeState = getActiveState(this.state);
    const currentScene = activeState.routeName;
    this.currentParams = { ...activeState.params, ...action.params }; //Here!!
    this.currentScene = currentScene;
    this.prevScene = this.prevState ? getActiveState(this.prevState).routeName : null;
    if (this.currentScene !== this.prevScene) {
      // run onExit for old scene
      this.onExitHandler(this.prevScene);
      setTimeout(() => this.dispatch({
        type: ActionConst.FOCUS,
        routeName: this.currentScene,
        params: this.currentParams,
      }));
      this.onEnterHandler(currentScene);
}
...

推荐阅读