import { CommonActions, DrawerActions, type DrawerNavigationState, type ParamListBase, useLinkBuilder, } from '@react-navigation/native'; import * as React from 'react'; import type { DrawerDescriptorMap, DrawerNavigationHelpers } from '../types'; import { DrawerItem } from './DrawerItem'; type Props = { state: DrawerNavigationState; navigation: DrawerNavigationHelpers; descriptors: DrawerDescriptorMap; }; /** * Component that renders the navigation list in the drawer. */ export function DrawerItemList({ state, navigation, descriptors }: Props) { const { buildHref } = useLinkBuilder(); const focusedRoute = state.routes[state.index]; const focusedDescriptor = descriptors[focusedRoute.key]; const focusedOptions = focusedDescriptor.options; const { drawerActiveTintColor, drawerInactiveTintColor, drawerActiveBackgroundColor, drawerInactiveBackgroundColor, } = focusedOptions; return state.routes.map((route, i) => { const focused = i === state.index; const onPress = () => { const event = navigation.emit({ type: 'drawerItemPress', target: route.key, canPreventDefault: true, }); if (!event.defaultPrevented) { navigation.dispatch({ ...(focused ? DrawerActions.closeDrawer() : CommonActions.navigate(route.name, route.params)), target: state.key, }); } }; const { title, drawerLabel, drawerIcon, drawerLabelStyle, drawerItemStyle, drawerItemTestID, drawerAllowFontScaling, } = descriptors[route.key].options; return ( ); }) as React.ReactNode as React.ReactElement; }