forked from futurice/pepperoni-app-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.android.js
47 lines (38 loc) · 1.39 KB
/
index.android.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import 'es6-symbol/implement';
import {Provider} from 'react-redux';
import store from './src/redux/store';
import AppViewContainer from './src/modules/AppViewContainer';
import React from 'react';
import {AppRegistry, BackAndroid} from 'react-native';
import * as NavigationStateActions from './src/modules/navigation/NavigationState';
const PepperoniAppTemplate = React.createClass({
componentWillMount() {
BackAndroid.addEventListener('hardwareBackPress', this.navigateBack);
},
navigateBack() {
const navigationState = store.getState().get('navigationState');
const tabs = navigationState.get('tabs');
const tabKey = tabs.getIn(['routes', tabs.get('index')]).get('key');
const currentTab = navigationState.get(tabKey);
// if we are in the beginning of our tab stack
if (currentTab.get('index') === 0) {
// if we are not in the first tab, switch tab to the leftmost one
if (navigationState.get('index') !== 0) {
store.dispatch(NavigationStateActions.switchTab(0));
return true;
}
// otherwise let OS handle the back button action
return false;
}
store.dispatch(NavigationStateActions.popRoute());
return true;
},
render() {
return (
<Provider store={store}>
<AppViewContainer />
</Provider>
);
}
});
AppRegistry.registerComponent('PepperoniAppTemplate', () => PepperoniAppTemplate);