BlueWallet/NavigationService.ts

41 lines
1 KiB
TypeScript
Raw Normal View History

2024-06-03 21:27:21 -04:00
import { createNavigationContainerRef, NavigationAction, ParamListBase, StackActions } from '@react-navigation/native';
2024-01-05 13:50:07 -04:00
export const navigationRef = createNavigationContainerRef<ParamListBase>();
2024-07-23 13:44:04 -04:00
export function navigate(name: string, params?: ParamListBase, options?: { merge: boolean }) {
2024-01-05 13:50:07 -04:00
if (navigationRef.isReady()) {
2024-07-23 13:44:04 -04:00
navigationRef.current?.navigate({ name, params, merge: options?.merge });
2024-01-05 13:50:07 -04:00
}
}
export function dispatch(action: NavigationAction) {
if (navigationRef.isReady()) {
navigationRef.current?.dispatch(action);
}
}
2024-07-23 13:44:04 -04:00
export function navigateToWalletsList() {
navigate('WalletsList');
}
export function reset() {
if (navigationRef.isReady()) {
navigationRef.current?.reset({
index: 0,
2024-06-03 21:27:21 -04:00
routes: [{ name: 'UnlockWithScreen' }],
});
}
}
2024-06-03 21:27:21 -04:00
export function popToTop() {
if (navigationRef.isReady()) {
navigationRef.current?.dispatch(StackActions.popToTop());
}
}
2024-06-08 12:01:56 -04:00
export function pop() {
if (navigationRef.isReady()) {
navigationRef.current?.dispatch(StackActions.pop());
}
}