import { BaseNavigationContainer , getActionFromState , getPathFromState , getStateFromPath , NavigationContainerProps , NavigationContainerRef , ParamListBase , validatePathConfig , } from '@react-navigation/core' ; import * as React from 'react' ; import LinkingContext from './LinkingContext' ; import DefaultTheme from './theming/DefaultTheme' ; import ThemeProvider from './theming/ThemeProvider' ; import type { DocumentTitleOptions , LinkingOptions , Theme } from './types' ; import useBackButton from './useBackButton' ; import useDocumentTitle from './useDocumentTitle' ; import useLinking from './useLinking' ; import useThenable from './useThenable' ; declare global { var REACT_NAVIGATION_DEVTOOLS ; } global . REACT_NAVIGATION_DEVTOOLS = new WeakMap ( ) ; type Props < ParamList extends { } > = NavigationContainerProps & { theme ? : Theme ; linking ? : LinkingOptions < ParamList > ; fallback ? : React . ReactNode ; documentTitle ? : DocumentTitleOptions ; onReady ? : ( ) => void ; } ; param props . initialState param props . onReady param props . onStateChange param props . theme param props . linking param props . fallback param props . documentTitle param props . children param props . ref function NavigationContainerInner ( { theme = DefaultTheme , linking , fallback = null , documentTitle , onReady , ... rest } , ref ? ) { const isLinkingEnabled = linking ? linking . enabled !== false : false ; if ( linking ?. config ) { validatePathConfig ( linking . config ) ; } const refContainer = React . useRef < NavigationContainerRef < ParamListBase > > ( null ) ; useBackButton ( refContainer ) ; useDocumentTitle ( refContainer , documentTitle ) ; const { getInitialState } = useLinking ( refContainer , { independent : rest . independent , enabled : isLinkingEnabled , prefixes : [ ] , ... linking , } ) ; React . useEffect ( ( ) => { if ( refContainer . current ) { REACT_NAVIGATION_DEVTOOLS . set ( refContainer . current , { get linking ( ) { return { ... linking , enabled : isLinkingEnabled , prefixes : linking ?. prefixes ?? [ ] , getStateFromPath : linking ?. getStateFromPath ?? getStateFromPath , getPathFromState : linking ?. getPathFromState ?? getPathFromState , getActionFromState : linking ?. getActionFromState ?? getActionFromState , } ; } , } ) ; } } ) ; const [ isResolved , initialState ] = useThenable ( getInitialState ) ; React . useImperativeHandle ( ref , ( ) => refContainer . current ) ; const linkingContext = React . useMemo ( ( ) => ( { options : linking } ) , [ linking ] ) ; const isReady = rest . initialState != null || ! isLinkingEnabled || isResolved ; const onReadyRef = React . useRef ( onReady ) ; React . useEffect ( ( ) => { onReadyRef . current = onReady ; } ) ; React . useEffect ( ( ) => { if ( isReady ) { onReadyRef . current ?. ( ) ; } } , [ isReady ] ) ; if ( ! isReady ) { return fallback as React . ReactElement ; } return ( < LinkingContext . Provider value = { linkingContext } > < ThemeProvider value = { theme } > < BaseNavigationContainer { ... rest } initialState = { rest . initialState == null ? initialState : rest . initialState } ref = { refContainer } / > < /ThemeProvider> < /LinkingContext.Provider>); } const NavigationContainer = React . forwardRef ( NavigationContainerInner ) as < RootParamList extends { } = ReactNavigation . RootParamList > ( props : Props < RootParamList > & { ref ? : React . Ref < NavigationContainerRef < RootParamList > > ; } ) => React . ReactElement ; export default NavigationContainer ;