Bladeren bron

expose navigation handleDeepLink as a static method (#727)

Artal Druk 8 jaren geleden
bovenliggende
commit
430d5de59a
2 gewijzigde bestanden met toevoegingen van 27 en 13 verwijderingen
  1. 24
    1
      src/Navigation.js
  2. 3
    12
      src/Screen.js

+ 24
- 1
src/Navigation.js Bestand weergeven

@@ -7,6 +7,7 @@ import Screen from './Screen';
7 7
 import PropRegistry from './PropRegistry';
8 8
 
9 9
 const registeredScreens = {};
10
+const _allNavigatorEventHandlers = {};
10 11
 
11 12
 function registerScreen(screenID, generator) {
12 13
   registeredScreens[screenID] = generator;
@@ -134,6 +135,25 @@ function startSingleScreenApp(params) {
134 135
   return platformSpecific.startSingleScreenApp(params);
135 136
 }
136 137
 
138
+function setEventHandler(navigatorEventID, eventHandler) {
139
+  _allNavigatorEventHandlers[navigatorEventID] = eventHandler;
140
+}
141
+
142
+function clearEventHandler(navigatorEventID) {
143
+  delete _allNavigatorEventHandlers[navigatorEventID];
144
+}
145
+
146
+function handleDeepLink(params = {}) {
147
+  if (!params.link) return;
148
+  const event = {
149
+    type: 'DeepLink',
150
+    link: params.link
151
+  };
152
+  for (let i in _allNavigatorEventHandlers) {
153
+    _allNavigatorEventHandlers[i](event);
154
+  }
155
+}
156
+
137 157
 export default {
138 158
   getRegisteredScreen,
139 159
   registerComponent,
@@ -145,5 +165,8 @@ export default {
145 165
   showInAppNotification: showInAppNotification,
146 166
   dismissInAppNotification: dismissInAppNotification,
147 167
   startTabBasedApp: startTabBasedApp,
148
-  startSingleScreenApp: startSingleScreenApp
168
+  startSingleScreenApp: startSingleScreenApp,
169
+  setEventHandler: setEventHandler,
170
+  clearEventHandler: clearEventHandler,
171
+  handleDeepLink: handleDeepLink
149 172
 };

+ 3
- 12
src/Screen.js Bestand weergeven

@@ -8,8 +8,6 @@ import {
8 8
 import platformSpecific from './deprecated/platformSpecificDeprecated';
9 9
 import Navigation from './Navigation';
10 10
 
11
-const _allNavigatorEventHandlers = {};
12
-
13 11
 const NavigationSpecific = {
14 12
   push: platformSpecific.navigatorPush,
15 13
   pop: platformSpecific.navigatorPop,
@@ -123,19 +121,12 @@ class Navigator {
123 121
     if (!this.navigatorEventSubscription) {
124 122
       let Emitter = Platform.OS === 'android' ? DeviceEventEmitter : NativeAppEventEmitter;
125 123
       this.navigatorEventSubscription = Emitter.addListener(this.navigatorEventID, (event) => this.onNavigatorEvent(event));
126
-      _allNavigatorEventHandlers[this.navigatorEventID] = (event) => this.onNavigatorEvent(event);
124
+      Navigation.setEventHandler(this.navigatorEventID, (event) => this.onNavigatorEvent(event));
127 125
     }
128 126
   }
129 127
 
130 128
   handleDeepLink(params = {}) {
131
-    if (!params.link) return;
132
-    const event = {
133
-      type: 'DeepLink',
134
-      link: params.link
135
-    };
136
-    for (let i in _allNavigatorEventHandlers) {
137
-      _allNavigatorEventHandlers[i](event);
138
-    }
129
+    Navigation.handleDeepLink(params);
139 130
   }
140 131
 
141 132
   onNavigatorEvent(event) {
@@ -147,7 +138,7 @@ class Navigator {
147 138
   cleanup() {
148 139
     if (this.navigatorEventSubscription) {
149 140
       this.navigatorEventSubscription.remove();
150
-      delete _allNavigatorEventHandlers[this.navigatorEventID];
141
+      Navigation.clearEventHandler(this.navigatorEventID);
151 142
     }
152 143
   }
153 144
 }