|
@@ -1,7 +1,6 @@
|
1
|
1
|
import React, {
|
2
|
2
|
AppRegistry,
|
3
|
|
- Component,
|
4
|
|
- View
|
|
3
|
+ Component
|
5
|
4
|
} from 'react-native';
|
6
|
5
|
import { createStore, applyMiddleware, combineReducers } from 'redux';
|
7
|
6
|
import { Provider } from 'react-redux';
|
|
@@ -18,6 +17,7 @@ const store = createStoreWithMiddleware(reducer);
|
18
|
17
|
// screen related book keeping
|
19
|
18
|
import { registerScreens } from './screens';
|
20
|
19
|
registerScreens(store, Provider);
|
|
20
|
+let unsubscribe;
|
21
|
21
|
|
22
|
22
|
AppRegistry.registerComponent('ExampleRedux', () => App);
|
23
|
23
|
|
|
@@ -25,28 +25,34 @@ AppRegistry.registerComponent('ExampleRedux', () => App);
|
25
|
25
|
export default class App extends React.Component {
|
26
|
26
|
constructor(props) {
|
27
|
27
|
super(props);
|
|
28
|
+ console.log('constructor');
|
28
|
29
|
// since react-redux only works on components, we need to subscribe this class manually
|
29
|
|
- store.subscribe(this.onStoreUpdate.bind(this));
|
|
30
|
+ unsubscribe = store.subscribe(this.onStoreUpdate.bind(this));
|
30
|
31
|
store.dispatch(appActions.appInitialized());
|
31
|
32
|
}
|
32
|
33
|
|
33
|
34
|
render() {
|
34
|
|
- return (
|
35
|
|
- <View />
|
36
|
|
- );
|
|
35
|
+ return null;
|
37
|
36
|
}
|
38
|
37
|
|
39
|
38
|
onStoreUpdate() {
|
40
|
39
|
const { root } = store.getState().app;
|
|
40
|
+ console.log('onStoreUpdate ' + root + ' currentRoot ' + this.currentRoot);
|
41
|
41
|
// handle a root change
|
42
|
42
|
// if your app doesn't change roots in runtime, you can remove onStoreUpdate() altogether
|
43
|
|
- if (this.currentRoot !== root) {
|
|
43
|
+ if (this.currentRoot != root) {
|
44
|
44
|
this.currentRoot = root;
|
45
|
45
|
this.startApp(root);
|
|
46
|
+ } else {
|
|
47
|
+ if (unsubscribe && this.currentRoot) {
|
|
48
|
+ console.log('unsubscribing ' + this.currentRoot);
|
|
49
|
+ unsubscribe();
|
|
50
|
+ }
|
46
|
51
|
}
|
47
|
52
|
}
|
48
|
53
|
|
49
|
54
|
startApp(root) {
|
|
55
|
+ console.log('startApp ' + root);
|
50
|
56
|
switch (root) {
|
51
|
57
|
case 'login':
|
52
|
58
|
Navigation.startSingleScreenApp({
|
|
@@ -77,7 +83,8 @@ export default class App extends React.Component {
|
77
|
83
|
navigatorStyle: {}
|
78
|
84
|
}
|
79
|
85
|
],
|
80
|
|
- animationType: 'slide-down'
|
|
86
|
+ animationType: 'slide-down',
|
|
87
|
+ title: 'Redux Example'
|
81
|
88
|
});
|
82
|
89
|
return;
|
83
|
90
|
default:
|