mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 07:40:10 +00:00
[react-navigation] Improve test, add screen component props type checks
This commit is contained in:
9
types/react-navigation/index.d.ts
vendored
9
types/react-navigation/index.d.ts
vendored
@@ -462,6 +462,11 @@ export type LayoutEvent = {
|
||||
* END FLOW TYPEDEFINITION.JS PORT
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* BEGIN MANUAL DEFINITIONS OUTSIDE OF TYPEDEFINITION.JS
|
||||
*/
|
||||
|
||||
// From addNavigatorHelpers.js
|
||||
export function addNavigationHelpers<S>(navigation: NavigationProp<S, NavigationAction>): NavigationScreenProp<S, NavigationAction>;
|
||||
|
||||
@@ -564,6 +569,10 @@ export function TabNavigator<T>(
|
||||
export const TabBarTop: React.ComponentClass<any>;
|
||||
export const TabBarBottom: React.ComponentClass<any>;
|
||||
|
||||
/**
|
||||
* END MANUAL DEFINITIONS OUTSIDE OF TYPEDEFINITION.JS
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* BEGIN CUSTOM CONVENIENCE INTERFACES
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as React from 'react';
|
||||
import { View } from 'react-native';
|
||||
import {
|
||||
addNavigationHelpers,
|
||||
NavigationScreenProps,
|
||||
NavigationStackAction,
|
||||
NavigationTabScreenOptions,
|
||||
StackNavigator,
|
||||
@@ -10,14 +11,33 @@ import {
|
||||
TabBarBottom,
|
||||
} from 'react-navigation';
|
||||
|
||||
const Start = (
|
||||
<View />
|
||||
);
|
||||
/**
|
||||
* @class StartScreen @extends React.Component
|
||||
* @desc Simple screen component class with typed component props that should
|
||||
* receive the navigation prop from the AppNavigator.
|
||||
*/
|
||||
interface StartScreenComponentProps {
|
||||
id: number,
|
||||
s: string,
|
||||
}
|
||||
interface StartScreenProps extends NavigationScreenProps<StartScreenComponentProps> { }
|
||||
class StartScreen extends React.Component<StartScreenProps, {}> {
|
||||
render() {
|
||||
// Implicit type checks.
|
||||
const navigationStateParams: StartScreenComponentProps = this.props.navigation.state.params;
|
||||
const id = this.props.navigation.state.params.id;
|
||||
const s = this.props.navigation.state.params.s;
|
||||
|
||||
return (
|
||||
<View />
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const AppNavigator = StackNavigator({
|
||||
StartImage: {
|
||||
path: 'startImage',
|
||||
screen: Start,
|
||||
screen: StartScreen,
|
||||
},
|
||||
}, {
|
||||
initialRouteName: 'StartImage',
|
||||
|
||||
Reference in New Issue
Block a user