|
@@ -1,4 +1,9 @@
|
1
|
|
-import { Component, NativeAppEventEmitter } from 'react-native';
|
|
1
|
+import {
|
|
2
|
+ Component,
|
|
3
|
+ NativeAppEventEmitter,
|
|
4
|
+ DeviceEventEmitter,
|
|
5
|
+ Platform
|
|
6
|
+} from 'react-native';
|
2
|
7
|
import platformSpecific from './platformSpecific';
|
3
|
8
|
import Navigation from './Navigation';
|
4
|
9
|
|
|
@@ -11,52 +16,68 @@ class Navigator {
|
11
|
16
|
this.navigatorEventHandler = null;
|
12
|
17
|
this.navigatorEventSubscription = null;
|
13
|
18
|
}
|
|
19
|
+
|
14
|
20
|
push(params = {}) {
|
15
|
21
|
return platformSpecific.navigatorPush(this, params);
|
16
|
22
|
}
|
|
23
|
+
|
17
|
24
|
pop(params = {}) {
|
18
|
25
|
return platformSpecific.navigatorPop(this, params);
|
19
|
26
|
}
|
|
27
|
+
|
20
|
28
|
popToRoot(params = {}) {
|
21
|
29
|
return platformSpecific.navigatorPopToRoot(this, params);
|
22
|
30
|
}
|
|
31
|
+
|
23
|
32
|
resetTo(params = {}) {
|
24
|
33
|
return platformSpecific.navigatorResetTo(this, params);
|
25
|
34
|
}
|
|
35
|
+
|
26
|
36
|
showModal(params = {}) {
|
27
|
37
|
return Navigation.showModal(params);
|
28
|
38
|
}
|
|
39
|
+
|
29
|
40
|
dismissModal(params = {}) {
|
30
|
41
|
return Navigation.dismissModal(params);
|
31
|
42
|
}
|
|
43
|
+
|
32
|
44
|
showLightBox(params = {}) {
|
33
|
45
|
return Navigation.showLightBox(params);
|
34
|
46
|
}
|
|
47
|
+
|
35
|
48
|
dismissLightBox(params = {}) {
|
36
|
49
|
return Navigation.dismissLightBox(params);
|
37
|
50
|
}
|
|
51
|
+
|
38
|
52
|
setButtons(params = {}) {
|
39
|
53
|
return platformSpecific.navigatorSetButtons(this, this.navigatorEventID, params);
|
40
|
54
|
}
|
|
55
|
+
|
41
|
56
|
setTitle(params = {}) {
|
42
|
57
|
return platformSpecific.navigatorSetTitle(this, params);
|
43
|
58
|
}
|
|
59
|
+
|
44
|
60
|
toggleDrawer(params = {}) {
|
45
|
61
|
return platformSpecific.navigatorToggleDrawer(this, params);
|
46
|
62
|
}
|
|
63
|
+
|
47
|
64
|
toggleTabs(params = {}) {
|
48
|
65
|
return platformSpecific.navigatorToggleTabs(this, params);
|
49
|
66
|
}
|
|
67
|
+
|
50
|
68
|
setTabBadge(params = {}) {
|
51
|
69
|
return platformSpecific.navigatorSetTabBadge(this, params);
|
52
|
70
|
}
|
|
71
|
+
|
53
|
72
|
switchToTab(params = {}) {
|
54
|
73
|
return platformSpecific.navigatorSwitchToTab(this, params);
|
55
|
74
|
}
|
|
75
|
+
|
56
|
76
|
setOnNavigatorEvent(callback) {
|
57
|
77
|
this.navigatorEventHandler = callback;
|
58
|
78
|
if (!this.navigatorEventSubscription) {
|
59
|
|
- this.navigatorEventSubscription = NativeAppEventEmitter.addListener(this.navigatorEventID, (event) => this.onNavigatorEvent(event));
|
|
79
|
+ let Emitter = Platform.OS === 'android' ? DeviceEventEmitter : NativeAppEventEmitter;
|
|
80
|
+ this.navigatorEventSubscription = Emitter.addListener(this.navigatorEventID, (event) => this.onNavigatorEvent(event));
|
60
|
81
|
_allNavigatorEventHandlers[this.navigatorEventID] = (event) => this.onNavigatorEvent(event);
|
61
|
82
|
}
|
62
|
83
|
}
|
|
@@ -70,11 +91,13 @@ class Navigator {
|
70
|
91
|
_allNavigatorEventHandlers[i](event);
|
71
|
92
|
}
|
72
|
93
|
}
|
|
94
|
+
|
73
|
95
|
onNavigatorEvent(event) {
|
74
|
96
|
if (this.navigatorEventHandler) {
|
75
|
97
|
this.navigatorEventHandler(event);
|
76
|
98
|
}
|
77
|
99
|
}
|
|
100
|
+
|
78
|
101
|
cleanup() {
|
79
|
102
|
if (this.navigatorEventSubscription) {
|
80
|
103
|
this.navigatorEventSubscription.remove();
|
|
@@ -86,12 +109,14 @@ class Navigator {
|
86
|
109
|
export default class Screen extends Component {
|
87
|
110
|
static navigatorStyle = {};
|
88
|
111
|
static navigatorButtons = {};
|
|
112
|
+
|
89
|
113
|
constructor(props) {
|
90
|
114
|
super(props);
|
91
|
115
|
if (props.navigatorID) {
|
92
|
116
|
this.navigator = new Navigator(props.navigatorID, props.navigatorEventID);
|
93
|
117
|
}
|
94
|
118
|
}
|
|
119
|
+
|
95
|
120
|
componentWillUnmount() {
|
96
|
121
|
if (this.navigator) {
|
97
|
122
|
this.navigator.cleanup();
|