mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-24 04:25:34 +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:
@@ -9,6 +9,7 @@ import {
|
||||
StackRouterOptions,
|
||||
StackNavigationState,
|
||||
StackActions,
|
||||
ParamListBase,
|
||||
} from '@react-navigation/native';
|
||||
import StackView from '../views/Stack/StackView';
|
||||
import type {
|
||||
@@ -36,7 +37,7 @@ function StackNavigator({
|
||||
};
|
||||
|
||||
const { state, descriptors, navigation } = useNavigationBuilder<
|
||||
StackNavigationState,
|
||||
StackNavigationState<ParamListBase>,
|
||||
StackRouterOptions,
|
||||
StackNavigationOptions,
|
||||
StackNavigationEventMap
|
||||
@@ -91,7 +92,7 @@ function StackNavigator({
|
||||
}
|
||||
|
||||
export default createNavigatorFactory<
|
||||
StackNavigationState,
|
||||
StackNavigationState<ParamListBase>,
|
||||
StackNavigationOptions,
|
||||
StackNavigationEventMap,
|
||||
typeof StackNavigator
|
||||
|
||||
@@ -52,7 +52,7 @@ export type StackNavigationProp<
|
||||
> = NavigationProp<
|
||||
ParamList,
|
||||
RouteName,
|
||||
StackNavigationState,
|
||||
StackNavigationState<ParamList>,
|
||||
StackNavigationOptions,
|
||||
StackNavigationEventMap
|
||||
> &
|
||||
@@ -250,7 +250,7 @@ export type StackHeaderProps = {
|
||||
export type StackDescriptor = Descriptor<
|
||||
ParamListBase,
|
||||
string,
|
||||
StackNavigationState,
|
||||
StackNavigationState<ParamListBase>,
|
||||
StackNavigationOptions
|
||||
>;
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@ import {
|
||||
Platform,
|
||||
} from 'react-native';
|
||||
import type { EdgeInsets } from 'react-native-safe-area-context';
|
||||
import type { Route, StackNavigationState } from '@react-navigation/native';
|
||||
import type {
|
||||
ParamListBase,
|
||||
Route,
|
||||
StackNavigationState,
|
||||
} from '@react-navigation/native';
|
||||
|
||||
import { MaybeScreenContainer, MaybeScreen } from '../Screens';
|
||||
import { getDefaultHeaderHeight } from '../Header/HeaderSegment';
|
||||
@@ -37,7 +41,7 @@ type GestureValues = {
|
||||
type Props = {
|
||||
mode: StackCardMode;
|
||||
insets: EdgeInsets;
|
||||
state: StackNavigationState;
|
||||
state: StackNavigationState<ParamListBase>;
|
||||
descriptors: StackDescriptorMap;
|
||||
routes: Route<string>[];
|
||||
openingRouteKeys: string[];
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
StackActions,
|
||||
StackNavigationState,
|
||||
Route,
|
||||
ParamListBase,
|
||||
} from '@react-navigation/native';
|
||||
|
||||
import { GestureHandlerRootView } from '../GestureHandler';
|
||||
@@ -23,7 +24,7 @@ import type {
|
||||
import HeaderShownContext from '../../utils/HeaderShownContext';
|
||||
|
||||
type Props = StackNavigationConfig & {
|
||||
state: StackNavigationState;
|
||||
state: StackNavigationState<ParamListBase>;
|
||||
navigation: StackNavigationHelpers;
|
||||
descriptors: StackDescriptorMap;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user