Browse Source

Register event listeners with screenInstanceId instead of navigatorEventId

Guy Carmeli 8 years ago
parent
commit
116f3d93fb
2 changed files with 16 additions and 6 deletions
  1. 16
    5
      src/Screen.js
  2. 0
    1
      src/platformSpecific.android.js

+ 16
- 5
src/Screen.js View File

11
 const _allNavigatorEventHandlers = {};
11
 const _allNavigatorEventHandlers = {};
12
 
12
 
13
 class Navigator {
13
 class Navigator {
14
-  constructor(navigatorID, navigatorEventID) {
14
+  constructor(navigatorID, navigatorEventID, screenInstanceId) {
15
     this.navigatorID = navigatorID;
15
     this.navigatorID = navigatorID;
16
     this.navigatorEventID = navigatorEventID;
16
     this.navigatorEventID = navigatorEventID;
17
+    this.screenInstanceId = screenInstanceId;
17
     this.navigatorEventHandler = null;
18
     this.navigatorEventHandler = null;
18
     this.navigatorEventSubscription = null;
19
     this.navigatorEventSubscription = null;
19
   }
20
   }
101
   setOnNavigatorEvent(callback) {
102
   setOnNavigatorEvent(callback) {
102
     this.navigatorEventHandler = callback;
103
     this.navigatorEventHandler = callback;
103
     if (!this.navigatorEventSubscription) {
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
     if (!props.navigatorID) {
149
     if (!props.navigatorID) {
143
       props.navigatorID = _.uniqueId('navigatorId');
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
   componentWillUnmount() {
159
   componentWillUnmount() {

+ 0
- 1
src/platformSpecific.android.js View File

13
     return;
13
     return;
14
   }
14
   }
15
 
15
 
16
-  screen.screenInstanceId = _.uniqueId('screenInstanceId');
17
   params.screen = convertNavigationStyleToScreenStyle(screen);
16
   params.screen = convertNavigationStyleToScreenStyle(screen);
18
 
17
 
19
   NativeModules.NavigationReactModule.startApp(params);
18
   NativeModules.NavigationReactModule.startApp(params);