mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-29 21:05:29 +08:00
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import * as React from 'react';
|
|
import { CommonActions } from '@react-navigation/native';
|
|
import {
|
|
DrawerActions,
|
|
DrawerNavigationState,
|
|
} from '@react-navigation/routers';
|
|
import DrawerItem from './DrawerItem';
|
|
import {
|
|
DrawerNavigationHelpers,
|
|
DrawerDescriptorMap,
|
|
DrawerContentOptions,
|
|
} from '../types';
|
|
|
|
type Props = Omit<DrawerContentOptions, 'contentContainerStyle' | 'style'> & {
|
|
state: DrawerNavigationState;
|
|
navigation: DrawerNavigationHelpers;
|
|
descriptors: DrawerDescriptorMap;
|
|
};
|
|
|
|
/**
|
|
* Component that renders the navigation list in the drawer.
|
|
*/
|
|
export default function DrawerItemList({
|
|
state,
|
|
navigation,
|
|
descriptors,
|
|
activeTintColor,
|
|
inactiveTintColor,
|
|
activeBackgroundColor,
|
|
inactiveBackgroundColor,
|
|
itemStyle,
|
|
labelStyle,
|
|
}: Props) {
|
|
return (state.routes.map((route, i) => {
|
|
const focused = i === state.index;
|
|
const { title, drawerLabel, drawerIcon } = descriptors[route.key].options;
|
|
|
|
return (
|
|
<DrawerItem
|
|
key={route.key}
|
|
label={
|
|
drawerLabel !== undefined
|
|
? drawerLabel
|
|
: title !== undefined
|
|
? title
|
|
: route.name
|
|
}
|
|
icon={drawerIcon}
|
|
focused={focused}
|
|
activeTintColor={activeTintColor}
|
|
inactiveTintColor={inactiveTintColor}
|
|
activeBackgroundColor={activeBackgroundColor}
|
|
inactiveBackgroundColor={inactiveBackgroundColor}
|
|
labelStyle={labelStyle}
|
|
style={itemStyle}
|
|
onPress={() => {
|
|
navigation.dispatch({
|
|
...(focused
|
|
? DrawerActions.closeDrawer()
|
|
: CommonActions.navigate(route.name)),
|
|
target: state.key,
|
|
});
|
|
}}
|
|
/>
|
|
);
|
|
}) as React.ReactNode) as React.ReactElement;
|
|
}
|