Parcourir la source

Register event listeners with screenInstanceId instead of navigatorEventId

Guy Carmeli il y a 8 ans
Parent
révision
116f3d93fb
2 fichiers modifiés avec 16 ajouts et 6 suppressions
  1. 16
    5
      src/Screen.js
  2. 0
    1
      src/platformSpecific.android.js

+ 16
- 5
src/Screen.js Voir le fichier

@@ -11,9 +11,10 @@ import _ from 'lodash';
11 11
 const _allNavigatorEventHandlers = {};
12 12
 
13 13
 class Navigator {
14
-  constructor(navigatorID, navigatorEventID) {
14
+  constructor(navigatorID, navigatorEventID, screenInstanceId) {
15 15
     this.navigatorID = navigatorID;
16 16
     this.navigatorEventID = navigatorEventID;
17
+    this.screenInstanceId = screenInstanceId;
17 18
     this.navigatorEventHandler = null;
18 19
     this.navigatorEventSubscription = null;
19 20
   }
@@ -101,9 +102,15 @@ class Navigator {
101 102
   setOnNavigatorEvent(callback) {
102 103
     this.navigatorEventHandler = callback;
103 104
     if (!this.navigatorEventSubscription) {
104
-      let Emitter = Platform.OS === 'android' ? DeviceEventEmitter : NativeAppEventEmitter;
105
-      this.navigatorEventSubscription = Emitter.addListener(this.navigatorEventID, (event) => this.onNavigatorEvent(event));
106
-      _allNavigatorEventHandlers[this.navigatorEventID] = (event) => this.onNavigatorEvent(event);
105
+      if (Platform.OS === 'android') {
106
+        let Emitter = DeviceEventEmitter;
107
+        this.navigatorEventSubscription = Emitter.addListener(this.screenInstanceId, (event) => this.onNavigatorEvent(event));
108
+        _allNavigatorEventHandlers[this.screenInstanceId] = (event) => this.onNavigatorEvent(event);
109
+      } else {
110
+        let Emitter = NativeAppEventEmitter;
111
+        this.navigatorEventSubscription = Emitter.addListener(this.navigatorEventID, (event) => this.onNavigatorEvent(event));
112
+        _allNavigatorEventHandlers[this.navigatorEventID] = (event) => this.onNavigatorEvent(event);
113
+      }
107 114
     }
108 115
   }
109 116
 
@@ -142,7 +149,11 @@ export default class Screen extends Component {
142 149
     if (!props.navigatorID) {
143 150
       props.navigatorID = _.uniqueId('navigatorId');
144 151
     }
145
-    this.navigator = new Navigator(props.navigatorID, props.navigatorEventID);
152
+    // TODO: keep this shit?
153
+    if (!props.screenInstanceId) {
154
+      props.screenInstanceId = _.uniqueId('screenInstanceId');
155
+    }
156
+    this.navigator = new Navigator(props.navigatorID, props.navigatorEventID, props.screenInstanceId);
146 157
   }
147 158
 
148 159
   componentWillUnmount() {

+ 0
- 1
src/platformSpecific.android.js Voir le fichier

@@ -13,7 +13,6 @@ function startApp(params) {
13 13
     return;
14 14
   }
15 15
 
16
-  screen.screenInstanceId = _.uniqueId('screenInstanceId');
17 16
   params.screen = convertNavigationStyleToScreenStyle(screen);
18 17
 
19 18
   NativeModules.NavigationReactModule.startApp(params);