Last active
November 8, 2021 19:48
-
-
Save jim-at-jibba/47c893ba9fbcf21f4c60cd5bf9e76595 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* How pendo document it | |
*/ | |
<SafeAreaProvider> | |
<NavigationContainer | |
theme={MyTheme} | |
ref={navigationRef} | |
linking={linking} | |
onReady={props.onReady} | |
onStateChange={props.onStateChange}> | |
<Routes /> | |
</NavigationContainer> | |
</SafeAreaProvider> | |
/** | |
* How we need to do it | |
*/ | |
<SafeAreaProvider> | |
<NavigationContainer | |
theme={MyTheme} | |
ref={navigationRef} | |
linking={linking} | |
onReady={() => { | |
routeNameRef.current = navigationRef.getCurrentRoute().name; | |
return props.onReady() | |
}} | |
onStateChange={() => ( | |
const previousRouteName = routeNameRef.current; | |
const currentRouteName = navigationRef.getCurrentRoute().name; | |
onNavigationStateChange(currentRouteName, previousRouteName); | |
routeNameRef.current = currentRouteName; | |
return props.onStateChange() | |
)} | |
> | |
<Routes /> | |
</NavigationContainer> | |
</SafeAreaProvider> |
@jim-at-jibba you need to pass the state to the
props.onStateChange()
onStateChange={() => (
const previousRouteName = routeNameRef.current;
const currentRouteName = navigationRef.getCurrentRoute().name;
onNavigationStateChange(currentRouteName, previousRouteName);
routeNameRef.current = currentRouteName;
const state = navigationRef.current.getRootState()
return props.onStateChange(state)
)}````
@MikePendo Hey bud,
Thanks for that. Things seem to work now.
It might be good to add this to the docs.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I dont understand why
props.onsStateChange
andprops.onStateChage
dont work when called inside an anonymous function.