mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-10 22:47:02 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user