Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

rootNavigation.ts

24 lines819 Bytes

1import {
2 createNavigationContainerRef,
3 type NavigationContainerRef,
4} from "@react-navigation/native";
5​
6/**
7 * The app's single navigation container. Work that outlives a screen (a draft
8 * route's branch checkout) navigates through it.
9 */
10export const rootNavigationRef = createNavigationContainerRef<ReactNavigation.RootParamList>();
11​
12/**
13 * Ref callback for the container. Android activity replacement mounts the new
14 * root before the old one unmounts, so the old container must not clear the
15 * ref the new one already owns.
16 */
17export function attachRootNavigation(
18 navigation: NavigationContainerRef<ReactNavigation.RootParamList> | null,
19): () => void {
20 rootNavigationRef.current = navigation;
21 return () => {
22 if (rootNavigationRef.current === navigation) rootNavigationRef.current = null;
23 };