mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-29 12:55:21 +08:00
feat: improve types for navigation state (#8980)
The commit improves the navigation state object to have more specific types. e.g. The `routeNames` array will now have proper type instead of `string[]`
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
DrawerNavigationState,
|
||||
DrawerRouterOptions,
|
||||
DrawerRouter,
|
||||
ParamListBase,
|
||||
} from '@react-navigation/native';
|
||||
|
||||
import DrawerView from '../views/DrawerView';
|
||||
@@ -28,7 +29,7 @@ function DrawerNavigator({
|
||||
...rest
|
||||
}: Props) {
|
||||
const { state, descriptors, navigation } = useNavigationBuilder<
|
||||
DrawerNavigationState,
|
||||
DrawerNavigationState<ParamListBase>,
|
||||
DrawerRouterOptions,
|
||||
DrawerNavigationOptions,
|
||||
DrawerNavigationEventMap
|
||||
@@ -51,7 +52,7 @@ function DrawerNavigator({
|
||||
}
|
||||
|
||||
export default createNavigatorFactory<
|
||||
DrawerNavigationState,
|
||||
DrawerNavigationState<ParamListBase>,
|
||||
DrawerNavigationOptions,
|
||||
DrawerNavigationEventMap,
|
||||
typeof DrawerNavigator
|
||||
|
||||
@@ -136,7 +136,7 @@ export type DrawerNavigationOptions = {
|
||||
};
|
||||
|
||||
export type DrawerContentComponentProps<T = DrawerContentOptions> = T & {
|
||||
state: DrawerNavigationState;
|
||||
state: DrawerNavigationState<ParamListBase>;
|
||||
navigation: DrawerNavigationHelpers;
|
||||
descriptors: DrawerDescriptorMap;
|
||||
/**
|
||||
@@ -203,7 +203,7 @@ export type DrawerNavigationProp<
|
||||
> = NavigationProp<
|
||||
ParamList,
|
||||
RouteName,
|
||||
DrawerNavigationState,
|
||||
DrawerNavigationState<ParamList>,
|
||||
DrawerNavigationOptions,
|
||||
DrawerNavigationEventMap
|
||||
> &
|
||||
@@ -220,7 +220,7 @@ export type DrawerScreenProps<
|
||||
export type DrawerDescriptor = Descriptor<
|
||||
ParamListBase,
|
||||
string,
|
||||
DrawerNavigationState,
|
||||
DrawerNavigationState<ParamListBase>,
|
||||
DrawerNavigationOptions
|
||||
>;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
CommonActions,
|
||||
DrawerActions,
|
||||
DrawerNavigationState,
|
||||
ParamListBase,
|
||||
useLinkBuilder,
|
||||
} from '@react-navigation/native';
|
||||
import DrawerItem from './DrawerItem';
|
||||
@@ -13,7 +14,7 @@ import type {
|
||||
} from '../types';
|
||||
|
||||
type Props = Omit<DrawerContentOptions, 'contentContainerStyle' | 'style'> & {
|
||||
state: DrawerNavigationState;
|
||||
state: DrawerNavigationState<ParamListBase>;
|
||||
navigation: DrawerNavigationHelpers;
|
||||
descriptors: DrawerDescriptorMap;
|
||||
};
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
DrawerNavigationState,
|
||||
DrawerActions,
|
||||
useTheme,
|
||||
ParamListBase,
|
||||
} from '@react-navigation/native';
|
||||
|
||||
import { GestureHandlerRootView } from './GestureHandler';
|
||||
@@ -31,7 +32,7 @@ import type {
|
||||
} from '../types';
|
||||
|
||||
type Props = DrawerNavigationConfig & {
|
||||
state: DrawerNavigationState;
|
||||
state: DrawerNavigationState<ParamListBase>;
|
||||
navigation: DrawerNavigationHelpers;
|
||||
descriptors: DrawerDescriptorMap;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user