ecency-mobile/src/navigation/service.js

30 lines
638 B
JavaScript
Raw Normal View History

import { NavigationActions } from 'react-navigation';
let _navigator;
2019-12-18 21:55:56 +03:00
let navigationStack = [];
2020-03-24 13:52:23 +03:00
const setTopLevelNavigator = (navigatorRef) => {
_navigator = navigatorRef;
2019-12-18 21:55:56 +03:00
if (navigationStack.length > 0) {
2020-03-24 13:52:23 +03:00
navigationStack.forEach((item) => navigate(item));
2019-12-18 21:55:56 +03:00
navigationStack = [];
}
};
2020-03-24 13:52:23 +03:00
const navigate = (navigationProps) => {
2019-12-18 21:55:56 +03:00
if (!_navigator) {
navigationStack.push(navigationProps);
} else {
_navigator.dispatch(
NavigationActions.navigate({
...navigationProps,
}),
);
}
};
// add other navigation functions that you need and export them
export { navigate, setTopLevelNavigator };