Skip to content

Commit a6d906f

Browse files
committed
Android Back Button support
1 parent 9d3c988 commit a6d906f

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

App/Navigation/NavigationBar.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88

99
import cssVar from '../Lib/cssVar';
1010

11+
import Back from '../Platform/Back';
1112
import NavigatorNavigationBarStyles from '../Platform/NavigatorNavigationBarStyles';
1213
import NavigationBarRouteMapper from '../Navigation/NavigationBarRouteMapper';
1314

@@ -128,6 +129,10 @@ var NavigationBar = {
128129
);
129130
},
130131

132+
componentDidMount: function() {
133+
Back.setNavigator(this.refs.navigator);
134+
},
135+
131136
render: function() {
132137
return (
133138
<View style={styles.appContainer}>

App/Platform/Back.android.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
3+
import {
4+
BackAndroid,
5+
} from 'react-native';
6+
7+
import AppActions from '../Actions/AppActions';
8+
// import DrawerStore from '../Stores/DrawerStore';
9+
10+
const Back = {
11+
setNavigator(navigator) {
12+
BackAndroid.addEventListener('hardwareBackPress', () => {
13+
// if (DrawerStore.get().open === true) {
14+
// AppActions.toggleDrawer();
15+
// return true;
16+
// }
17+
if (navigator && navigator.getCurrentRoutes().length > 1) {
18+
AppActions.goBack(navigator);
19+
return true;
20+
}
21+
return false;
22+
});
23+
},
24+
};
25+
26+
export default Back;

Back.ios.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const Back = {
2+
setNavigator(navigator) {
3+
},
4+
};
5+
6+
export default Back;

0 commit comments

Comments
 (0)