[react-navigation] Improve test, add screen component props type checks

This commit is contained in:
abrahambotros
2017-06-14 22:58:27 -07:00
parent e5843ac8f5
commit e34616fd3c
2 changed files with 33 additions and 4 deletions

View File

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

View File

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