hybrid-navigation 2.13.3 → 2.13.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,7 +37,11 @@ public class Garden {
37
37
  globalStyle = new GlobalStyle(options);
38
38
  }
39
39
 
40
+ @NonNull
40
41
  static GlobalStyle getGlobalStyle() {
42
+ if (globalStyle == null) {
43
+ globalStyle = new GlobalStyle(new Bundle());
44
+ }
41
45
  return globalStyle;
42
46
  }
43
47
 
@@ -46,7 +46,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
46
46
  clearFragments();
47
47
  });
48
48
  }
49
-
49
+
50
50
  private void clearFragments() {
51
51
  AwesomeActivity activity = getActiveActivity();
52
52
  if (activity != null) {
@@ -103,7 +103,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
103
103
  FLog.w(TAG, "ReactContext hasn't active CatalystInstance, skip action `setRoot`");
104
104
  return;
105
105
  }
106
-
106
+
107
107
  if (bridgeManager.getPendingCallback() != null) {
108
108
  bridgeManager.getPendingCallback().invoke(null, false);
109
109
  }
@@ -115,7 +115,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
115
115
  if (!bridgeManager.isReactModuleRegisterCompleted()) {
116
116
  return;
117
117
  }
118
-
118
+
119
119
  ReactAppCompatActivity activity = getActiveActivity();
120
120
  if (activity != null && !activity.getSupportFragmentManager().isStateSaved()) {
121
121
  FLog.i(TAG, "Have active Activity and React module was registered, set root Fragment immediately.");
@@ -157,7 +157,7 @@ public class NavigationModule extends ReactContextBaseJavaModule {
157
157
  callback.invoke(null, -1);
158
158
  return;
159
159
  }
160
-
160
+
161
161
  callback.invoke(null, tabs.getSelectedIndex());
162
162
  });
163
163
  }
@@ -194,19 +194,17 @@ public class NavigationModule extends ReactContextBaseJavaModule {
194
194
  UiThreadUtil.runOnUiThread(this, 16);
195
195
  return;
196
196
  }
197
+
198
+ FragmentManager fragmentManager = activity.getSupportFragmentManager();
199
+ Fragment fragment = fragmentManager.findFragmentById(android.R.id.content);
200
+ if (!(fragment instanceof AwesomeFragment)) {
201
+ callback.invoke(null, null);
202
+ return;
203
+ }
197
204
 
198
- activity.scheduleTaskAtStarted(() -> {
199
- FragmentManager fragmentManager = activity.getSupportFragmentManager();
200
- Fragment fragment = fragmentManager.findFragmentById(android.R.id.content);
201
- if (!(fragment instanceof AwesomeFragment)) {
202
- callback.invoke(null, null);
203
- return;
204
- }
205
-
206
- String sceneId = findSceneIdByModuleName(moduleName, (AwesomeFragment) fragment);
207
- FLog.i(TAG, "The sceneId found by " + moduleName + " : " + sceneId);
208
- callback.invoke(null, sceneId);
209
- });
205
+ String sceneId = findSceneIdByModuleName(moduleName, (AwesomeFragment) fragment);
206
+ FLog.i(TAG, "The sceneId found by " + moduleName + " : " + sceneId);
207
+ callback.invoke(null, sceneId);
210
208
  }
211
209
  };
212
210
 
@@ -256,21 +254,19 @@ public class NavigationModule extends ReactContextBaseJavaModule {
256
254
  UiThreadUtil.runOnUiThread(this, 16);
257
255
  return;
258
256
  }
257
+
258
+ FragmentManager fragmentManager = activity.getSupportFragmentManager();
259
+ HybridFragment current = bridgeManager.primaryFragment(fragmentManager);
260
+ if (current == null) {
261
+ UiThreadUtil.runOnUiThread(this, 16);
262
+ return;
263
+ }
259
264
 
260
- activity.scheduleTaskAtStarted(() -> {
261
- FragmentManager fragmentManager = activity.getSupportFragmentManager();
262
- HybridFragment current = bridgeManager.primaryFragment(fragmentManager);
263
- if (current == null) {
264
- UiThreadUtil.runOnUiThread(this, 16);
265
- return;
266
- }
267
-
268
- Bundle bundle = new Bundle();
269
- bundle.putString("moduleName", current.getModuleName());
270
- bundle.putString("sceneId", current.getSceneId());
271
- bundle.putString("mode", Navigator.Util.getMode(current));
272
- callback.invoke(null, Arguments.fromBundle(bundle));
273
- });
265
+ Bundle bundle = new Bundle();
266
+ bundle.putString("moduleName", current.getModuleName());
267
+ bundle.putString("sceneId", current.getSceneId());
268
+ bundle.putString("mode", Navigator.Util.getMode(current));
269
+ callback.invoke(null, Arguments.fromBundle(bundle));
274
270
  }
275
271
  };
276
272
 
@@ -287,17 +283,15 @@ public class NavigationModule extends ReactContextBaseJavaModule {
287
283
  UiThreadUtil.runOnUiThread(this, 16);
288
284
  return;
289
285
  }
286
+
287
+ FragmentManager fragmentManager = activity.getSupportFragmentManager();
288
+ ArrayList<Bundle> graph = bridgeManager.buildRouteGraph(fragmentManager);
289
+ if (graph.size() == 0) {
290
+ UiThreadUtil.runOnUiThread(this, 16);
291
+ return;
292
+ }
290
293
 
291
- activity.scheduleTaskAtStarted(() -> {
292
- FragmentManager fragmentManager = activity.getSupportFragmentManager();
293
- ArrayList<Bundle> graph = bridgeManager.buildRouteGraph(fragmentManager);
294
- if (graph.size() == 0) {
295
- UiThreadUtil.runOnUiThread(this, 16);
296
- return;
297
- }
298
-
299
- callback.invoke(null, Arguments.fromList(graph));
300
- });
294
+ callback.invoke(null, Arguments.fromList(graph));
301
295
  }
302
296
  };
303
297
 
@@ -68,7 +68,7 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
68
68
  public void inflateStyle() {
69
69
  Style style = getStyle();
70
70
  GlobalStyle globalStyle = Garden.getGlobalStyle();
71
- if (style != null && globalStyle != null && !isFinishing()) {
71
+ if (style != null && !isFinishing()) {
72
72
  styleInflated = true;
73
73
  FLog.i(TAG, "ReactAppCompatActivity#inflateStyle");
74
74
  globalStyle.inflateStyle(this, style);
@@ -160,7 +160,7 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
160
160
  }
161
161
  HBDEventEmitter.sendEvent(HBDEventEmitter.EVENT_DID_SET_ROOT, Arguments.createMap());
162
162
  }
163
-
163
+
164
164
  @Override
165
165
  protected void onPause() {
166
166
  activityDelegate.onPause();
@@ -177,7 +177,7 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
177
177
  }
178
178
  activityDelegate.onResume();
179
179
  }
180
-
180
+
181
181
  @Override
182
182
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
183
183
  activityDelegate.onActivityResult(requestCode, resultCode, data);
@@ -48,6 +48,9 @@ static GlobalStyle *globalStyle;
48
48
  }
49
49
 
50
50
  + (GlobalStyle *)globalStyle {
51
+ if (!globalStyle) {
52
+ [self createWithOptions:@{}];
53
+ }
51
54
  return globalStyle;
52
55
  }
53
56
 
@@ -238,18 +238,18 @@
238
238
  }
239
239
 
240
240
  if ([drawer.contentController isKindOfClass:[UITabBarController class]]) {
241
- UITabBarController *tabBar = (UITabBarController *) drawer.contentController;
242
- if ([tabBar.selectedViewController isKindOfClass:[UINavigationController class]]) {
243
- return (UINavigationController *)tabBar.selectedViewController;
241
+ UITabBarController *tabs = (UITabBarController *)drawer.contentController;
242
+ if ([tabs.selectedViewController isKindOfClass:[UINavigationController class]]) {
243
+ return (UINavigationController *)tabs.selectedViewController;
244
244
  }
245
245
  return nil;
246
246
  }
247
247
 
248
248
  if ([drawer.contentController isKindOfClass:[UINavigationController class]]) {
249
- return (UINavigationController *) drawer.contentController;
249
+ return (UINavigationController *)drawer.contentController;
250
250
  }
251
251
 
252
- return nil;
252
+ return drawer.contentController.navigationController;
253
253
  }
254
254
 
255
255
  -(void)handleNavigation:(NSDictionary *)params {
@@ -188,12 +188,8 @@ const NSInteger ResultCancel = 0;
188
188
  }
189
189
 
190
190
  - (UIViewController *)viewControllerBySceneId:(NSString *)sceneId {
191
- if (self.viewHierarchyReady) {
192
- UIWindow *window = [self mainWindow];
193
- return [self viewControllerWithSceneId:sceneId viewController:window.rootViewController];
194
- }
195
-
196
- return nil;
191
+ UIWindow *window = [self mainWindow];
192
+ return [self viewControllerWithSceneId:sceneId viewController:window.rootViewController];
197
193
  }
198
194
 
199
195
  - (UIViewController *)viewControllerWithSceneId:(NSString *)sceneId viewController:(UIViewController *)vc {
package/lib/DeepLink.d.ts CHANGED
@@ -1,7 +1,11 @@
1
- declare function activate(uriPrefix: string): void;
2
- declare function deactivate(): void;
3
- export declare const DeepLink: {
4
- activate: typeof activate;
5
- deactivate: typeof deactivate;
6
- };
1
+ declare class DeepLinkImpl {
2
+ private active;
3
+ private uriPrefix;
4
+ private hasHandleInitialURL;
5
+ private subscription;
6
+ activate(uriPrefix: string): void;
7
+ deactivate(): void;
8
+ private handleLinking;
9
+ }
10
+ export declare const DeepLink: DeepLinkImpl;
7
11
  export {};
package/lib/DeepLink.js CHANGED
@@ -1,55 +1,54 @@
1
1
  import { Linking } from 'react-native';
2
2
  import { router } from './router';
3
- let _active = 0;
4
- let _uriPrefix = '';
5
- let _hasHandleInitialURL = false;
6
- let _linkingSubscription;
7
- function activate(uriPrefix) {
8
- if (!uriPrefix) {
9
- throw new Error('must pass `uriPrefix` when activate router.');
10
- }
11
- if (_active === 0) {
12
- _uriPrefix = uriPrefix;
13
- if (!_hasHandleInitialURL) {
14
- _hasHandleInitialURL = true;
15
- Linking.getInitialURL()
16
- .then(url => {
17
- if (url) {
18
- console.info(`deeplink:${url}`);
19
- const path = url.replace(_uriPrefix, '');
20
- return router.open(path);
21
- }
22
- })
23
- .catch(err => console.error('An error occurred', err));
3
+ class DeepLinkImpl {
4
+ active = 0;
5
+ uriPrefix = '';
6
+ hasHandleInitialURL = false;
7
+ subscription = null;
8
+ activate(uriPrefix) {
9
+ if (!uriPrefix) {
10
+ throw new Error('must pass `uriPrefix` when activate router.');
11
+ }
12
+ if (this.active === 0) {
13
+ this.uriPrefix = uriPrefix;
14
+ if (!this.hasHandleInitialURL) {
15
+ this.hasHandleInitialURL = true;
16
+ Linking.getInitialURL()
17
+ .then(url => {
18
+ if (url) {
19
+ console.info(`deeplink:${url}`);
20
+ const path = url.replace(this.uriPrefix, '');
21
+ return router.open(path);
22
+ }
23
+ })
24
+ .catch(err => console.error('An error occurred', err));
25
+ }
26
+ this.subscription = Linking.addEventListener('url', this.handleLinking);
24
27
  }
25
- _linkingSubscription = Linking.addEventListener('url', handleLinking);
28
+ this.active++;
26
29
  }
27
- _active++;
28
- }
29
- function deactivate() {
30
- _active--;
31
- if (_active === 0) {
32
- if (_linkingSubscription) {
33
- _linkingSubscription.remove();
34
- _linkingSubscription = undefined;
30
+ deactivate() {
31
+ this.active--;
32
+ if (this.active === 0) {
33
+ if (this.subscription) {
34
+ this.subscription.remove();
35
+ this.subscription = null;
36
+ }
37
+ else {
38
+ Linking.removeEventListener('url', this.handleLinking);
39
+ }
35
40
  }
36
- else {
37
- Linking.removeEventListener('url', handleLinking);
41
+ if (this.active < 0) {
42
+ this.active = 0;
38
43
  }
39
44
  }
40
- if (_active < 0) {
41
- _active = 0;
42
- }
43
- }
44
- function handleLinking(event) {
45
- console.info(`deeplink:${event.url}`);
46
- let path = event.url.replace(_uriPrefix, '');
47
- if (!path.startsWith('/')) {
48
- path = '/' + path;
49
- }
50
- router.open(path);
45
+ handleLinking = (event) => {
46
+ console.info(`deeplink:${event.url}`);
47
+ let path = event.url.replace(this.uriPrefix, '');
48
+ if (!path.startsWith('/')) {
49
+ path = '/' + path;
50
+ }
51
+ router.open(path);
52
+ };
51
53
  }
52
- export const DeepLink = {
53
- activate,
54
- deactivate,
55
- };
54
+ export const DeepLink = new DeepLinkImpl();
package/lib/Route.d.ts CHANGED
@@ -72,7 +72,7 @@ export interface RouteHandler {
72
72
  /**
73
73
  * @param graph - current RouteGraph to process
74
74
  * @param target - route may add to the graph
75
- * @reurns [boolean, RouteGraph] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
75
+ * @returns [boolean, RouteGraph] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
76
76
  */
77
77
  process: (graph: RouteGraph, target: RouteInfo) => Promise<[boolean, RouteGraph | null]>;
78
78
  }
@@ -21,6 +21,7 @@ export declare type NavigationInterceptor = (action: string, params: InterceptPa
21
21
  export default class DispatchCommandHandler {
22
22
  private interceptor;
23
23
  dispatch(sceneId: string, action: string, params: DispatchParams): Promise<boolean>;
24
+ private intercept;
24
25
  setInterceptor(interceptor: NavigationInterceptor): void;
25
26
  }
26
27
  export {};
@@ -2,25 +2,26 @@ import NavigationModule from '../NavigationModule';
2
2
  export default class DispatchCommandHandler {
3
3
  interceptor = () => false;
4
4
  async dispatch(sceneId, action, params) {
5
- let intercepted = false;
6
5
  const { from, to } = params;
7
- if (this.interceptor) {
8
- const result = this.interceptor(action, {
9
- sceneId,
10
- from,
11
- to,
12
- });
13
- if (result instanceof Promise) {
14
- intercepted = await result;
15
- }
16
- else {
17
- intercepted = result;
18
- }
6
+ const intercepted = await this.intercept(action, {
7
+ sceneId,
8
+ from,
9
+ to,
10
+ });
11
+ if (intercepted) {
12
+ return false;
19
13
  }
20
- if (!intercepted) {
21
- return NavigationModule.dispatch(sceneId, action, params);
14
+ return NavigationModule.dispatch(sceneId, action, params);
15
+ }
16
+ intercept(action, params) {
17
+ if (!this.interceptor) {
18
+ return Promise.resolve(false);
19
+ }
20
+ const result = this.interceptor(action, params);
21
+ if (result instanceof Promise) {
22
+ return result;
22
23
  }
23
- return false;
24
+ return Promise.resolve(result);
24
25
  }
25
26
  setInterceptor(interceptor) {
26
27
  this.interceptor = interceptor;
@@ -1,21 +1,25 @@
1
1
  import { RouteHandler, RouteInterceptor } from '../Route';
2
2
  import { NavigationItem } from '../Options';
3
+ interface IndexType {
4
+ [index: string]: any;
5
+ }
3
6
  declare class Router {
4
7
  constructor();
5
8
  private handlers;
6
9
  registerRouteHandler(layout: string, handler: RouteHandler): void;
7
10
  private convertConfigToData;
8
11
  private isRouteConfigInflated;
9
- private routeDatas;
12
+ private routeDataSet;
10
13
  private inflateRouteData;
11
14
  private interceptors;
12
15
  addInterceptor(interceptor: RouteInterceptor): void;
13
16
  removeInterceptor(interceptor: RouteInterceptor): void;
14
17
  private intercept;
18
+ private resolveInterceptResult;
15
19
  private pathToRoute;
16
20
  private routeDependencies;
17
21
  private processRoute;
18
- open(path: string, props?: object, options?: NavigationItem): Promise<void>;
22
+ open(path: string, props?: IndexType, options?: NavigationItem): Promise<void>;
19
23
  }
20
24
  export declare const router: Router;
21
25
  export * from './drawer';
@@ -46,7 +46,7 @@ class Router {
46
46
  return { moduleName, mode, path, regexp, dependency };
47
47
  }
48
48
  isRouteConfigInflated = false;
49
- routeDatas = new Map();
49
+ routeDataSet = new Map();
50
50
  inflateRouteData() {
51
51
  if (this.isRouteConfigInflated) {
52
52
  return;
@@ -55,7 +55,7 @@ class Router {
55
55
  const routeConfigs = Navigation.routeConfigs();
56
56
  for (const [moduleName, config] of routeConfigs) {
57
57
  const data = this.convertConfigToData(moduleName, config);
58
- this.routeDatas.set(moduleName, data);
58
+ this.routeDataSet.set(moduleName, data);
59
59
  }
60
60
  }
61
61
  interceptors = [];
@@ -68,14 +68,21 @@ class Router {
68
68
  async intercept(path) {
69
69
  for (let interceptor of this.interceptors.values()) {
70
70
  const result = interceptor(path);
71
- if (result instanceof Promise) {
72
- return await result;
71
+ const intercepted = await this.resolveInterceptResult(result);
72
+ if (intercepted) {
73
+ return true;
73
74
  }
75
+ }
76
+ return false;
77
+ }
78
+ resolveInterceptResult(result) {
79
+ if (result instanceof Promise) {
74
80
  return result;
75
81
  }
82
+ return Promise.resolve(result);
76
83
  }
77
84
  pathToRoute(path, props, options) {
78
- for (const data of this.routeDatas.values()) {
85
+ for (const data of this.routeDataSet.values()) {
79
86
  if (!data.regexp) {
80
87
  continue;
81
88
  }
@@ -96,7 +103,7 @@ class Router {
96
103
  let data = routeData;
97
104
  while (data && data.dependency) {
98
105
  dependencies.push(data.dependency);
99
- data = this.routeDatas.get(data.dependency);
106
+ data = this.routeDataSet.get(data.dependency);
100
107
  }
101
108
  return dependencies.reverse();
102
109
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hybrid-navigation",
3
3
  "description": "React Native Navigation that supports seamless navigation between Native and React.",
4
- "version": "2.13.3",
4
+ "version": "2.13.6",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
7
7
  "react-native": "src/index",
@@ -69,7 +69,7 @@
69
69
  "react-test-renderer": "17.0.2",
70
70
  "redux": "^4.1.1",
71
71
  "typescript": "^4.6.4",
72
- "vuepress": "^2.0.0-beta.49",
72
+ "vuepress": "2.0.0-beta.51",
73
73
  "zustand": "^3.7.1"
74
74
  }
75
75
  }
package/src/DeepLink.ts CHANGED
@@ -1,60 +1,59 @@
1
1
  import { EmitterSubscription, Linking } from 'react-native'
2
2
  import { router } from './router'
3
3
 
4
- let _active = 0
5
- let _uriPrefix: string = ''
6
- let _hasHandleInitialURL = false
7
- let _linkingSubscription: EmitterSubscription | undefined
4
+ class DeepLinkImpl {
5
+ private active = 0
6
+ private uriPrefix = ''
7
+ private hasHandleInitialURL = false
8
+ private subscription: EmitterSubscription | null = null
8
9
 
9
- function activate(uriPrefix: string) {
10
- if (!uriPrefix) {
11
- throw new Error('must pass `uriPrefix` when activate router.')
12
- }
13
- if (_active === 0) {
14
- _uriPrefix = uriPrefix
15
- if (!_hasHandleInitialURL) {
16
- _hasHandleInitialURL = true
17
- Linking.getInitialURL()
18
- .then(url => {
19
- if (url) {
20
- console.info(`deeplink:${url}`)
21
- const path = url.replace(_uriPrefix, '')
22
- return router.open(path)
23
- }
24
- })
25
- .catch(err => console.error('An error occurred', err))
10
+ activate(uriPrefix: string) {
11
+ if (!uriPrefix) {
12
+ throw new Error('must pass `uriPrefix` when activate router.')
13
+ }
14
+ if (this.active === 0) {
15
+ this.uriPrefix = uriPrefix
16
+ if (!this.hasHandleInitialURL) {
17
+ this.hasHandleInitialURL = true
18
+ Linking.getInitialURL()
19
+ .then(url => {
20
+ if (url) {
21
+ console.info(`deeplink:${url}`)
22
+ const path = url.replace(this.uriPrefix, '')
23
+ return router.open(path)
24
+ }
25
+ })
26
+ .catch(err => console.error('An error occurred', err))
27
+ }
28
+ this.subscription = Linking.addEventListener('url', this.handleLinking)
26
29
  }
27
- _linkingSubscription = Linking.addEventListener('url', handleLinking)
30
+ this.active++
28
31
  }
29
- _active++
30
- }
31
32
 
32
- function deactivate() {
33
- _active--
34
- if (_active === 0) {
35
- if (_linkingSubscription) {
36
- _linkingSubscription.remove()
37
- _linkingSubscription = undefined
38
- } else {
39
- Linking.removeEventListener('url', handleLinking)
33
+ deactivate() {
34
+ this.active--
35
+ if (this.active === 0) {
36
+ if (this.subscription) {
37
+ this.subscription.remove()
38
+ this.subscription = null
39
+ } else {
40
+ Linking.removeEventListener('url', this.handleLinking)
41
+ }
40
42
  }
41
- }
42
43
 
43
- if (_active < 0) {
44
- _active = 0
44
+ if (this.active < 0) {
45
+ this.active = 0
46
+ }
45
47
  }
46
- }
47
48
 
48
- function handleLinking(event: { url: string }): void {
49
- console.info(`deeplink:${event.url}`)
50
- let path = event.url.replace(_uriPrefix, '')
51
- if (!path.startsWith('/')) {
52
- path = '/' + path
49
+ private handleLinking = (event: { url: string }) => {
50
+ console.info(`deeplink:${event.url}`)
51
+ let path = event.url.replace(this.uriPrefix, '')
52
+ if (!path.startsWith('/')) {
53
+ path = '/' + path
54
+ }
55
+ router.open(path)
53
56
  }
54
- router.open(path)
55
57
  }
56
58
 
57
- export const DeepLink = {
58
- activate,
59
- deactivate,
60
- }
59
+ export const DeepLink = new DeepLinkImpl()
package/src/Route.ts CHANGED
@@ -85,7 +85,7 @@ export interface RouteHandler {
85
85
  /**
86
86
  * @param graph - current RouteGraph to process
87
87
  * @param target - route may add to the graph
88
- * @reurns [boolean, RouteGraph] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
88
+ * @returns [boolean, RouteGraph] - if the route is handled, return true and childGraph for next Handler to process, [false, graph] otherwise
89
89
  */
90
90
  process: (graph: RouteGraph, target: RouteInfo) => Promise<[boolean, RouteGraph | null]>
91
91
  }
@@ -30,26 +30,29 @@ export default class DispatchCommandHandler {
30
30
  private interceptor: NavigationInterceptor = () => false
31
31
 
32
32
  async dispatch(sceneId: string, action: string, params: DispatchParams): Promise<boolean> {
33
- let intercepted = false
34
33
  const { from, to } = params
35
- if (this.interceptor) {
36
- const result = this.interceptor(action, {
37
- sceneId,
38
- from,
39
- to,
40
- })
41
- if (result instanceof Promise) {
42
- intercepted = await result
43
- } else {
44
- intercepted = result
45
- }
34
+ const intercepted = await this.intercept(action, {
35
+ sceneId,
36
+ from,
37
+ to,
38
+ })
39
+
40
+ if (intercepted) {
41
+ return false
46
42
  }
43
+ return NavigationModule.dispatch(sceneId, action, params)
44
+ }
47
45
 
48
- if (!intercepted) {
49
- return NavigationModule.dispatch(sceneId, action, params)
46
+ private intercept(action: string, params: InterceptParams) {
47
+ if (!this.interceptor) {
48
+ return Promise.resolve(false)
50
49
  }
51
50
 
52
- return false
51
+ const result = this.interceptor(action, params)
52
+ if (result instanceof Promise) {
53
+ return result
54
+ }
55
+ return Promise.resolve(result)
53
56
  }
54
57
 
55
58
  setInterceptor(interceptor: NavigationInterceptor) {
@@ -66,7 +66,7 @@ class Router {
66
66
  }
67
67
 
68
68
  private isRouteConfigInflated = false
69
- private routeDatas = new Map<string, RouteData>()
69
+ private routeDataSet = new Map<string, RouteData>()
70
70
 
71
71
  private inflateRouteData() {
72
72
  if (this.isRouteConfigInflated) {
@@ -76,7 +76,7 @@ class Router {
76
76
  const routeConfigs = Navigation.routeConfigs()
77
77
  for (const [moduleName, config] of routeConfigs) {
78
78
  const data = this.convertConfigToData(moduleName, config)
79
- this.routeDatas.set(moduleName, data)
79
+ this.routeDataSet.set(moduleName, data)
80
80
  }
81
81
  }
82
82
 
@@ -93,15 +93,23 @@ class Router {
93
93
  private async intercept(path: string) {
94
94
  for (let interceptor of this.interceptors.values()) {
95
95
  const result = interceptor(path)
96
- if (result instanceof Promise) {
97
- return await result
96
+ const intercepted = await this.resolveInterceptResult(result)
97
+ if (intercepted) {
98
+ return true
98
99
  }
100
+ }
101
+ return false
102
+ }
103
+
104
+ private resolveInterceptResult(result: boolean | Promise<boolean>) {
105
+ if (result instanceof Promise) {
99
106
  return result
100
107
  }
108
+ return Promise.resolve(result)
101
109
  }
102
110
 
103
111
  private pathToRoute(path: string, props: object, options: NavigationItem): RouteInfo | undefined {
104
- for (const data of this.routeDatas.values()) {
112
+ for (const data of this.routeDataSet.values()) {
105
113
  if (!data.regexp) {
106
114
  continue
107
115
  }
@@ -125,7 +133,7 @@ class Router {
125
133
  let data: RouteData | undefined = routeData
126
134
  while (data && data.dependency) {
127
135
  dependencies.push(data.dependency)
128
- data = this.routeDatas.get(data.dependency)
136
+ data = this.routeDataSet.get(data.dependency)
129
137
  }
130
138
  return dependencies.reverse()
131
139
  }
@@ -143,7 +151,7 @@ class Router {
143
151
  return consumed
144
152
  }
145
153
 
146
- async open(path: string, props: object = {}, options: NavigationItem = {}) {
154
+ async open(path: string, props: IndexType = {}, options: NavigationItem = {}) {
147
155
  this.inflateRouteData()
148
156
 
149
157
  const intercepted = await this.intercept(path)