mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-06 17:34:59 +08:00
Show screen props warning only once. Fixes #258
This commit is contained in:
@@ -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}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user