import { observable , action } from 'mobx' ; import { NavigationScreenProp , NavigationState , NavigationContainerComponent , NavigationAction , NavigationParams , NavigationNavigateAction } from 'react-navigation' ; export default class Navigation { @ observable . ref navigation : NavigationScreenProp < NavigationState > | undefined ; @ action . bound createRef ( ref ) { if ( ref ) { this . navigation = ref . _navigation ; } } @ action . bound dispatch ( action ) { if ( ! this . navigation ) { throw new Error ( 'please create navigation refs first.' ) ; } this . navigation . dispatch ( action ) ; } @ action . bound getParam ( paramName , fallback ? ) { if ( ! this . navigation ) { throw new Error ( 'please create navigation refs first.' ) ; } this . navigation . getParam ( paramName , fallback ) ; } @ action . bound setParams ( newParams ) { if ( ! this . navigation ) { throw new Error ( 'please create navigation refs first.' ) ; } this . navigation . setParams ( newParams ) ; } @ action . bound navigate ( routeNameOrOptions , params ? , action ? ) { if ( ! this . navigation ) { throw new Error ( 'please create navigation refs first.' ) ; } this . navigation . navigate ( routeNameOrOptions as string , params , action ) ; } @ action . bound push ( routeName , params ? , action ? ) { if ( ! this . navigation ) { throw new Error ( 'please create navigation refs first.' ) ; } this . navigation . push ( routeName , params , action as NavigationNavigateAction ) ; } @ action . bound replace ( routeName , params ? , action ? ) { if ( ! this . navigation ) { throw new Error ( 'please create navigation refs first.' ) ; } this . navigation . replace ( routeName , params , action as NavigationNavigateAction ) ; } @ action . bound goBack ( routeKey ? ) { if ( ! this . navigation ) { throw new Error ( 'please create navigation refs first.' ) ; } this . navigation . goBack ( routeKey ) ; } @ action . bound pop ( n ? , params ? ) { if ( ! this . navigation ) { throw new Error ( 'please create navigation refs first.' ) ; } this . navigation . pop ( n , params ) ; } @ action . bound popToTop ( params ? ) { if ( ! this . navigation ) { throw new Error ( 'please create navigation refs first.' ) ; } this . navigation . popToTop ( params ) ; } }