[英]Update InitialRouteStack in React Native Navigator
I have got a Navigator that has to handle 4 different views, which should be on the same level. 我有一个Navigator,它必须处理4个不同的视图,这些视图应该在同一级别上。 I am loading them in the InitialRouteStack and whenever I need one of them, I am calling jumpTo(route) and getting what I want.
我将它们加载到InitialRouteStack中,每当我需要其中之一时,就调用jumpTo(route)并获得所需的内容。
However, when I change a value in one of the views, I do have a callback that updates the state of the given value where the Navigator is placed. 但是,当我在其中一个视图中更改值时,确实有一个回调,该回调可更新给定值的位置(将其放置在导航器中)。 I thought this would re-render the whole thing and update the props within the RouteStack.
我认为这将重新渲染整个事物并更新RouteStack中的道具。
This is not happening. 这没有发生。 I have also tried to run a forceUpdate() on the Navigator, but the props in each component are not updating.
我也尝试过在Navigator上运行forceUpdate(),但是每个组件中的道具都没有更新。 I keep having the values I passed when Navigator was rendered the first time.
第一次呈现Navigator时,我一直保持传递的值。
Is there a way to solve this? 有办法解决吗? I really don't want to use replace(route) because re-rendering each component every single time would be silly.
我真的不想使用replace(route),因为每一次重新渲染每个组件都是很愚蠢的。
Edit I have looked at immediatelyResetRouteStack and replacedAtIndex, but they don't seem viable. 编辑我已经看了当下的ResetRouteStack和replacedAtIndex,但是它们似乎不可行。 The first one reset the whole thing, the second one replaces at Index, while, in theory, I should update the props passed to each component in the stack.
第一个重置整个对象,第二个替换在Index处,而从理论上讲,我应该更新传递给堆栈中每个组件的props。
I had a similar question . 我有一个类似的问题 。 There you can find possible solutions.
在那里您可以找到可能的解决方案。
Eventually I used redux
to handle all the data flow, which solved the issue for me. 最终,我使用
redux
来处理所有数据流,这为我解决了这个问题。 There I connected every single smart component , at least the once included by a NavigatorIOS-Route, to the store. 在这里,我将每个智能组件 (至少是NavigatorIOS-Route包含的组件)连接到了商店。 By that I completely bypass NavigatorIOS, together with
passProps
. 这样,我就完全绕过了NavigatorIOS以及
passProps
。
Also there exists an issue for react-native about rerendering a component inside NavigatorIOS, when passProps changed. 当passProps更改时,在本地重新呈现组件也存在反应问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.