diff --git a/packages/core/src/views/withNavigation.js b/packages/core/src/views/withNavigation.js index f3095e05..70be9c34 100644 --- a/packages/core/src/views/withNavigation.js +++ b/packages/core/src/views/withNavigation.js @@ -3,7 +3,10 @@ import hoistStatics from 'hoist-non-react-statics'; import invariant from '../utils/invariant'; import NavigationContext from './NavigationContext'; -export default function withNavigation(Component) { +export default function withNavigation( + Component, + config = { forwardRef: true } +) { class ComponentWithNavigation extends React.Component { static displayName = `withNavigation(${Component.displayName || Component.name})`; @@ -22,7 +25,7 @@ export default function withNavigation(Component) { ); }} diff --git a/packages/core/src/views/withNavigationFocus.js b/packages/core/src/views/withNavigationFocus.js index 63c0b547..30e5bf7e 100644 --- a/packages/core/src/views/withNavigationFocus.js +++ b/packages/core/src/views/withNavigationFocus.js @@ -1,6 +1,5 @@ import React from 'react'; import hoistStatics from 'hoist-non-react-statics'; -import invariant from '../utils/invariant'; import withNavigation from './withNavigation'; export default function withNavigationFocus(Component) { @@ -18,11 +17,6 @@ export default function withNavigationFocus(Component) { componentDidMount() { const { navigation } = this.props; - 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.' - ); - this.subscriptions = [ navigation.addListener('didFocus', () => this.setState({ isFocused: true }) @@ -48,5 +42,8 @@ export default function withNavigationFocus(Component) { } } - return hoistStatics(withNavigation(ComponentWithNavigationFocus), Component); + return hoistStatics( + withNavigation(ComponentWithNavigationFocus, { forwardRef: false }), + Component + ); }