node_modules/@react-navigation/core/lib/module/useDescriptors.js
/**
 * Hook to create descriptor objects for the child routes.
 *
 * A descriptor object provides 3 things:
 * - Helper method to render a screen
 * - Options specified by the screen for the navigator
 * - Navigation object intended for the route
 */
Hook to create descriptor objects for the child routes.
A descriptor object provides 3 things:
- Helper method to render a screen
- Options specified by the screen for the navigator
- Navigation object intended for the route
Hook to create descriptor objects for the child routes . A descriptor object provides 3 things : - Helper method to render a screen - Options specified by the screen for the navigator - Navigation object intended for the route
function useDescriptors({
  state,
  screens,
  navigation,
  screenOptions,
  defaultScreenOptions,
  onAction,
  getState,
  setState,
  addListener,
  addKeyedListener,
  onRouteFocus,
  router,
  emitter
}) {
  const [options, setOptions] = React.useState({});
  const {
    onDispatchAction,
    onOptionsChange
  } = React.useContext(NavigationBuilderContext);
  const context = React.useMemo(() => ({
    navigation,
    onAction,
    addListener,
    addKeyedListener,
    onRouteFocus,
    onDispatchAction,
    onOptionsChange
  }), [navigation, onAction, addListener, addKeyedListener, onRouteFocus, onDispatchAction, onOptionsChange]);
  const navigations = useNavigationCache({
    state,
    getState,
    navigation,
    setOptions,
    router,
    emitter
  });
  const routes = useRouteCache(state.routes);
  return routes.reduce((acc, route, i) => {
    const screen = screens[route.name];
    const navigation = navigations[route.key];
    const routeOptions = { 
      ...(typeof screenOptions === 'object' || screenOptions == null ? screenOptions : 
      screenOptions({
        route,
        navigation
      })),
      ...(typeof screen.options === 'object' || screen.options == null ? screen.options : 
      screen.options({
        route,
        navigation
      })),
      ...options[route.key]
    };
    const mergedOptions = { ...(typeof defaultScreenOptions === 'function' ? 
      defaultScreenOptions({
        route,
        navigation,
        options: routeOptions
      }) : defaultScreenOptions),
      ...routeOptions
    };
    const clearOptions = () => setOptions(o => {
      if (route.key in o) {
        const {
          [route.key]: _,
          ...rest
        } = o;
        return rest;
      }
      return o;
    });
    acc[route.key] = {
      navigation,
      render() {
        return React.createElement(NavigationBuilderContext.Provider, {
          key: route.key,
          value: context
        }, React.createElement(NavigationContext.Provider, {
          value: navigation
        }, React.createElement(NavigationRouteContext.Provider, {
          value: route
        }, React.createElement(SceneView, {
          navigation: navigation,
          route: route,
          screen: screen,
          routeState: state.routes[i].state,
          getState: getState,
          setState: setState,
          options: mergedOptions,
          clearOptions: clearOptions
        }))));
      },
      options: mergedOptions
    };
    return acc;
  }, {});
}
function useDescriptors ( { state , screens , navigation , screenOptions , defaultScreenOptions , onAction , getState , setState , addListener , addKeyedListener , onRouteFocus , router , emitter } ) { const [ options , setOptions ] = React . useState ( { } ) ; const { onDispatchAction , onOptionsChange } = React . useContext ( NavigationBuilderContext ) ; const context = React . useMemo ( ( ) => ( { navigation , onAction , addListener , addKeyedListener , onRouteFocus , onDispatchAction , onOptionsChange } ) , [ navigation , onAction , addListener , addKeyedListener , onRouteFocus , onDispatchAction , onOptionsChange ] ) ; const navigations = useNavigationCache ( { state , getState , navigation , setOptions , router , emitter } ) ; const routes = useRouteCache ( state . routes ) ; return routes . reduce ( ( acc , route , i ) => { const screen = screens [ route . name ] ; const navigation = navigations [ route . key ] ; const routeOptions = { ... ( typeof screenOptions === 'object' || screenOptions == null ? screenOptions : screenOptions ( { route , navigation } ) ) , ... ( typeof screen . options === 'object' || screen . options == null ? screen . options : screen . options ( { route , navigation } ) ) , ... options [ route . key ] } ; const mergedOptions = { ... ( typeof defaultScreenOptions === 'function' ? defaultScreenOptions ( { route , navigation , options : routeOptions } ) : defaultScreenOptions ) , ... routeOptions } ; const clearOptions = ( ) => setOptions ( o => { if ( route . key in o ) { const { [ route . key ] : _ , ... rest } = o ; return rest ; } return o ; } ) ; acc [ route . key ] = { navigation , render ( ) { return React . createElement ( NavigationBuilderContext . Provider , { key : route . key , value : context } , React . createElement ( NavigationContext . Provider , { value : navigation } , React . createElement ( NavigationRouteContext . Provider , { value : route } , React . createElement ( SceneView , { navigation : navigation , route : route , screen : screen , routeState : state . routes [ i ] . state , getState : getState , setState : setState , options : mergedOptions , clearOptions : clearOptions } ) ) ) ) ; } , options : mergedOptions } ; return acc ; } , { } ) ; }
Hook to create descriptor objects for the child routes.
Hook to create descriptor objects for the child routes .
// The default `screenOptions` passed to the navigator // @ts-expect-error: this is a function, but typescript doesn't think so // The `options` prop passed to `Screen` elements // @ts-expect-error: this is a function, but typescript doesn't think so // The options set via `navigation.setOptions` // @ts-expect-error: ts gives incorrect error here // eslint-disable-next-line @typescript-eslint/no-unused-vars /*#__PURE__*/ /*#__PURE__*/ /*#__PURE__*/ /*#__PURE__*/