Skip to content

Instantly share code, notes, and snippets.

@andreferi3
Last active July 25, 2020 08:35
Show Gist options
  • Select an option

  • Save andreferi3/ddcca45a94f77bcfde832ff18af2cc40 to your computer and use it in GitHub Desktop.

Select an option

Save andreferi3/ddcca45a94f77bcfde832ff18af2cc40 to your computer and use it in GitHub Desktop.
import {NavigationActions, StackActions} from 'react-navigation';
let _navigator;
function setTopLevelNavigator(navigatorRef) {
_navigator = navigatorRef;
}
function navigate(routeName, params) {
_navigator.dispatch(
NavigationActions.navigate({
routeName,
params,
}),
);
}
function goBack() {
_navigator.dispatch(NavigationActions.back());
}
function replace(routeName, params) {
_navigator.dispatch(
StackActions.replace({
routeName,
params,
}),
);
}
function pop() {
_navigator.dispatch(StackActions.pop())
}
function popToTop(routeName) {
_navigator.dispatch(
StackActions.popToTop({
routeName
})
)
}
export default {
goBack,
navigate,
replace,
setTopLevelNavigator,
pop,
popToTop
};
import AppContainer from '../Navigation/AppNavigation'
import NavigationServices from '../Navigation/NavigationServices'
class RootContainer extends Component {
render() {
return (
<View style={styles.applicationView}>
<StatusBar barStyle='light-content' />
<AppContainer ref={ref => NavigationServices.setTopLevelNavigator(ref)} />
</View>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment