Skip to content

Commit 430d5de

Browse files
artaldDanielZlotin
authored andcommitted
expose navigation handleDeepLink as a static method (wix#727)
1 parent 326f483 commit 430d5de

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/Navigation.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Screen from './Screen';
77
import PropRegistry from './PropRegistry';
88

99
const registeredScreens = {};
10+
const _allNavigatorEventHandlers = {};
1011

1112
function registerScreen(screenID, generator) {
1213
registeredScreens[screenID] = generator;
@@ -134,6 +135,25 @@ function startSingleScreenApp(params) {
134135
return platformSpecific.startSingleScreenApp(params);
135136
}
136137

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+
137157
export default {
138158
getRegisteredScreen,
139159
registerComponent,
@@ -145,5 +165,8 @@ export default {
145165
showInAppNotification: showInAppNotification,
146166
dismissInAppNotification: dismissInAppNotification,
147167
startTabBasedApp: startTabBasedApp,
148-
startSingleScreenApp: startSingleScreenApp
168+
startSingleScreenApp: startSingleScreenApp,
169+
setEventHandler: setEventHandler,
170+
clearEventHandler: clearEventHandler,
171+
handleDeepLink: handleDeepLink
149172
};

src/Screen.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import {
88
import platformSpecific from './deprecated/platformSpecificDeprecated';
99
import Navigation from './Navigation';
1010

11-
const _allNavigatorEventHandlers = {};
12-
1311
const NavigationSpecific = {
1412
push: platformSpecific.navigatorPush,
1513
pop: platformSpecific.navigatorPop,
@@ -123,19 +121,12 @@ class Navigator {
123121
if (!this.navigatorEventSubscription) {
124122
let Emitter = Platform.OS === 'android' ? DeviceEventEmitter : NativeAppEventEmitter;
125123
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));
127125
}
128126
}
129127

130128
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);
139130
}
140131

141132
onNavigatorEvent(event) {
@@ -147,7 +138,7 @@ class Navigator {
147138
cleanup() {
148139
if (this.navigatorEventSubscription) {
149140
this.navigatorEventSubscription.remove();
150-
delete _allNavigatorEventHandlers[this.navigatorEventID];
141+
Navigation.clearEventHandler(this.navigatorEventID);
151142
}
152143
}
153144
}

0 commit comments

Comments
 (0)