hybrid-navigation 2.13.4 → 2.13.7
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.
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +4 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +34 -40
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +18 -5
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +10 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +9 -3
- package/ios/HybridNavigation/GlobalStyle.m +3 -0
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +7 -2
- package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.m +2 -6
- package/lib/DeepLink.d.ts +10 -6
- package/lib/DeepLink.js +46 -47
- package/lib/NavigationComponentWrap.js +2 -1
- package/lib/Navigator.d.ts +1 -7
- package/lib/Navigator.js +4 -10
- package/lib/Route.d.ts +1 -1
- package/lib/handler/DispatchCommandHandler.d.ts +1 -0
- package/lib/handler/DispatchCommandHandler.js +17 -16
- package/lib/router/index.d.ts +6 -2
- package/lib/router/index.js +18 -11
- package/package.json +2 -2
- package/src/DeepLink.ts +45 -46
- package/src/NavigationComponentWrap.tsx +2 -1
- package/src/Navigator.ts +5 -12
- package/src/Route.ts +1 -1
- package/src/handler/DispatchCommandHandler.ts +18 -15
- package/src/router/index.ts +21 -12
|
@@ -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
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
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 &&
|
|
71
|
+
if (style != null && !isFinishing()) {
|
|
72
72
|
styleInflated = true;
|
|
73
73
|
FLog.i(TAG, "ReactAppCompatActivity#inflateStyle");
|
|
74
74
|
globalStyle.inflateStyle(this, style);
|
|
@@ -85,6 +85,10 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
|
|
|
85
85
|
@Override
|
|
86
86
|
public void onReactModuleRegisterCompleted() {
|
|
87
87
|
FLog.i(TAG, "ReactAppCompatActivity#onReactModuleRegisterCompleted");
|
|
88
|
+
if (!isFirstCallResume) {
|
|
89
|
+
isFirstCallResume = true;
|
|
90
|
+
activityDelegate.onResume();
|
|
91
|
+
}
|
|
88
92
|
createMainComponent();
|
|
89
93
|
}
|
|
90
94
|
|
|
@@ -160,24 +164,33 @@ public class ReactAppCompatActivity extends AwesomeActivity implements DefaultHa
|
|
|
160
164
|
}
|
|
161
165
|
HBDEventEmitter.sendEvent(HBDEventEmitter.EVENT_DID_SET_ROOT, Arguments.createMap());
|
|
162
166
|
}
|
|
163
|
-
|
|
167
|
+
|
|
164
168
|
@Override
|
|
165
169
|
protected void onPause() {
|
|
166
|
-
|
|
170
|
+
ReactContext reactContext = getCurrentReactContext();
|
|
171
|
+
if (reactContext != null) {
|
|
172
|
+
activityDelegate.onPause();
|
|
173
|
+
}
|
|
167
174
|
super.onPause();
|
|
168
175
|
}
|
|
169
176
|
|
|
177
|
+
private boolean isFirstCallResume;
|
|
178
|
+
|
|
170
179
|
@Override
|
|
171
180
|
protected void onResume() {
|
|
172
181
|
super.onResume();
|
|
182
|
+
if (getReactInstanceManager().hasStartedCreatingInitialContext()) {
|
|
183
|
+
isFirstCallResume = true;
|
|
184
|
+
activityDelegate.onResume();
|
|
185
|
+
}
|
|
186
|
+
|
|
173
187
|
ReactBridgeManager bridgeManager = getReactBridgeManager();
|
|
174
188
|
if (bridgeManager.hasPendingLayout()) {
|
|
175
189
|
FLog.i(TAG, "Set root Fragment from pending layout when resume.");
|
|
176
190
|
setActivityRootFragment(bridgeManager.getPendingLayout());
|
|
177
191
|
}
|
|
178
|
-
activityDelegate.onResume();
|
|
179
192
|
}
|
|
180
|
-
|
|
193
|
+
|
|
181
194
|
@Override
|
|
182
195
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
183
196
|
activityDelegate.onActivityResult(requestCode, resultCode, data);
|
|
@@ -60,11 +60,15 @@ public class ReactBridgeManager {
|
|
|
60
60
|
private ReactNativeHost reactNativeHost;
|
|
61
61
|
|
|
62
62
|
public void install(@NonNull ReactNativeHost reactNativeHost) {
|
|
63
|
+
this.setReactNativeHost(reactNativeHost);
|
|
64
|
+
this.initialize();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public void setReactNativeHost(@NonNull ReactNativeHost reactNativeHost) {
|
|
63
68
|
this.reactNativeHost = reactNativeHost;
|
|
64
|
-
this.setup();
|
|
65
69
|
}
|
|
66
70
|
|
|
67
|
-
|
|
71
|
+
public void initialize() {
|
|
68
72
|
final ReactInstanceManager reactInstanceManager = getReactInstanceManager();
|
|
69
73
|
reactInstanceManager.addReactInstanceEventListener(context -> {
|
|
70
74
|
FLog.i(TAG, "React instance context initialized.");
|
|
@@ -248,13 +252,13 @@ public class ReactBridgeManager {
|
|
|
248
252
|
AwesomeFragment fragment = fragments.get(i);
|
|
249
253
|
Bundle bundle = buildRouteGraph(fragment);
|
|
250
254
|
if (bundle == null) {
|
|
251
|
-
|
|
255
|
+
continue;
|
|
252
256
|
}
|
|
253
257
|
root.add(bundle);
|
|
254
258
|
}
|
|
255
259
|
return root;
|
|
256
260
|
}
|
|
257
|
-
|
|
261
|
+
|
|
258
262
|
@Nullable
|
|
259
263
|
public Bundle buildRouteGraph(@NonNull AwesomeFragment fragment) {
|
|
260
264
|
String layout = navigatorRegistry.layoutForFragment(fragment);
|
|
@@ -366,7 +370,7 @@ public class ReactBridgeManager {
|
|
|
366
370
|
args.putBundle(Constants.ARG_PROPS, notNull(props));
|
|
367
371
|
args.putBundle(Constants.ARG_OPTIONS, mergeOptions(moduleName, notNull(options)));
|
|
368
372
|
args.putString(Constants.ARG_MODULE_NAME, moduleName);
|
|
369
|
-
|
|
373
|
+
|
|
370
374
|
fragment.setArguments(args);
|
|
371
375
|
|
|
372
376
|
return fragment;
|
|
@@ -383,7 +387,7 @@ public class ReactBridgeManager {
|
|
|
383
387
|
if (!hasReactModule(moduleName)) {
|
|
384
388
|
return options;
|
|
385
389
|
}
|
|
386
|
-
|
|
390
|
+
|
|
387
391
|
ReadableMap readableMap = reactModuleOptionsForKey(moduleName);
|
|
388
392
|
WritableMap writableMap = Arguments.createMap();
|
|
389
393
|
writableMap.merge(readableMap);
|
package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java
CHANGED
|
@@ -165,10 +165,9 @@ public class StackNavigator implements Navigator {
|
|
|
165
165
|
callback.invoke(null, false);
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
|
-
|
|
169
|
-
boolean inclusive = extras.getBoolean("inclusive");
|
|
168
|
+
|
|
170
169
|
FragmentManager fragmentManager = stackFragment.getChildFragmentManager();
|
|
171
|
-
AwesomeFragment fragment = findFragmentForPopTo(moduleName, inclusive, fragmentManager);
|
|
170
|
+
AwesomeFragment fragment = findFragmentForPopTo(moduleName, inclusive(extras), fragmentManager);
|
|
172
171
|
if (fragment == null) {
|
|
173
172
|
callback.invoke(null, false);
|
|
174
173
|
return;
|
|
@@ -176,6 +175,13 @@ public class StackNavigator implements Navigator {
|
|
|
176
175
|
|
|
177
176
|
stackFragment.popToFragment(fragment, () -> callback.invoke(null, true));
|
|
178
177
|
}
|
|
178
|
+
|
|
179
|
+
private boolean inclusive(@NonNull ReadableMap extras) {
|
|
180
|
+
if (extras.hasKey("inclusive")) {
|
|
181
|
+
return extras.getBoolean("inclusive");
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
179
185
|
|
|
180
186
|
@Nullable
|
|
181
187
|
private AwesomeFragment findFragmentForPopTo(String moduleName, boolean inclusive, FragmentManager fragmentManager) {
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
#import "UINavigationController+HBD.h"
|
|
6
6
|
#import "HBDAnimationObserver.h"
|
|
7
7
|
|
|
8
|
+
#import <React/RCTLog.h>
|
|
9
|
+
|
|
8
10
|
@implementation HBDStackNavigator
|
|
9
11
|
|
|
10
12
|
- (NSString *)name {
|
|
@@ -72,7 +74,10 @@
|
|
|
72
74
|
[nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
73
75
|
// empty
|
|
74
76
|
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
75
|
-
|
|
77
|
+
// 确保最后执行
|
|
78
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
79
|
+
[self handleNavigationWithViewController:vc action:action extras:extras callback:callback];
|
|
80
|
+
});
|
|
76
81
|
}];
|
|
77
82
|
return;
|
|
78
83
|
}
|
|
@@ -124,7 +129,7 @@
|
|
|
124
129
|
callback(@[NSNull.null, @NO]);
|
|
125
130
|
return;
|
|
126
131
|
}
|
|
127
|
-
|
|
132
|
+
|
|
128
133
|
vc.hidesBottomBarWhenPushed = nav.hidesBottomBarWhenPushed;
|
|
129
134
|
[[HBDAnimationObserver sharedObserver] beginAnimation];
|
|
130
135
|
[nav pushViewController:vc animated:YES];
|
|
@@ -188,12 +188,8 @@ const NSInteger ResultCancel = 0;
|
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
- (UIViewController *)viewControllerBySceneId:(NSString *)sceneId {
|
|
191
|
-
|
|
192
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
28
|
+
this.active++;
|
|
26
29
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
37
|
-
|
|
41
|
+
if (this.active < 0) {
|
|
42
|
+
this.active = 0;
|
|
38
43
|
}
|
|
39
44
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
2
|
import { Navigator, NavigationContext } from './Navigator';
|
|
3
|
+
import Navigation from './Navigation';
|
|
3
4
|
function getDisplayName(WrappedComponent) {
|
|
4
5
|
return WrappedComponent.displayName || WrappedComponent.name || 'Component';
|
|
5
6
|
}
|
|
@@ -13,7 +14,7 @@ export function withNavigation(moduleName) {
|
|
|
13
14
|
}
|
|
14
15
|
const garden = navigator.garden;
|
|
15
16
|
useEffect(() => {
|
|
16
|
-
|
|
17
|
+
Navigation.signalFirstRenderComplete(navigator.sceneId);
|
|
17
18
|
return () => {
|
|
18
19
|
navigator.unmount();
|
|
19
20
|
};
|
package/lib/Navigator.d.ts
CHANGED
|
@@ -18,13 +18,8 @@ export declare class Navigator implements Navigator {
|
|
|
18
18
|
sceneId: string;
|
|
19
19
|
moduleName?: string | undefined;
|
|
20
20
|
static of(sceneId: string): Navigator;
|
|
21
|
-
static current(): Promise<Navigator>;
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
|
|
24
|
-
* @param moduleName
|
|
25
|
-
* @returns
|
|
26
|
-
*/
|
|
27
21
|
static find(moduleName: string): Promise<Navigator | undefined>;
|
|
22
|
+
static current(): Promise<Navigator>;
|
|
28
23
|
/**
|
|
29
24
|
* @deprecated Use Navigation.currentRoute() instead
|
|
30
25
|
* @returns
|
|
@@ -90,6 +85,5 @@ export declare class Navigator implements Navigator {
|
|
|
90
85
|
openMenu: () => Promise<boolean>;
|
|
91
86
|
closeMenu: () => Promise<boolean>;
|
|
92
87
|
isStackRoot: () => Promise<boolean>;
|
|
93
|
-
signalFirstRenderComplete: () => void;
|
|
94
88
|
}
|
|
95
89
|
export {};
|
package/lib/Navigator.js
CHANGED
|
@@ -25,21 +25,16 @@ export class Navigator {
|
|
|
25
25
|
}
|
|
26
26
|
return navigator;
|
|
27
27
|
}
|
|
28
|
-
static async current() {
|
|
29
|
-
const route = await Navigation.currentRoute();
|
|
30
|
-
return Navigator.of(route.sceneId);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
|
|
34
|
-
* @param moduleName
|
|
35
|
-
* @returns
|
|
36
|
-
*/
|
|
37
28
|
static async find(moduleName) {
|
|
38
29
|
const sceneId = await Navigation.findSceneIdByModuleName(moduleName);
|
|
39
30
|
if (sceneId) {
|
|
40
31
|
return Navigator.of(sceneId);
|
|
41
32
|
}
|
|
42
33
|
}
|
|
34
|
+
static async current() {
|
|
35
|
+
const route = await Navigation.currentRoute();
|
|
36
|
+
return Navigator.of(route.sceneId);
|
|
37
|
+
}
|
|
43
38
|
/**
|
|
44
39
|
* @deprecated Use Navigation.currentRoute() instead
|
|
45
40
|
* @returns
|
|
@@ -210,5 +205,4 @@ export class Navigator {
|
|
|
210
205
|
openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', { from: this.moduleName });
|
|
211
206
|
closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName });
|
|
212
207
|
isStackRoot = () => Navigation.isStackRoot(this.sceneId);
|
|
213
|
-
signalFirstRenderComplete = () => Navigation.signalFirstRenderComplete(this.sceneId);
|
|
214
208
|
}
|
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
|
-
* @
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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
|
|
24
|
+
return Promise.resolve(result);
|
|
24
25
|
}
|
|
25
26
|
setInterceptor(interceptor) {
|
|
26
27
|
this.interceptor = interceptor;
|
package/lib/router/index.d.ts
CHANGED
|
@@ -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
|
|
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?:
|
|
22
|
+
open(path: string, props?: IndexType, options?: NavigationItem): Promise<void>;
|
|
19
23
|
}
|
|
20
24
|
export declare const router: Router;
|
|
21
25
|
export * from './drawer';
|
package/lib/router/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { pathToRegexp, match } from 'path-to-regexp';
|
|
2
|
-
import Navigation from '../Navigation';
|
|
3
2
|
import { StackRouteHandler } from './stack';
|
|
4
3
|
import { ScreenRouteHandler } from './screen';
|
|
5
4
|
import { TabsRouteHandler } from './tabs';
|
|
6
5
|
import { DrawerRouteHandler } from './drawer';
|
|
6
|
+
import Navigation from '../Navigation';
|
|
7
7
|
function pathParams(path) {
|
|
8
8
|
const pathMatch = match(path, {
|
|
9
9
|
encode: encodeURI,
|
|
@@ -46,7 +46,7 @@ class Router {
|
|
|
46
46
|
return { moduleName, mode, path, regexp, dependency };
|
|
47
47
|
}
|
|
48
48
|
isRouteConfigInflated = false;
|
|
49
|
-
|
|
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.
|
|
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
|
-
|
|
72
|
-
|
|
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.
|
|
85
|
+
for (const data of this.routeDataSet.values()) {
|
|
79
86
|
if (!data.regexp) {
|
|
80
87
|
continue;
|
|
81
88
|
}
|
|
@@ -96,18 +103,18 @@ class Router {
|
|
|
96
103
|
let data = routeData;
|
|
97
104
|
while (data && data.dependency) {
|
|
98
105
|
dependencies.push(data.dependency);
|
|
99
|
-
data = this.
|
|
106
|
+
data = this.routeDataSet.get(data.dependency);
|
|
100
107
|
}
|
|
101
108
|
return dependencies.reverse();
|
|
102
109
|
}
|
|
103
|
-
async processRoute(
|
|
110
|
+
async processRoute(graph, target) {
|
|
104
111
|
const handler = this.handlers.get(graph.layout);
|
|
105
112
|
if (!handler) {
|
|
106
113
|
return false;
|
|
107
114
|
}
|
|
108
|
-
const [consumed, childGraph] = await handler.process(graph,
|
|
115
|
+
const [consumed, childGraph] = await handler.process(graph, target);
|
|
109
116
|
if (consumed && childGraph) {
|
|
110
|
-
return await this.processRoute(
|
|
117
|
+
return await this.processRoute(childGraph, target);
|
|
111
118
|
}
|
|
112
119
|
return consumed;
|
|
113
120
|
}
|
|
@@ -138,7 +145,7 @@ class Router {
|
|
|
138
145
|
}
|
|
139
146
|
}
|
|
140
147
|
const routeGraph = graphArray[0];
|
|
141
|
-
const consumed = await this.processRoute(
|
|
148
|
+
const consumed = await this.processRoute(routeGraph, route);
|
|
142
149
|
if (consumed) {
|
|
143
150
|
return;
|
|
144
151
|
}
|
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
|
+
"version": "2.13.7",
|
|
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": "
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
class DeepLinkImpl {
|
|
5
|
+
private active = 0
|
|
6
|
+
private uriPrefix = ''
|
|
7
|
+
private hasHandleInitialURL = false
|
|
8
|
+
private subscription: EmitterSubscription | null = null
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
30
|
+
this.active++
|
|
28
31
|
}
|
|
29
|
-
_active++
|
|
30
|
-
}
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
44
|
-
|
|
44
|
+
if (this.active < 0) {
|
|
45
|
+
this.active = 0
|
|
46
|
+
}
|
|
45
47
|
}
|
|
46
|
-
}
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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()
|
|
@@ -2,6 +2,7 @@ import React, { useEffect } from 'react'
|
|
|
2
2
|
import type { Garden } from './Garden'
|
|
3
3
|
import type { NavigationItem } from './Options'
|
|
4
4
|
import { Navigator, NavigationContext } from './Navigator'
|
|
5
|
+
import Navigation from './Navigation'
|
|
5
6
|
|
|
6
7
|
export interface NavigationProps {
|
|
7
8
|
navigator: Navigator
|
|
@@ -35,7 +36,7 @@ export function withNavigation(moduleName: string) {
|
|
|
35
36
|
const garden = navigator.garden
|
|
36
37
|
|
|
37
38
|
useEffect(() => {
|
|
38
|
-
|
|
39
|
+
Navigation.signalFirstRenderComplete(navigator.sceneId)
|
|
39
40
|
return () => {
|
|
40
41
|
navigator.unmount()
|
|
41
42
|
}
|
package/src/Navigator.ts
CHANGED
|
@@ -47,16 +47,6 @@ export class Navigator implements Navigator {
|
|
|
47
47
|
return navigator
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
static async current(): Promise<Navigator> {
|
|
51
|
-
const route = await Navigation.currentRoute()
|
|
52
|
-
return Navigator.of(route.sceneId)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @deprecated Garden is deprecated, use Navigation.findSceneIdByModuleName() instead.
|
|
57
|
-
* @param moduleName
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
60
50
|
static async find(moduleName: string) {
|
|
61
51
|
const sceneId = await Navigation.findSceneIdByModuleName(moduleName)
|
|
62
52
|
if (sceneId) {
|
|
@@ -64,6 +54,11 @@ export class Navigator implements Navigator {
|
|
|
64
54
|
}
|
|
65
55
|
}
|
|
66
56
|
|
|
57
|
+
static async current(): Promise<Navigator> {
|
|
58
|
+
const route = await Navigation.currentRoute()
|
|
59
|
+
return Navigator.of(route.sceneId)
|
|
60
|
+
}
|
|
61
|
+
|
|
67
62
|
/**
|
|
68
63
|
* @deprecated Use Navigation.currentRoute() instead
|
|
69
64
|
* @returns
|
|
@@ -284,6 +279,4 @@ export class Navigator implements Navigator {
|
|
|
284
279
|
closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName })
|
|
285
280
|
|
|
286
281
|
isStackRoot = () => Navigation.isStackRoot(this.sceneId)
|
|
287
|
-
|
|
288
|
-
signalFirstRenderComplete = () => Navigation.signalFirstRenderComplete(this.sceneId)
|
|
289
282
|
}
|
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
|
-
* @
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
49
|
-
|
|
46
|
+
private intercept(action: string, params: InterceptParams) {
|
|
47
|
+
if (!this.interceptor) {
|
|
48
|
+
return Promise.resolve(false)
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
|
|
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) {
|
package/src/router/index.ts
CHANGED
|
@@ -8,12 +8,13 @@ import {
|
|
|
8
8
|
RouteInterceptor,
|
|
9
9
|
} from '../Route'
|
|
10
10
|
import { NavigationItem } from '../Options'
|
|
11
|
-
import Navigation from '../Navigation'
|
|
12
11
|
import { StackRouteHandler } from './stack'
|
|
13
12
|
import { ScreenRouteHandler } from './screen'
|
|
14
13
|
import { TabsRouteHandler } from './tabs'
|
|
15
14
|
import { DrawerRouteHandler } from './drawer'
|
|
16
15
|
|
|
16
|
+
import Navigation from '../Navigation'
|
|
17
|
+
|
|
17
18
|
interface IndexType {
|
|
18
19
|
[index: string]: any
|
|
19
20
|
}
|
|
@@ -66,7 +67,7 @@ class Router {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
private isRouteConfigInflated = false
|
|
69
|
-
private
|
|
70
|
+
private routeDataSet = new Map<string, RouteData>()
|
|
70
71
|
|
|
71
72
|
private inflateRouteData() {
|
|
72
73
|
if (this.isRouteConfigInflated) {
|
|
@@ -76,7 +77,7 @@ class Router {
|
|
|
76
77
|
const routeConfigs = Navigation.routeConfigs()
|
|
77
78
|
for (const [moduleName, config] of routeConfigs) {
|
|
78
79
|
const data = this.convertConfigToData(moduleName, config)
|
|
79
|
-
this.
|
|
80
|
+
this.routeDataSet.set(moduleName, data)
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
|
|
@@ -93,15 +94,23 @@ class Router {
|
|
|
93
94
|
private async intercept(path: string) {
|
|
94
95
|
for (let interceptor of this.interceptors.values()) {
|
|
95
96
|
const result = interceptor(path)
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
const intercepted = await this.resolveInterceptResult(result)
|
|
98
|
+
if (intercepted) {
|
|
99
|
+
return true
|
|
98
100
|
}
|
|
101
|
+
}
|
|
102
|
+
return false
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private resolveInterceptResult(result: boolean | Promise<boolean>) {
|
|
106
|
+
if (result instanceof Promise) {
|
|
99
107
|
return result
|
|
100
108
|
}
|
|
109
|
+
return Promise.resolve(result)
|
|
101
110
|
}
|
|
102
111
|
|
|
103
112
|
private pathToRoute(path: string, props: object, options: NavigationItem): RouteInfo | undefined {
|
|
104
|
-
for (const data of this.
|
|
113
|
+
for (const data of this.routeDataSet.values()) {
|
|
105
114
|
if (!data.regexp) {
|
|
106
115
|
continue
|
|
107
116
|
}
|
|
@@ -125,25 +134,25 @@ class Router {
|
|
|
125
134
|
let data: RouteData | undefined = routeData
|
|
126
135
|
while (data && data.dependency) {
|
|
127
136
|
dependencies.push(data.dependency)
|
|
128
|
-
data = this.
|
|
137
|
+
data = this.routeDataSet.get(data.dependency)
|
|
129
138
|
}
|
|
130
139
|
return dependencies.reverse()
|
|
131
140
|
}
|
|
132
141
|
|
|
133
|
-
private async processRoute(
|
|
142
|
+
private async processRoute(graph: RouteGraph, target: RouteInfo): Promise<boolean> {
|
|
134
143
|
const handler = this.handlers.get(graph.layout)
|
|
135
144
|
if (!handler) {
|
|
136
145
|
return false
|
|
137
146
|
}
|
|
138
147
|
|
|
139
|
-
const [consumed, childGraph] = await handler.process(graph,
|
|
148
|
+
const [consumed, childGraph] = await handler.process(graph, target)
|
|
140
149
|
if (consumed && childGraph) {
|
|
141
|
-
return await this.processRoute(
|
|
150
|
+
return await this.processRoute(childGraph, target)
|
|
142
151
|
}
|
|
143
152
|
return consumed
|
|
144
153
|
}
|
|
145
154
|
|
|
146
|
-
async open(path: string, props:
|
|
155
|
+
async open(path: string, props: IndexType = {}, options: NavigationItem = {}) {
|
|
147
156
|
this.inflateRouteData()
|
|
148
157
|
|
|
149
158
|
const intercepted = await this.intercept(path)
|
|
@@ -173,7 +182,7 @@ class Router {
|
|
|
173
182
|
|
|
174
183
|
const routeGraph = graphArray[0]
|
|
175
184
|
|
|
176
|
-
const consumed = await this.processRoute(
|
|
185
|
+
const consumed = await this.processRoute(routeGraph, route)
|
|
177
186
|
if (consumed) {
|
|
178
187
|
return
|
|
179
188
|
}
|