1
1
/* @flow */
2
2
import React , { PureComponent } from 'react' ;
3
- import { AppState , NetInfo , View } from 'react-native' ;
3
+ import { AppState , BackHandler , NetInfo , View } from 'react-native' ;
4
4
import { connect } from 'react-redux' ;
5
5
6
6
import boundActions from '../boundActions' ;
7
7
import AppWithNavigationState from './AppWithNavigationState' ;
8
- import { getAuth } from '../selectors' ;
8
+ import { getAuth , getNavigationIndex } from '../selectors' ;
9
9
import { registerAppActivity } from '../utils/activity' ;
10
10
import { checkCompatibility } from '../api' ;
11
11
import CompatibilityScreen from '../start/CompatibilityScreen' ;
12
12
import { Auth , Actions } from '../types' ;
13
13
14
14
type Props = {
15
15
auth : Auth ,
16
+ navIndex : number ,
16
17
needsInitialFetch : boolean ,
17
18
actions : Actions ,
18
19
} ;
@@ -48,6 +49,15 @@ class AppContainer extends PureComponent {
48
49
actions . appState ( state === 'active' ) ;
49
50
} ;
50
51
52
+ handleBackButtonPress = ( ) => {
53
+ const { navIndex, actions } = this . props ;
54
+ if ( navIndex !== 0 ) {
55
+ actions . navigateBack ( ) ;
56
+ return true ;
57
+ }
58
+ return false ;
59
+ }
60
+
51
61
handleMemoryWarning = ( ) => {
52
62
// Release memory here
53
63
} ;
@@ -56,6 +66,7 @@ class AppContainer extends PureComponent {
56
66
NetInfo . isConnected . addEventListener ( 'change' , this . handleConnectivityChange ) ;
57
67
AppState . addEventListener ( 'change' , this . handleAppStateChange ) ;
58
68
AppState . addEventListener ( 'memoryWarning' , this . handleMemoryWarning ) ;
69
+ BackHandler . addEventListener ( 'hardwareBackPress' , this . handleBackButtonPress ) ;
59
70
checkCompatibility ( ) . then ( res => {
60
71
if ( res . status === 400 ) {
61
72
this . setState ( {
@@ -102,6 +113,7 @@ export default connect(
102
113
state => ( {
103
114
auth : getAuth ( state ) ,
104
115
needsInitialFetch : state . app . needsInitialFetch ,
116
+ navIndex : getNavigationIndex ( state ) ,
105
117
} ) ,
106
118
boundActions ,
107
119
) ( AppContainer ) ;
0 commit comments