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:
Satyajit Sahoo
2020-10-23 17:06:31 +02:00
committed by GitHub
parent 8ec6c1a603
commit 7dc2f5832e
25 changed files with 144 additions and 101 deletions

View File

@@ -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

View File

@@ -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
>;

View File

@@ -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;
};

View File

@@ -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;
};