I want to access the full navigation state in a screen without connecting to Redux.
我想在屏幕*问完整的导航状态而不连接到Redux。
I know I have the prop navigation
which contains a state
key in my screen but there is only the key
and the routeName
in it. I want the full state with the routes
hierarchy and so on (the same react-navigation
stores internally and gives us in navigationOptions
).
我知道我的道具导航在我的屏幕中包含一个状态键,但它只有键和routeName。我想要完整的状态与路由层次结构等(内部相同的react-navigation存储,并在navigationOptions中提供)。
Is it possible?
可能吗?
1 个解决方案
#1
0
You can track the navigation stack and screens with onNavigationStateChange
prop. You can find more information here in the docs.
您可以使用onNavigationStateChange prop跟踪导航堆栈和屏幕。您可以在文档中找到更多信息。
Example
例
export default () => (
<AppNavigator
onNavigationStateChange={(prevState, currentState) => {
const currentScreen = getCurrentRouteName(currentState);
const prevScreen = getCurrentRouteName(prevState);
if (prevScreen !== currentScreen) {
// the line below uses the Google Analytics tracker
// change the tracker here to use other Mobile analytics SDK.
tracker.trackScreenView(currentScreen);
}
}}
/>
);
#1
0
You can track the navigation stack and screens with onNavigationStateChange
prop. You can find more information here in the docs.
您可以使用onNavigationStateChange prop跟踪导航堆栈和屏幕。您可以在文档中找到更多信息。
Example
例
export default () => (
<AppNavigator
onNavigationStateChange={(prevState, currentState) => {
const currentScreen = getCurrentRouteName(currentState);
const prevScreen = getCurrentRouteName(prevState);
if (prevScreen !== currentScreen) {
// the line below uses the Google Analytics tracker
// change the tracker here to use other Mobile analytics SDK.
tracker.trackScreenView(currentScreen);
}
}}
/>
);