mirror of
https://github.com/status-im/react-navigation.git
synced 2025-02-25 01:28:16 +00:00
Pass through screenProps to nested navigators
This changes the behaviour of screenProps so that the props no longer get splatted. Components will receive this as `this.props.screenProps`.
This commit is contained in:
parent
797833a69a
commit
b9bc386a4b
@ -130,6 +130,6 @@ The navigator component created by `DrawerNavigator(...)` takes the following pr
|
|||||||
});
|
});
|
||||||
|
|
||||||
<DrawerNav
|
<DrawerNav
|
||||||
screenProps={/* these will get passed to the screen components */}
|
screenProps={/* this prop will get passed to the screen components as this.props.screenProps */}
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
|
@ -139,7 +139,7 @@ The navigator component created by `StackNavigator(...)` takes the following pro
|
|||||||
});
|
});
|
||||||
|
|
||||||
<SomeStack
|
<SomeStack
|
||||||
screenProps={/* these will get passed to the screen components */}
|
screenProps={/* this prop will get passed to the screen components as this.props.screenProps */}
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ The navigator component created by `TabNavigator(...)` takes the following props
|
|||||||
});
|
});
|
||||||
|
|
||||||
<TabNav
|
<TabNav
|
||||||
screenProps={/* these will get passed to the screen components */}
|
screenProps={/* this prop will get passed to the screen components as this.props.screenProps */}
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -11,12 +11,12 @@ import type {
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
screenProps?: {};
|
screenProps?: {};
|
||||||
|
hideScreenPropsWarning?: boolean;
|
||||||
navigation: NavigationScreenProp<NavigationState, NavigationAction>;
|
navigation: NavigationScreenProp<NavigationState, NavigationAction>;
|
||||||
component: ReactClass<*>;
|
component: ReactClass<*>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class SceneView extends PureComponent<void, Props, void> {
|
export default class SceneView extends PureComponent<void, Props, void> {
|
||||||
|
|
||||||
static childContextTypes = {
|
static childContextTypes = {
|
||||||
navigation: React.PropTypes.object.isRequired,
|
navigation: React.PropTypes.object.isRequired,
|
||||||
};
|
};
|
||||||
@ -29,8 +29,30 @@ export default class SceneView extends PureComponent<void, Props, void> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillMount() {
|
||||||
|
if (this.props.screenProps !== undefined && !this.props.hideScreenPropsWarning) {
|
||||||
|
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.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { screenProps, navigation, component: Component } = this.props;
|
const {
|
||||||
return <Component {...screenProps} navigation={navigation} />;
|
hideScreenPropsWarning,
|
||||||
|
screenProps,
|
||||||
|
navigation,
|
||||||
|
component: Component,
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Component
|
||||||
|
hideScreenPropsWarning={hideScreenPropsWarning}
|
||||||
|
screenProps={screenProps}
|
||||||
|
navigation={navigation}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user