import type { ParamListBase, Route } from '@react-navigation/routers'; import * as React from 'react'; import { NavigationContext } from './NavigationContext'; import type { NavigationProp } from './types'; import { FocusedRouteKeyContext, IsFocusedContext } from './useIsFocused'; /** * Context which holds the route prop for a screen. */ export const NavigationRouteContext = React.createContext< Route | undefined >(undefined); type Props = { route: Route; navigation: NavigationProp; children: React.ReactNode; }; /** * Component to provide the navigation and route contexts to its children. */ export const NamedRouteContextListContext = React.createContext< Record>> | undefined >(undefined); export function NavigationProvider({ route, navigation, children }: Props) { const parentIsFocused = React.useContext(IsFocusedContext); const focusedRouteKey = React.useContext(FocusedRouteKeyContext); // Mark route as focused only if: // - It doesn't have a parent navigator // - Parent navigator is focused const isFocused = parentIsFocused == null || parentIsFocused ? focusedRouteKey === route.key : false; return ( {children} ); }