mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-13 22:30:41 +08:00
Add NavigationContainer and NavigationContainerProps types (#3030)
Adding types for these fixes the errors we're seeing when using `TabNavigator` and `StackNavigator`.
This commit is contained in:
29
packages/react-navigation/src/TypeDefinition.js
vendored
29
packages/react-navigation/src/TypeDefinition.js
vendored
@@ -228,9 +228,9 @@ export type NavigationScreenDetails<T> = {
|
||||
navigation: NavigationScreenProp<NavigationRoute>,
|
||||
};
|
||||
|
||||
export type NavigationScreenOptions = {|
|
||||
export type NavigationScreenOptions = {
|
||||
title?: string,
|
||||
|};
|
||||
};
|
||||
|
||||
export type NavigationScreenConfigProps = {
|
||||
navigation: NavigationScreenProp<NavigationRoute>,
|
||||
@@ -421,6 +421,31 @@ export type NavigationNavigatorProps<O: {}, S: {}> = {
|
||||
navigationOptions?: O,
|
||||
};
|
||||
|
||||
/**
|
||||
* Navigation container
|
||||
*/
|
||||
|
||||
export type NavigationContainer<
|
||||
State: NavigationState,
|
||||
Options: {},
|
||||
Props: {}
|
||||
> = React.ComponentType<NavigationContainerProps<State, Options> & Props> & {
|
||||
router: NavigationRouter<State, Options>,
|
||||
navigationOptions?: ?NavigationScreenConfig<Options>,
|
||||
};
|
||||
|
||||
export type NavigationContainerProps<S: {}, O: {}> = {
|
||||
uriPrefix?: string | RegExp,
|
||||
onNavigationStateChange?: (
|
||||
NavigationState,
|
||||
NavigationState,
|
||||
NavigationAction
|
||||
) => void,
|
||||
navigation?: NavigationScreenProp<S>,
|
||||
screenProps?: *,
|
||||
navigationOptions?: O,
|
||||
};
|
||||
|
||||
/**
|
||||
* Gestures, Animations, and Interpolators
|
||||
*/
|
||||
|
||||
@@ -13,20 +13,10 @@ import type {
|
||||
NavigationNavigator,
|
||||
PossiblyDeprecatedNavigationAction,
|
||||
NavigationInitAction,
|
||||
NavigationContainerProps,
|
||||
NavigationContainer,
|
||||
} from './TypeDefinition';
|
||||
|
||||
type Props<S, O> = {
|
||||
uriPrefix?: string | RegExp,
|
||||
onNavigationStateChange?: (
|
||||
NavigationState,
|
||||
NavigationState,
|
||||
NavigationAction
|
||||
) => void,
|
||||
navigation?: NavigationScreenProp<S>,
|
||||
screenProps?: *,
|
||||
navigationOptions?: O,
|
||||
};
|
||||
|
||||
type State<NavState> = {
|
||||
nav: ?NavState,
|
||||
};
|
||||
@@ -40,15 +30,19 @@ type State<NavState> = {
|
||||
export default function createNavigationContainer<S: NavigationState, O: {}>(
|
||||
// Let the NavigationNavigator props flowwwww
|
||||
Component: NavigationNavigator<S, O, *>
|
||||
) {
|
||||
class NavigationContainer extends React.Component<Props<S, O>, State<S>> {
|
||||
): NavigationContainer<S, O, *> {
|
||||
class NavigationContainer extends React.Component<
|
||||
NavigationContainerProps<S, O>,
|
||||
State<S>
|
||||
> {
|
||||
subs: ?{
|
||||
remove: () => void,
|
||||
} = null;
|
||||
|
||||
static router = Component.router;
|
||||
static navigationOptions = null;
|
||||
|
||||
constructor(props: Props<S, O>) {
|
||||
constructor(props: NavigationContainerProps<S, O>) {
|
||||
super(props);
|
||||
|
||||
this._validateProps(props);
|
||||
@@ -64,7 +58,7 @@ export default function createNavigationContainer<S: NavigationState, O: {}>(
|
||||
return !this.props.navigation;
|
||||
}
|
||||
|
||||
_validateProps(props: Props<S, O>) {
|
||||
_validateProps(props: NavigationContainerProps<S, O>) {
|
||||
if (this._isStateful()) {
|
||||
return;
|
||||
}
|
||||
@@ -142,7 +136,7 @@ export default function createNavigationContainer<S: NavigationState, O: {}>(
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps: Props<S, O>) {
|
||||
componentWillReceiveProps(nextProps: NavigationContainerProps<S, O>) {
|
||||
this._validateProps(nextProps);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user