aboutsummaryrefslogtreecommitdiff
path: root/src/RootNavigation.ts
blob: 9baa78287f0a1cb344a5e0c6032ebb0345158d31 (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
26
27
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) {
    // Perform navigation if the app has mounted
    //console.log('Reached root navigation');
    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;
};