import * as React from 'react'; import { DeviceEventEmitter } from 'react-native'; import { StackActions, CommonActions, DrawerActions } from '@react-navigation/native'; import { BjTypeDrawerContent } from './utils/types'; export const navigationRef: any = React.createRef(); export function navigate(name: string, params?: object): void { let navigation: any = navigationRef.current navigation?.navigate(name, params); }; export function back() { let navigation: any = navigationRef.current navigation?.goBack(); }; export function reset(name: string, params?: object) { let navigation: any = navigationRef.current; navigation.dispatch( CommonActions.reset({ index: 1, routes: [ { name: name, params: params }, ], }) ); }; export function backUtils(backStackSize: number, handel?: Function) { const popAction = StackActions.pop(backStackSize); let navigation: any = navigationRef.current; navigation.dispatch(popAction); }; export function replace(name: string, params?: object) { const popAction = StackActions.replace(name, params); let navigation: any = navigationRef.current; navigation.dispatch(popAction); } export function openDrawer( type: BjTypeDrawerContent, data?: any, drawerWidth?: number ) { let navigation: any = navigationRef.current; DeviceEventEmitter.emit('open-drawer', { type, data, drawerWidth }) navigation.dispatch(DrawerActions.openDrawer()); } export function closeDrawer() { let navigation: any = navigationRef.current; DeviceEventEmitter.emit('close-drawer') navigation.dispatch(DrawerActions.closeDrawer()); }