hybrid-navigation 2.13.4 → 2.13.5

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.
@@ -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
  }
@@ -256,21 +256,19 @@ public class NavigationModule extends ReactContextBaseJavaModule {
256
256
  UiThreadUtil.runOnUiThread(this, 16);
257
257
  return;
258
258
  }
259
+
260
+ FragmentManager fragmentManager = activity.getSupportFragmentManager();
261
+ HybridFragment current = bridgeManager.primaryFragment(fragmentManager);
262
+ if (current == null) {
263
+ UiThreadUtil.runOnUiThread(this, 16);
264
+ return;
265
+ }
259
266
 
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
- });
267
+ Bundle bundle = new Bundle();
268
+ bundle.putString("moduleName", current.getModuleName());
269
+ bundle.putString("sceneId", current.getSceneId());
270
+ bundle.putString("mode", Navigator.Util.getMode(current));
271
+ callback.invoke(null, Arguments.fromBundle(bundle));
274
272
  }
275
273
  };
276
274
 
@@ -287,17 +285,15 @@ public class NavigationModule extends ReactContextBaseJavaModule {
287
285
  UiThreadUtil.runOnUiThread(this, 16);
288
286
  return;
289
287
  }
288
+
289
+ FragmentManager fragmentManager = activity.getSupportFragmentManager();
290
+ ArrayList<Bundle> graph = bridgeManager.buildRouteGraph(fragmentManager);
291
+ if (graph.size() == 0) {
292
+ UiThreadUtil.runOnUiThread(this, 16);
293
+ return;
294
+ }
290
295
 
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
- });
296
+ callback.invoke(null, Arguments.fromList(graph));
301
297
  }
302
298
  };
303
299
 
@@ -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;
@@ -6,12 +6,13 @@ declare class Router {
6
6
  registerRouteHandler(layout: string, handler: RouteHandler): void;
7
7
  private convertConfigToData;
8
8
  private isRouteConfigInflated;
9
- private routeDatas;
9
+ private routeDataSet;
10
10
  private inflateRouteData;
11
11
  private interceptors;
12
12
  addInterceptor(interceptor: RouteInterceptor): void;
13
13
  removeInterceptor(interceptor: RouteInterceptor): void;
14
14
  private intercept;
15
+ private resolveInterceptResult;
15
16
  private pathToRoute;
16
17
  private routeDependencies;
17
18
  private processRoute;
@@ -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.4",
4
+ "version": "2.13.5",
5
5
  "main": "./lib/index.js",
6
6
  "typings": "./lib/index.d.ts",
7
7
  "react-native": "src/index",
@@ -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
  }