Show screen props warning only once. Fixes #258

This commit is contained in:
Satyajit Sahoo 2017-02-09 19:32:59 +05:30
parent 73426e8015
commit 1f80d98112

View File

@ -11,11 +11,12 @@ import type {
type Props = {
screenProps?: {};
hideScreenPropsWarning?: boolean;
navigation: NavigationScreenProp<NavigationState, NavigationAction>;
component: ReactClass<*>;
};
let screenPropsWarningShown = false;
export default class SceneView extends PureComponent<void, Props, void> {
static childContextTypes = {
navigation: React.PropTypes.object.isRequired,
@ -30,18 +31,18 @@ export default class SceneView extends PureComponent<void, Props, void> {
}
componentWillMount() {
if (this.props.screenProps !== undefined && !this.props.hideScreenPropsWarning) {
if (this.props.screenProps !== undefined && !screenPropsWarningShown) {
console.warn(
'Behaviour of screenProps has changed from initial beta. ' +
'Components will now receive it as `this.props.screenProps` instead.\n' +
'Pass `hideScreenPropsWarning` to hide this warning.'
'This warning will be removed in future.'
);
screenPropsWarningShown = true;
}
}
render() {
const {
hideScreenPropsWarning,
screenProps,
navigation,
component: Component,
@ -49,7 +50,6 @@ export default class SceneView extends PureComponent<void, Props, void> {
return (
<Component
hideScreenPropsWarning={hideScreenPropsWarning}
screenProps={screenProps}
navigation={navigation}
/>