blob: bd2ba20defdddd65463c9803cf7714921516b65b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import {NavigationContainerRef} from '@react-navigation/native';
import React from 'react';
export const navigationRef: React.RefObject<NavigationContainerRef> =
React.createRef();
export function navigate(name: string) {
if (navigationRef.current) {
navigationRef.current.navigate(name);
} else {
// TODO: Decide what to do if the app hasn't mounted
// Ignore this, or add these actions to a queue you can call later
}
}
export const getActiveRouteName = (state) => {
const route = state.routes[state?.index || 0];
if (route.state) {
// Dive into nested navigators
return getActiveRouteName(route.state);
}
return route.name;
};
|