Skip to content

Instantly share code, notes, and snippets.

@jason-shen
Forked from EQuimper/isRootScreen.js
Created March 16, 2018 13:53
Show Gist options
  • Save jason-shen/ea4e953079c33d681ad8d91d8d0fa295 to your computer and use it in GitHub Desktop.
Save jason-shen/ea4e953079c33d681ad8d91d8d0fa295 to your computer and use it in GitHub Desktop.
React-Navigation for know if the root screen. Let us manages back button android.
// @flow
export function isRootScreen(navigator: {
index: ?number,
routes: ?Array<Object>,
}) {
if (navigator.index == null) {
return true;
}
if (navigator.index > 0) {
return false;
}
return (
!navigator.routes || !navigator.routes.find(route => !isRootScreen(route))
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment