Skip to content

Instantly share code, notes, and snippets.

@jim-at-jibba
Last active November 8, 2021 19:48
Show Gist options
  • Save jim-at-jibba/47c893ba9fbcf21f4c60cd5bf9e76595 to your computer and use it in GitHub Desktop.
Save jim-at-jibba/47c893ba9fbcf21f4c60cd5bf9e76595 to your computer and use it in GitHub Desktop.
/**
* 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
Copy link
Author

I dont understand why props.onsStateChange and props.onStateChage dont work when called inside an anonymous function.

@MikePendo
Copy link

@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)
    )}````

@jim-at-jibba
Copy link
Author

@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