Skip to content

Instantly share code, notes, and snippets.

@ScreamZ
Last active November 2, 2019 14:16
Show Gist options
  • Save ScreamZ/59f79b6530c647c87c957e7dabffe8f6 to your computer and use it in GitHub Desktop.
Save ScreamZ/59f79b6530c647c87c957e7dabffe8f6 to your computer and use it in GitHub Desktop.
/**
* Crawl through navigation state to get route metadata.
*
* @param {*} navigationState
* @returns {*}
*/
export function getActiveRouteMetadata(navigationState) {
if (!navigationState) {
return null;
}
const route = navigationState.routes[navigationState.index];
// Dive into nested navigators as long we haven't reach current screen.
if (route.routes) {
return getActiveRouteMetadata(route);
}
return route;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment