Skip to content

Instantly share code, notes, and snippets.

@1uokun
Created November 18, 2020 03:46
Show Gist options
  • Save 1uokun/3827e11cf07f289c8d239f4bf9817144 to your computer and use it in GitHub Desktop.
Save 1uokun/3827e11cf07f289c8d239f4bf9817144 to your computer and use it in GitHub Desktop.
NavigationService.js
import { NavigationActions } from 'react-navigation';
let _navigator;
function setTopLevelNavigator(navigatorRef) {
_navigator = navigatorRef;
}
function navigate(routeName, params, key) {
_navigator.dispatch(
NavigationActions.navigate({
routeName,
params,
key
})
);
}
function reset(routeName,params) {
const navigateAction = NavigationActions.navigate({
routeName: routeName,
params:params,
action: NavigationActions.navigate(routeName),
});
_navigator.dispatch(navigateAction);
}
function getNavigator(){
return _navigator
}
export default {
navigate,
setTopLevelNavigator,
reset,
getNavigator
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment