mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
Merge pull request #24632 from doomsower/react-nav-patch2
[react-navigation] Stronger definitions for screen params
This commit is contained in:
Vendored
+9
-8
@@ -173,13 +173,14 @@ export type NavigationScreenConfig<Options> =
|
||||
}) => Options);
|
||||
|
||||
export type NavigationComponent =
|
||||
NavigationScreenComponent<any, any>
|
||||
NavigationScreenComponent<any, any, any>
|
||||
| NavigationNavigator<any, any, any>;
|
||||
|
||||
export type NavigationScreenComponent<
|
||||
Params = NavigationParams,
|
||||
Options = {},
|
||||
Props = {}
|
||||
> = React.ComponentType<NavigationNavigatorProps<Options, NavigationState> & Props> &
|
||||
> = React.ComponentType<NavigationScreenProps<Params, Options> & Props> &
|
||||
{ navigationOptions?: NavigationScreenConfig<Options> };
|
||||
|
||||
export type NavigationNavigator<
|
||||
@@ -429,17 +430,17 @@ export interface NavigationScreenProp<S, P = NavigationParams> {
|
||||
goBack: (routeKey?: string | null) => boolean;
|
||||
navigate(options: {
|
||||
routeName: string;
|
||||
params?: P;
|
||||
params?: NavigationParams;
|
||||
action?: NavigationAction;
|
||||
key?: string;
|
||||
}): boolean;
|
||||
navigate(
|
||||
routeNameOrOptions: string,
|
||||
params?: P,
|
||||
params?: NavigationParams,
|
||||
action?: NavigationAction,
|
||||
): boolean;
|
||||
getParam: <T extends keyof P>(param: T, fallback?: P[T]) => P[T];
|
||||
setParams: (newParams: NavigationParams) => boolean;
|
||||
setParams: (newParams: P) => boolean;
|
||||
addListener: (
|
||||
eventName: string,
|
||||
callback: NavigationEventCallback
|
||||
@@ -859,10 +860,10 @@ export function createNavigationContainer(
|
||||
* BEGIN CUSTOM CONVENIENCE INTERFACES
|
||||
*/
|
||||
|
||||
export interface NavigationScreenProps<Params = NavigationParams> {
|
||||
navigation: NavigationScreenProp<NavigationRoute<Params>>;
|
||||
export interface NavigationScreenProps<Params = NavigationParams, Options = any> {
|
||||
navigation: NavigationScreenProp<NavigationRoute<Params>, Params>;
|
||||
screenProps?: { [key: string]: any };
|
||||
navigationOptions?: NavigationScreenConfig<any>;
|
||||
navigationOptions?: NavigationScreenConfig<Options>;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -134,7 +134,12 @@ export const AppNavigator = StackNavigator(
|
||||
},
|
||||
);
|
||||
|
||||
const StatelessScreen: NavigationScreenComponent = () => <View />;
|
||||
interface StatelessScreenParams {
|
||||
testID: string;
|
||||
}
|
||||
|
||||
const StatelessScreen: NavigationScreenComponent<StatelessScreenParams> = (props) =>
|
||||
<View testID={props.navigation.getParam('testID', 'fallback')}/>;
|
||||
|
||||
StatelessScreen.navigationOptions = { title: 'Stateless' };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user