Add isFocused helper to navigation and fix withNavigationFocus (1.x branch) (#3651)

* Add isFocused helper to navigation and fix withNavigationFocus accordingly

* Fix snapshots

* Make flow pass on TabsWithNavigationFocus example
This commit is contained in:
Brent Vatne
2018-03-03 09:58:19 -08:00
committed by GitHub
parent 2744cb32b7
commit 138151433d
7 changed files with 97 additions and 36 deletions

View File

@@ -109,6 +109,12 @@ class CardStack extends React.Component {
});
}
_isRouteFocused = route => {
const { state } = this.props.navigation;
const focusedRoute = state.routes[state.index];
return route === focusedRoute;
};
_getScreenDetails = scene => {
const { screenProps, transitionProps: { navigation }, router } = this.props;
let screenDetails = this._screenDetails[scene.key];
@@ -123,6 +129,7 @@ class CardStack extends React.Component {
const screenNavigation = addNavigationHelpers({
dispatch: navigation.dispatch,
state: scene.route,
isFocused: this._isRouteFocused.bind(this, scene.route),
addListener: this._childEventSubscribers[scene.route.key],
});
screenDetails = {