React Native Router Flux Actions.currentParams props

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

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

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

我在浏览线程时发现了这个技巧,但是没有找到关于它以及它如何工作的解释。在RNRF的github上也找不到任何文档。我现在得到的任何信息都主要基于打印道具进行控制台以及剖析和推测答案。我猜想我像这样盲目地操作,而没有关于我在代码中使用的东西的具体文档,这很烦人。

如果您有任何相关信息,将非常感谢您提供资料阅读的链接,因为它已经困扰了我DAYS!哈哈

react-native react-native-navigation react-native-router-flux
1个回答
0
投票

我在document中找到了东西。

看起来有些相关。希望对您有所帮助。

...
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);
}
...
© www.soinside.com 2019 - 2024. All rights reserved.