Skip to content

Commit d10e393

Browse files
committed
BackNavigationHandler: Get canGoBack from NavigationService.
We've been getting this value from the navigation state in Redux, via react-redux, but - We want to stop using the nav state in Redux, for #3804. - `NavigationService` can give it to us, and it should be ready (the ref it uses should have been set) by the time we use it. - The value has only been used in an event handler; we haven't been taking advantage of the fact (thanks to react-redux) that `BackNavigationHandler`'s `render` and `componentDidUpdate` methods have been getting called whenever it changes.
1 parent ff872f6 commit d10e393

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/nav/BackNavigationHandler.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/* @flow strict-local */
22
import type { Node as React$Node } from 'react';
3-
43
import { PureComponent } from 'react';
54
import { BackHandler } from 'react-native';
65

6+
import NavigationService from './NavigationService';
77
import type { Dispatch } from '../types';
88
import { connect } from '../react-redux';
99
import { navigateBack } from '../actions';
1010

1111
type Props = $ReadOnly<{|
1212
children: React$Node,
13-
canGoBack: boolean,
13+
1414
dispatch: Dispatch,
1515
|}>;
1616

@@ -24,7 +24,8 @@ class BackNavigationHandler extends PureComponent<Props> {
2424
}
2525

2626
handleBackButtonPress = () => {
27-
const { canGoBack, dispatch } = this.props;
27+
const { dispatch } = this.props;
28+
const canGoBack = NavigationService.getState().index > 0;
2829
if (canGoBack) {
2930
dispatch(navigateBack());
3031
}
@@ -36,6 +37,4 @@ class BackNavigationHandler extends PureComponent<Props> {
3637
}
3738
}
3839

39-
export default connect(state => ({
40-
canGoBack: state.nav.index > 0,
41-
}))(BackNavigationHandler);
40+
export default connect(state => ({}))(BackNavigationHandler);

0 commit comments

Comments
 (0)