From e34616fd3c94b0b4a1fc8a13c2becd801cdd97ba Mon Sep 17 00:00:00 2001 From: abrahambotros Date: Wed, 14 Jun 2017 22:58:27 -0700 Subject: [PATCH] [react-navigation] Improve test, add screen component props type checks --- types/react-navigation/index.d.ts | 9 ++++++ .../react-navigation-tests.tsx | 28 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/types/react-navigation/index.d.ts b/types/react-navigation/index.d.ts index 82de567263..ffd543f261 100644 --- a/types/react-navigation/index.d.ts +++ b/types/react-navigation/index.d.ts @@ -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(navigation: NavigationProp): NavigationScreenProp; @@ -564,6 +569,10 @@ export function TabNavigator( export const TabBarTop: React.ComponentClass; export const TabBarBottom: React.ComponentClass; +/** + * END MANUAL DEFINITIONS OUTSIDE OF TYPEDEFINITION.JS + */ + /** * BEGIN CUSTOM CONVENIENCE INTERFACES diff --git a/types/react-navigation/react-navigation-tests.tsx b/types/react-navigation/react-navigation-tests.tsx index 884d57e4f0..b95092d5e0 100644 --- a/types/react-navigation/react-navigation-tests.tsx +++ b/types/react-navigation/react-navigation-tests.tsx @@ -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 = ( - -); +/** + * @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 { } +class StartScreen extends React.Component { + 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 ( + + ); + } +} export const AppNavigator = StackNavigator({ StartImage: { path: 'startImage', - screen: Start, + screen: StartScreen, }, }, { initialRouteName: 'StartImage',