import React from 'react'; import { CommonActions, DrawerActions } from '@react-navigation/native'; import type { DrawerContentComponentProps } from '@react-navigation/drawer'; import UITideAtom from '../../UITideAtom'; import { Stack } from '@mobily/stacks'; import BoxNucleon from '../../nucleons/BoxNucleon'; import { IconNucleonProps } from '../../nucleons/IconNucleon'; import { useColorRoles } from '../../../theme/colorSystem'; import TextRoleNucleon from '../../nucleons/TextRoleNucleon'; import groupBy from './groupBy'; interface ItemDefinition { index: number; group: string; groupLabel: string; key: string; name: string; title: string; drawerLabel: string; iconName: IconNucleonProps['name']; } /** * Component that renders the navigation list in the drawer. */ export default function DrawerItemList({ state, navigation, descriptors }: DrawerContentComponentProps) { const { surface } = useColorRoles(); // const buildLink = useLinkBuilder(); // const routes = state.routes as Array<{ key: string; }> const routeDefinitions = state.routes.map( ({ key, name }: { key: string; name: string }, index: number) => ({ ...descriptors[key].options, key, name, index }) ) as Array; const renderItem = ({ key, title, drawerLabel, iconName, name, index }: ItemDefinition) => { const focused = index === state.index; return ( { navigation.dispatch({ ...(focused ? DrawerActions.closeDrawer() : CommonActions.navigate(name)), target: state.key }); }} /> ); }; const renderGroup = (name: string, defs: ItemDefinition[]) => { return ( {name === 'root' ? 'Getting Started' : name} {defs.map(renderItem)} ); }; const groups = groupBy(routeDefinitions, 'group'); return ( {Object.entries(groups).map(([name, defs]) => renderGroup(name, defs))} ); }