Files
react-navigation/src/views/withNavigation.js
Satyajit Sahoo a7b1243053 Fix flow (#305)
* Fix Flow and Android build

* Enable flow on CI

* Fix and suppress flow errors
2017-02-13 08:26:30 -08:00

34 lines
858 B
JavaScript

/* @flow */
import React from 'react';
import hoistStatics from 'hoist-non-react-statics';
import type {
NavigationState,
NavigationRoute,
NavigationAction,
} from '../TypeDefinition';
type Context = {
navigation: InjectedProps<NavigationState, NavigationAction>,
};
type InjectedProps = {
navigation: InjectedProps<NavigationState, NavigationAction>,
};
export default function withNavigation<T: *>(Component: ReactClass<T & InjectedProps>) {
const componentWithNavigation = (props: T, { navigation }: Context) => (
<Component {...props} navigation={navigation} />
);
componentWithNavigation.displayName = `withNavigation(${Component.displayName || Component.name})`;
componentWithNavigation.contextTypes = {
navigation: React.PropTypes.object.isRequired,
};
return hoistStatics(componentWithNavigation, Component);
}