withNavigation improvement (#3834)

The navigation prop should also pass through, and be prioritized over context because it is more explicit

This also fixes an incorrect warning/invariant
This commit is contained in:
Eric Vicenti
2018-03-25 13:49:09 -04:00
parent 598f18688c
commit b41d268572

View File

@@ -10,12 +10,14 @@ export default function withNavigation(Component) {
Component.name})`;
render() {
const navigationProp = this.props.navigation;
return (
<NavigationConsumer>
{navigation => {
{navigationContext => {
const navigation = navigationProp || navigationContext;
invariant(
!!navigation,
'withNavigationFocus can only be used on a view hierarchy of a navigator. The wrapped component is unable to get access to navigation from props or context.'
'withNavigation can only be used on a view hierarchy of a navigator. The wrapped component is unable to get access to navigation from props or context.'
);
return (
<Component