hybrid-navigation 2.13.2 → 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.
- package/README.md +4 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDReactRootView.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +31 -36
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigatorRegistry.java +0 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +32 -64
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +8 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFrameLayout.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +1 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +1 -2
- package/ios/HybridNavigation/HBDUtils.m +3 -3
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +2 -2
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +5 -5
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +8 -8
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +22 -15
- package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.h +2 -3
- package/ios/HybridNavigation/ReactBridge/HBDReactBridgeManager.m +35 -29
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +2 -2
- package/ios/HybridNavigation/ViewController/HBDViewController.m +1 -1
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +1 -1
- package/lib/Event.d.ts +0 -2
- package/lib/Event.js +0 -9
- package/lib/GardenModule.d.ts +4 -0
- package/lib/GardenModule.js +19 -1
- package/lib/Navigation.d.ts +1 -1
- package/lib/NavigationModule.d.ts +1 -1
- package/lib/NavigationModule.js +6 -2
- package/lib/Navigator.js +10 -8
- package/lib/handler/DispatchCommandHandler.d.ts +1 -0
- package/lib/handler/DispatchCommandHandler.js +17 -16
- package/lib/handler/LayoutCommandHandler.d.ts +1 -3
- package/lib/handler/LayoutCommandHandler.js +2 -19
- package/lib/index.d.ts +1 -4
- package/lib/index.js +1 -20
- package/lib/router/index.d.ts +2 -1
- package/lib/router/index.js +13 -6
- package/package.json +1 -1
- package/src/Event.ts +0 -11
- package/src/GardenModule.ts +27 -1
- package/src/NavigationModule.ts +7 -3
- package/src/Navigator.ts +10 -8
- package/src/handler/DispatchCommandHandler.ts +18 -15
- package/src/handler/LayoutCommandHandler.ts +2 -22
- package/src/index.ts +1 -24
- package/src/router/index.ts +14 -6
|
@@ -28,7 +28,7 @@ RCT_EXPORT_MODULE(NavigationModule)
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
- (void)invalidate {
|
|
31
|
-
RCTLogInfo(@"[
|
|
31
|
+
RCTLogInfo(@"[Navigation] NavigationModule#invalidate");
|
|
32
32
|
[NSObject cancelPreviousPerformRequestsWithTarget:self];
|
|
33
33
|
[[HBDAnimationObserver sharedObserver] invalidate];
|
|
34
34
|
[self.bridgeManager invalidate];
|
|
@@ -58,27 +58,34 @@ RCT_EXPORT_METHOD(registerReactComponent:(NSString *)appKey options:(NSDictionar
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
RCT_EXPORT_METHOD(signalFirstRenderComplete:(NSString *) sceneId) {
|
|
61
|
-
// RCTLogInfo(@"[
|
|
62
|
-
UIViewController *vc = [self.bridgeManager
|
|
61
|
+
// RCTLogInfo(@"[Navigation] signalFirstRenderComplete sceneId:%@", sceneId);
|
|
62
|
+
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
63
63
|
if ([vc isKindOfClass:[HBDReactViewController class]]) {
|
|
64
64
|
[(HBDReactViewController *)vc signalFirstRenderComplete];
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
RCT_EXPORT_METHOD(setRoot:(NSDictionary *)layout sticky:(BOOL)sticky
|
|
68
|
+
RCT_EXPORT_METHOD(setRoot:(NSDictionary *)layout sticky:(BOOL)sticky callback:(RCTResponseSenderBlock)callback) {
|
|
69
69
|
self.bridgeManager.viewHierarchyReady = NO;
|
|
70
70
|
UIViewController *vc = [self.bridgeManager viewControllerWithLayout:layout];
|
|
71
|
-
if (vc) {
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
if (!vc) {
|
|
72
|
+
@throw [[NSException alloc] initWithName:@"IllegalArgumentsException" reason:@"无法创建 ViewController" userInfo:@{ @"layout": layout }];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (self.bridgeManager.didSetRoot) {
|
|
76
|
+
self.bridgeManager.didSetRoot(@[NSNull.null, @NO]);
|
|
74
77
|
}
|
|
78
|
+
self.bridgeManager.didSetRoot = callback;
|
|
79
|
+
self.bridgeManager.hasRootLayout = YES;
|
|
80
|
+
|
|
81
|
+
[self.bridgeManager setRootViewController:vc];
|
|
75
82
|
}
|
|
76
83
|
|
|
77
84
|
RCT_EXPORT_METHOD(dispatch:(NSString *)sceneId action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback) {
|
|
78
|
-
UIViewController *vc = [self.bridgeManager
|
|
85
|
+
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
79
86
|
if (!vc) {
|
|
80
87
|
callback(@[NSNull.null, @NO]);
|
|
81
|
-
RCTLogWarn(@"[
|
|
88
|
+
RCTLogWarn(@"[Navigation] Can't find target scene for action: %@, maybe the scene is gone. \nextras: %@", action, extras);
|
|
82
89
|
return;
|
|
83
90
|
}
|
|
84
91
|
|
|
@@ -86,7 +93,7 @@ RCT_EXPORT_METHOD(dispatch:(NSString *)sceneId action:(NSString *)action extras:
|
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
RCT_EXPORT_METHOD(currentTab:(NSString *)sceneId callback:(RCTResponseSenderBlock)callback) {
|
|
89
|
-
UIViewController *vc = [self.bridgeManager
|
|
96
|
+
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
90
97
|
UITabBarController *tabs = vc.tabBarController;
|
|
91
98
|
if (tabs) {
|
|
92
99
|
callback(@[NSNull.null, @(tabs.selectedIndex)]);
|
|
@@ -96,7 +103,7 @@ RCT_EXPORT_METHOD(currentTab:(NSString *)sceneId callback:(RCTResponseSenderBloc
|
|
|
96
103
|
}
|
|
97
104
|
|
|
98
105
|
RCT_EXPORT_METHOD(isStackRoot:(NSString *)sceneId callback:(RCTResponseSenderBlock)callback) {
|
|
99
|
-
UIViewController *vc = [self.bridgeManager
|
|
106
|
+
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
100
107
|
UINavigationController *nav = vc.navigationController;
|
|
101
108
|
if (!nav) {
|
|
102
109
|
callback(@[NSNull.null, @NO]);
|
|
@@ -119,7 +126,7 @@ RCT_EXPORT_METHOD(isStackRoot:(NSString *)sceneId callback:(RCTResponseSenderBlo
|
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
RCT_EXPORT_METHOD(setResult:(NSString *)sceneId resultCode:(NSInteger)resultCode data:(NSDictionary *)data) {
|
|
122
|
-
UIViewController *vc = [self.bridgeManager
|
|
129
|
+
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
123
130
|
[vc setResultCode:resultCode resultData:data];
|
|
124
131
|
}
|
|
125
132
|
|
|
@@ -141,12 +148,12 @@ RCT_EXPORT_METHOD(findSceneIdByModuleName:(NSString *)moduleName callback:(RCTRe
|
|
|
141
148
|
|
|
142
149
|
NSString *sceneId = [self findSceneIdByModuleName:moduleName];
|
|
143
150
|
if (sceneId == nil) {
|
|
144
|
-
RCTLogInfo(@"[
|
|
151
|
+
RCTLogInfo(@"[Navigation] Can't find sceneId by : %@", moduleName);
|
|
145
152
|
callback(@[NSNull.null, NSNull.null]);
|
|
146
153
|
return;
|
|
147
154
|
}
|
|
148
155
|
|
|
149
|
-
RCTLogInfo(@"[
|
|
156
|
+
RCTLogInfo(@"[Navigation] The sceneId found by %@ : %@", moduleName, sceneId);
|
|
150
157
|
callback(@[[NSNull null], sceneId]);
|
|
151
158
|
}
|
|
152
159
|
|
|
@@ -158,7 +165,7 @@ RCT_EXPORT_METHOD(findSceneIdByModuleName:(NSString *)moduleName callback:(RCTRe
|
|
|
158
165
|
UIWindow *window = application.windows[i];
|
|
159
166
|
NSString *sceneId = [self findSceneIdByModuleName:moduleName withViewController:window.rootViewController];
|
|
160
167
|
if (sceneId != nil) {
|
|
161
|
-
RCTLogInfo(@"[
|
|
168
|
+
RCTLogInfo(@"[Navigation] The sceneId found by %@ : %@", moduleName, sceneId);
|
|
162
169
|
return sceneId;
|
|
163
170
|
}
|
|
164
171
|
}
|
|
@@ -23,6 +23,7 @@ extern const NSInteger ResultCancel;
|
|
|
23
23
|
@property(nonatomic, assign, readonly, getter=isReactModuleRegisterCompleted) BOOL reactModuleRegisterCompleted;
|
|
24
24
|
@property(nonatomic, assign, getter=isViewHierarchyReady) BOOL viewHierarchyReady;
|
|
25
25
|
@property(nonatomic, assign) BOOL hasRootLayout;
|
|
26
|
+
@property(nonatomic, copy) RCTResponseSenderBlock didSetRoot;
|
|
26
27
|
|
|
27
28
|
- (void)installWithBridge:(RCTBridge *)bridge;
|
|
28
29
|
|
|
@@ -46,12 +47,10 @@ extern const NSInteger ResultCancel;
|
|
|
46
47
|
|
|
47
48
|
- (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout;
|
|
48
49
|
|
|
49
|
-
- (UIViewController *)
|
|
50
|
+
- (UIViewController *)viewControllerBySceneId:(NSString *)sceneId;
|
|
50
51
|
|
|
51
52
|
- (void)setRootViewController:(UIViewController *)rootViewController;
|
|
52
53
|
|
|
53
|
-
- (void)setRootViewController:(UIViewController *)rootViewController withTag:(NSNumber *)tag;
|
|
54
|
-
|
|
55
54
|
- (NSArray *)routeGraph;
|
|
56
55
|
|
|
57
56
|
- (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc;
|
|
@@ -53,7 +53,7 @@ const NSInteger ResultCancel = 0;
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
- (void)invalidate {
|
|
56
|
-
RCTLogInfo(@"[
|
|
56
|
+
RCTLogInfo(@"[Navigation] HBDReactBridgeManager#invalidate");
|
|
57
57
|
[NSObject cancelPreviousPerformRequestsWithTarget:self];
|
|
58
58
|
|
|
59
59
|
NSArray<id <HBDNavigator>> *navigators = [self.navigatorRegistry allNavigators];
|
|
@@ -63,6 +63,7 @@ const NSInteger ResultCancel = 0;
|
|
|
63
63
|
|
|
64
64
|
self.viewHierarchyReady = NO;
|
|
65
65
|
self.reactModuleRegisterCompleted = NO;
|
|
66
|
+
self.didSetRoot = NULL;
|
|
66
67
|
|
|
67
68
|
UIWindow *mainWindow = [self mainWindow];
|
|
68
69
|
UIViewController *presentedViewController = mainWindow.rootViewController.presentedViewController;
|
|
@@ -155,7 +156,7 @@ const NSInteger ResultCancel = 0;
|
|
|
155
156
|
UIViewController *vc = [self createViewControllerWithLayout:layout];
|
|
156
157
|
|
|
157
158
|
if (!vc) {
|
|
158
|
-
RCTLogError(@"[
|
|
159
|
+
RCTLogError(@"[Navigation] Can't find a navigator that can handle layout '%@'. Did you forget to register?", layout);
|
|
159
160
|
return nil;
|
|
160
161
|
}
|
|
161
162
|
|
|
@@ -186,13 +187,13 @@ const NSInteger ResultCancel = 0;
|
|
|
186
187
|
}
|
|
187
188
|
}
|
|
188
189
|
|
|
189
|
-
- (UIViewController *)
|
|
190
|
-
if (
|
|
191
|
-
|
|
190
|
+
- (UIViewController *)viewControllerBySceneId:(NSString *)sceneId {
|
|
191
|
+
if (self.viewHierarchyReady) {
|
|
192
|
+
UIWindow *window = [self mainWindow];
|
|
193
|
+
return [self viewControllerWithSceneId:sceneId viewController:window.rootViewController];
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
|
|
195
|
-
return [self viewControllerWithSceneId:sceneId viewController:window.rootViewController];
|
|
196
|
+
return nil;
|
|
196
197
|
}
|
|
197
198
|
|
|
198
199
|
- (UIViewController *)viewControllerWithSceneId:(NSString *)sceneId viewController:(UIViewController *)vc {
|
|
@@ -224,24 +225,19 @@ const NSInteger ResultCancel = 0;
|
|
|
224
225
|
}
|
|
225
226
|
|
|
226
227
|
- (void)setRootViewController:(UIViewController *)rootViewController {
|
|
227
|
-
[self setRootViewController:rootViewController withTag:@(0)];
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
- (void)setRootViewController:(UIViewController *)rootViewController withTag:(NSNumber *)tag {
|
|
231
|
-
[HBDEventEmitter sendEvent:EVENT_WILL_SET_ROOT data:@{}];
|
|
232
|
-
|
|
233
228
|
UIWindow *mainWindow = [self mainWindow];
|
|
234
229
|
UIViewController *presentedViewController = mainWindow.rootViewController.presentedViewController;
|
|
235
230
|
if (presentedViewController && !presentedViewController.isBeingDismissed) {
|
|
236
231
|
[mainWindow.rootViewController dismissViewControllerAnimated:NO completion:^{
|
|
237
|
-
[self performSetRootViewController:rootViewController
|
|
232
|
+
[self performSetRootViewController:rootViewController animated:NO];
|
|
238
233
|
}];
|
|
239
234
|
} else {
|
|
240
|
-
[self performSetRootViewController:rootViewController
|
|
235
|
+
[self performSetRootViewController:rootViewController animated:YES];
|
|
241
236
|
}
|
|
242
237
|
}
|
|
243
238
|
|
|
244
|
-
- (void)performSetRootViewController:(UIViewController *)rootViewController
|
|
239
|
+
- (void)performSetRootViewController:(UIViewController *)rootViewController animated:(BOOL)animated {
|
|
240
|
+
[HBDEventEmitter sendEvent:EVENT_WILL_SET_ROOT data:@{}];
|
|
245
241
|
UIWindow *mainWindow = [self mainWindow];
|
|
246
242
|
if (animated) {
|
|
247
243
|
[UIView transitionWithView:mainWindow duration:0.15f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
|
|
@@ -253,9 +249,13 @@ const NSInteger ResultCancel = 0;
|
|
|
253
249
|
[mainWindow makeKeyAndVisible];
|
|
254
250
|
}
|
|
255
251
|
[UIView setAnimationsEnabled:oldState];
|
|
252
|
+
} completion:^(BOOL finished) {
|
|
256
253
|
self.viewHierarchyReady = YES;
|
|
257
|
-
|
|
258
|
-
|
|
254
|
+
if (self.didSetRoot) {
|
|
255
|
+
self.didSetRoot(@[NSNull.null, @YES]);
|
|
256
|
+
self.didSetRoot = NULL;
|
|
257
|
+
}
|
|
258
|
+
[HBDEventEmitter sendEvent:EVENT_DID_SET_ROOT data:@{}];
|
|
259
259
|
}];
|
|
260
260
|
} else {
|
|
261
261
|
mainWindow.rootViewController = rootViewController;
|
|
@@ -263,8 +263,13 @@ const NSInteger ResultCancel = 0;
|
|
|
263
263
|
if (!mainWindow.isKeyWindow) {
|
|
264
264
|
[mainWindow makeKeyAndVisible];
|
|
265
265
|
}
|
|
266
|
+
|
|
266
267
|
self.viewHierarchyReady = YES;
|
|
267
|
-
|
|
268
|
+
if (self.didSetRoot) {
|
|
269
|
+
self.didSetRoot(@[NSNull.null, @YES]);
|
|
270
|
+
self.didSetRoot = NULL;
|
|
271
|
+
}
|
|
272
|
+
[HBDEventEmitter sendEvent:EVENT_DID_SET_ROOT data:@{}];
|
|
268
273
|
}
|
|
269
274
|
}
|
|
270
275
|
|
|
@@ -281,11 +286,12 @@ const NSInteger ResultCancel = 0;
|
|
|
281
286
|
}
|
|
282
287
|
|
|
283
288
|
NSString *layout = [self.navigatorRegistry layoutForViewController:vc];
|
|
284
|
-
if (
|
|
285
|
-
|
|
289
|
+
if (layout) {
|
|
290
|
+
id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
|
|
291
|
+
return [navigator primaryViewControllerWithViewController:vc];
|
|
286
292
|
}
|
|
287
|
-
|
|
288
|
-
return
|
|
293
|
+
|
|
294
|
+
return nil;
|
|
289
295
|
}
|
|
290
296
|
|
|
291
297
|
- (NSArray *)routeGraph {
|
|
@@ -295,13 +301,13 @@ const NSInteger ResultCancel = 0;
|
|
|
295
301
|
NSMutableArray *root = [[NSMutableArray alloc] init];
|
|
296
302
|
[root addObject:graph];
|
|
297
303
|
[root addObjectsFromArray:[self presentedGraphsWithRootViewController:vc]];
|
|
298
|
-
|
|
299
304
|
return root;
|
|
300
305
|
}
|
|
301
306
|
|
|
302
307
|
- (NSArray *)presentedGraphsWithRootViewController:(UIViewController *)vc {
|
|
303
308
|
NSMutableArray *graphs = [[NSMutableArray alloc] init];
|
|
304
309
|
UIViewController *presented = vc.presentedViewController;
|
|
310
|
+
|
|
305
311
|
while (presented && !presented.beingDismissed && ![presented isKindOfClass:[UIAlertController class]]) {
|
|
306
312
|
NSDictionary *graph = [self routeGraphWithViewController:presented];
|
|
307
313
|
if (graph) {
|
|
@@ -315,17 +321,17 @@ const NSInteger ResultCancel = 0;
|
|
|
315
321
|
|
|
316
322
|
- (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
|
|
317
323
|
NSString *layout = [self.navigatorRegistry layoutForViewController:vc];
|
|
318
|
-
if (
|
|
319
|
-
|
|
324
|
+
if (layout) {
|
|
325
|
+
id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForLayout:layout];
|
|
326
|
+
return [navigator routeGraphWithViewController:vc];
|
|
320
327
|
}
|
|
321
|
-
|
|
322
|
-
return [navigator routeGraphWithViewController:vc];
|
|
328
|
+
return nil;
|
|
323
329
|
}
|
|
324
330
|
|
|
325
331
|
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
326
332
|
id <HBDNavigator> navigator = [self.navigatorRegistry navigatorForAction:action];
|
|
327
333
|
if (!navigator) {
|
|
328
|
-
RCTLogWarn(@"[
|
|
334
|
+
RCTLogWarn(@"[Navigation] Can't find a navigator that can handle action '%@'", action);
|
|
329
335
|
callback(@[NSNull.null, @NO]);
|
|
330
336
|
return;
|
|
331
337
|
}
|
|
@@ -327,7 +327,7 @@
|
|
|
327
327
|
@dynamic navigationBar;
|
|
328
328
|
|
|
329
329
|
- (void)dealloc {
|
|
330
|
-
RCTLogInfo(@"[
|
|
330
|
+
RCTLogInfo(@"[Navigation] %s", __FUNCTION__);
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController {
|
|
@@ -415,7 +415,7 @@
|
|
|
415
415
|
UIEdgeInsets safeAreaInsets = self.view.safeAreaInsets;
|
|
416
416
|
UIEdgeInsets additionalInsets = self.additionalSafeAreaInsets;
|
|
417
417
|
|
|
418
|
-
// RCTLogInfo(@"[
|
|
418
|
+
// RCTLogInfo(@"[Navigation] safeAreaInsets:%@, additionalInsets:%@", NSStringFromUIEdgeInsets(safeAreaInsets), NSStringFromUIEdgeInsets(additionalInsets));
|
|
419
419
|
|
|
420
420
|
BOOL statusBarHidden = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarHidden;
|
|
421
421
|
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
@implementation HBDViewController
|
|
19
19
|
|
|
20
20
|
- (void)dealloc {
|
|
21
|
-
RCTLogInfo(@"[
|
|
21
|
+
RCTLogInfo(@"[Navigation] %s", __FUNCTION__);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
- (BOOL)canPresentViewController {
|
|
51
51
|
UIViewController *presented = self.presentedViewController;
|
|
52
52
|
if (presented && !presented.isBeingDismissed) {
|
|
53
|
-
RCTLogWarn(@"[
|
|
53
|
+
RCTLogWarn(@"[Navigation] Can't present since the scene had present another scene already.");
|
|
54
54
|
return NO;
|
|
55
55
|
}
|
|
56
56
|
return YES;
|
package/lib/Event.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Visibility } from './Route';
|
|
2
|
-
declare function listenStatusBarHeightChange(listener: (statusBarHeight: number) => void): import("react-native").EmitterSubscription;
|
|
3
2
|
declare function listenComponentResult(listener: (sceneId: string, requestCode: number, resultCode: number, resultData: object) => void): import("react-native").EmitterSubscription;
|
|
4
3
|
declare function listenComponentVisibility(listener: (sceneId: string, visibility: Visibility) => void): import("react-native").EmitterSubscription;
|
|
5
4
|
declare function listenBarButtonItemClick(listener: (sceneId: string, action: string) => void): import("react-native").EmitterSubscription;
|
|
@@ -7,7 +6,6 @@ declare function listenTabSwitch(listener: (sceneId: string, from: number, to: n
|
|
|
7
6
|
declare function listenWillSetRoot(willSetRoot: () => void): import("react-native").EmitterSubscription;
|
|
8
7
|
declare function listenDidSetRoot(didSetRoot: (tag: number) => void): import("react-native").EmitterSubscription;
|
|
9
8
|
declare const _default: {
|
|
10
|
-
listenStatusBarHeightChange: typeof listenStatusBarHeightChange;
|
|
11
9
|
listenBarButtonItemClick: typeof listenBarButtonItemClick;
|
|
12
10
|
listenComponentResult: typeof listenComponentResult;
|
|
13
11
|
listenComponentVisibility: typeof listenComponentVisibility;
|
package/lib/Event.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
2
|
-
import GardenModule from './GardenModule';
|
|
3
|
-
function listenStatusBarHeightChange(listener) {
|
|
4
|
-
const GardenEventReceiver = new NativeEventEmitter(GardenModule);
|
|
5
|
-
const { EVENT_STATUSBAR_FRAME_CHANGE } = GardenModule.getConstants();
|
|
6
|
-
return GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight }) => {
|
|
7
|
-
listener(statusBarHeight);
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
2
|
const HBDEventEmitter = NativeModules.HBDEventEmitter;
|
|
11
3
|
const HBDEventReceiver = new NativeEventEmitter(HBDEventEmitter);
|
|
12
4
|
function listenComponentResult(listener) {
|
|
@@ -61,7 +53,6 @@ function listenDidSetRoot(didSetRoot) {
|
|
|
61
53
|
});
|
|
62
54
|
}
|
|
63
55
|
export default {
|
|
64
|
-
listenStatusBarHeightChange,
|
|
65
56
|
listenBarButtonItemClick,
|
|
66
57
|
listenComponentResult,
|
|
67
58
|
listenComponentVisibility,
|
package/lib/GardenModule.d.ts
CHANGED
|
@@ -17,4 +17,8 @@ interface GardenModule extends NativeModule {
|
|
|
17
17
|
setMenuInteractive: (sceneId: string, enabled: boolean) => void;
|
|
18
18
|
}
|
|
19
19
|
declare const GardenModule: GardenModule;
|
|
20
|
+
declare function statusBarHeight(): number;
|
|
21
|
+
declare function toolbarHeight(): number;
|
|
22
|
+
declare function topBarHeight(): number;
|
|
23
|
+
export { statusBarHeight, toolbarHeight, topBarHeight };
|
|
20
24
|
export default GardenModule;
|
package/lib/GardenModule.js
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
import { NativeModules } from 'react-native';
|
|
1
|
+
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
|
|
2
2
|
const GardenModule = NativeModules.GardenModule;
|
|
3
|
+
const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT, EVENT_STATUSBAR_FRAME_CHANGE } = GardenModule.getConstants();
|
|
4
|
+
let _statusBarHeight = STATUSBAR_HEIGHT;
|
|
5
|
+
if (Platform.OS === 'ios') {
|
|
6
|
+
const GardenEventReceiver = new NativeEventEmitter(GardenModule);
|
|
7
|
+
GardenEventReceiver.addListener(EVENT_STATUSBAR_FRAME_CHANGE, ({ statusBarHeight: height }) => {
|
|
8
|
+
_statusBarHeight = height;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
function statusBarHeight() {
|
|
12
|
+
return _statusBarHeight;
|
|
13
|
+
}
|
|
14
|
+
function toolbarHeight() {
|
|
15
|
+
return TOOLBAR_HEIGHT;
|
|
16
|
+
}
|
|
17
|
+
function topBarHeight() {
|
|
18
|
+
return statusBarHeight() + toolbarHeight();
|
|
19
|
+
}
|
|
20
|
+
export { statusBarHeight, toolbarHeight, topBarHeight };
|
|
3
21
|
export default GardenModule;
|
package/lib/Navigation.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare class Navigation implements Navigation {
|
|
|
43
43
|
setResult: <T extends ResultType>(sceneId: string, resultCode: number, data?: T) => void;
|
|
44
44
|
result<T>(sceneId: string, resultCode: number): Promise<[number, T]>;
|
|
45
45
|
unmount(sceneId: string): void;
|
|
46
|
-
setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<
|
|
46
|
+
setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<boolean>;
|
|
47
47
|
setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
|
|
48
48
|
currentTab(sceneId: string): Promise<number>;
|
|
49
49
|
findSceneIdByModuleName(moduleName: string): Promise<string | null>;
|
|
@@ -8,7 +8,7 @@ declare function endRegisterReactComponent(): void;
|
|
|
8
8
|
declare function registerReactComponent(appKey: string, options: object): void;
|
|
9
9
|
declare function signalFirstRenderComplete(sceneId: string): void;
|
|
10
10
|
declare function setResult(sceneId: string, resultCode: number, data: object | null): void;
|
|
11
|
-
declare function setRoot(layout: object, sticky: boolean
|
|
11
|
+
declare function setRoot(layout: object, sticky: boolean): Promise<boolean>;
|
|
12
12
|
declare function dispatch(sceneId: string, action: string, params: object): Promise<boolean>;
|
|
13
13
|
declare function currentTab(sceneId: string): Promise<number>;
|
|
14
14
|
declare function isStackRoot(sceneId: string): Promise<boolean>;
|
package/lib/NavigationModule.js
CHANGED
|
@@ -18,8 +18,12 @@ function signalFirstRenderComplete(sceneId) {
|
|
|
18
18
|
function setResult(sceneId, resultCode, data) {
|
|
19
19
|
NavigationModule.setResult(sceneId, resultCode, data);
|
|
20
20
|
}
|
|
21
|
-
function setRoot(layout, sticky
|
|
22
|
-
|
|
21
|
+
function setRoot(layout, sticky) {
|
|
22
|
+
return new Promise(resolve => {
|
|
23
|
+
NavigationModule.setRoot(layout, sticky, (_, success) => {
|
|
24
|
+
resolve(success);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
23
27
|
}
|
|
24
28
|
function dispatch(sceneId, action, params) {
|
|
25
29
|
return new Promise(resolve => {
|
package/lib/Navigator.js
CHANGED
|
@@ -135,11 +135,13 @@ export class Navigator {
|
|
|
135
135
|
}
|
|
136
136
|
return await Navigation.result(this.sceneId, 0);
|
|
137
137
|
};
|
|
138
|
-
pop = () => Navigation.dispatch(this.sceneId, 'pop');
|
|
139
|
-
popTo = (moduleName, inclusive = false) => Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive });
|
|
140
|
-
popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot');
|
|
138
|
+
pop = () => Navigation.dispatch(this.sceneId, 'pop', { from: this.moduleName });
|
|
139
|
+
popTo = (moduleName, inclusive = false) => Navigation.dispatch(this.sceneId, 'popTo', { moduleName, inclusive, from: this.moduleName });
|
|
140
|
+
popToRoot = () => Navigation.dispatch(this.sceneId, 'popToRoot', { from: this.moduleName });
|
|
141
141
|
redirectTo = (moduleName, props = {}, options = {}) => Navigation.dispatch(this.sceneId, 'redirectTo', {
|
|
142
142
|
moduleName,
|
|
143
|
+
from: this.moduleName,
|
|
144
|
+
to: moduleName,
|
|
143
145
|
props,
|
|
144
146
|
options,
|
|
145
147
|
});
|
|
@@ -170,7 +172,7 @@ export class Navigator {
|
|
|
170
172
|
}
|
|
171
173
|
return await Navigation.result(this.sceneId, requestCode);
|
|
172
174
|
};
|
|
173
|
-
dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss');
|
|
175
|
+
dismiss = () => Navigation.dispatch(this.sceneId, 'dismiss', { from: this.moduleName });
|
|
174
176
|
showModal = async (moduleName, props = {}, options = {}) => {
|
|
175
177
|
const requestCode = --tagGenerator;
|
|
176
178
|
const success = await Navigation.dispatch(this.sceneId, 'showModal', {
|
|
@@ -198,15 +200,15 @@ export class Navigator {
|
|
|
198
200
|
}
|
|
199
201
|
return await Navigation.result(this.sceneId, requestCode);
|
|
200
202
|
};
|
|
201
|
-
hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal');
|
|
203
|
+
hideModal = () => Navigation.dispatch(this.sceneId, 'hideModal', { from: this.moduleName });
|
|
202
204
|
setResult = (resultCode, data = null) => Navigation.setResult(this.sceneId, resultCode, data);
|
|
203
205
|
switchTab = async (index, popToRoot = false) => {
|
|
204
206
|
const from = await Navigation.currentTab(this.sceneId);
|
|
205
207
|
return Navigation.dispatch(this.sceneId, 'switchTab', { from, to: index, popToRoot });
|
|
206
208
|
};
|
|
207
|
-
toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu');
|
|
208
|
-
openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu');
|
|
209
|
-
closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu');
|
|
209
|
+
toggleMenu = () => Navigation.dispatch(this.sceneId, 'toggleMenu', { from: this.moduleName });
|
|
210
|
+
openMenu = () => Navigation.dispatch(this.sceneId, 'openMenu', { from: this.moduleName });
|
|
211
|
+
closeMenu = () => Navigation.dispatch(this.sceneId, 'closeMenu', { from: this.moduleName });
|
|
210
212
|
isStackRoot = () => Navigation.isStackRoot(this.sceneId);
|
|
211
213
|
signalFirstRenderComplete = () => Navigation.signalFirstRenderComplete(this.sceneId);
|
|
212
214
|
}
|
|
@@ -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;
|
|
@@ -2,10 +2,8 @@ import { BuildInLayout, Layout } from '../Route';
|
|
|
2
2
|
export default class LayoutCommandHandler {
|
|
3
3
|
private willSetRoot;
|
|
4
4
|
private didSetRoot;
|
|
5
|
-
private canInvokeWillSetRoot;
|
|
6
|
-
private tagGenerator;
|
|
7
5
|
constructor();
|
|
8
6
|
handleRootLayoutChange(): void;
|
|
9
|
-
setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<
|
|
7
|
+
setRoot(layout: BuildInLayout | Layout, sticky?: boolean): Promise<boolean>;
|
|
10
8
|
setRootLayoutUpdateListener(willSetRoot?: () => void, didSetRoot?: () => void): void;
|
|
11
9
|
}
|
|
@@ -3,34 +3,17 @@ import NavigationModule from '../NavigationModule';
|
|
|
3
3
|
export default class LayoutCommandHandler {
|
|
4
4
|
willSetRoot = () => { };
|
|
5
5
|
didSetRoot = () => { };
|
|
6
|
-
canInvokeWillSetRoot = true;
|
|
7
|
-
tagGenerator = 0;
|
|
8
6
|
constructor() { }
|
|
9
7
|
handleRootLayoutChange() {
|
|
10
8
|
Event.listenWillSetRoot(() => {
|
|
11
|
-
|
|
12
|
-
this.willSetRoot();
|
|
13
|
-
}
|
|
9
|
+
this.willSetRoot();
|
|
14
10
|
});
|
|
15
11
|
Event.listenDidSetRoot(() => {
|
|
16
12
|
this.didSetRoot();
|
|
17
|
-
this.canInvokeWillSetRoot = true;
|
|
18
13
|
});
|
|
19
14
|
}
|
|
20
15
|
setRoot(layout, sticky = false) {
|
|
21
|
-
|
|
22
|
-
this.canInvokeWillSetRoot = false;
|
|
23
|
-
const flag = this.tagGenerator++;
|
|
24
|
-
NavigationModule.setRoot(layout, sticky, flag);
|
|
25
|
-
return new Promise(resolve => {
|
|
26
|
-
const subscription = Event.listenDidSetRoot((tag) => {
|
|
27
|
-
// FIXME: 此处恐有内存泄漏
|
|
28
|
-
if (tag === flag) {
|
|
29
|
-
subscription.remove();
|
|
30
|
-
resolve();
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
16
|
+
return NavigationModule.setRoot(layout, sticky);
|
|
34
17
|
}
|
|
35
18
|
setRootLayoutUpdateListener(willSetRoot = () => { }, didSetRoot = () => { }) {
|
|
36
19
|
this.willSetRoot = willSetRoot;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import Navigation from './Navigation';
|
|
2
|
-
declare function statusBarHeight(): number;
|
|
3
|
-
declare function toolbarHeight(): number;
|
|
4
|
-
declare function topBarHeight(): number;
|
|
5
2
|
export default Navigation;
|
|
6
|
-
export { statusBarHeight, toolbarHeight, topBarHeight };
|
|
7
3
|
export { RESULT_OK, RESULT_CANCEL } from './Navigation';
|
|
4
|
+
export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule';
|
|
8
5
|
export { withNavigationItem, NavigationProps, InjectedProps } from './NavigationComponentWrap';
|
|
9
6
|
export * from './Navigator';
|
|
10
7
|
export * from './Garden';
|
package/lib/index.js
CHANGED
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
import { Platform } from 'react-native';
|
|
2
|
-
import Event from './Event';
|
|
3
|
-
import GardenModule from './GardenModule';
|
|
4
1
|
import { withNavigation } from './NavigationComponentWrap';
|
|
5
2
|
import Navigation from './Navigation';
|
|
6
3
|
Navigation.setNavigationComponentWrap(withNavigation);
|
|
7
|
-
const { STATUSBAR_HEIGHT, TOOLBAR_HEIGHT } = GardenModule.getConstants();
|
|
8
|
-
let _statusBarHeight = STATUSBAR_HEIGHT;
|
|
9
|
-
if (Platform.OS === 'ios') {
|
|
10
|
-
Event.listenStatusBarHeightChange(height => {
|
|
11
|
-
_statusBarHeight = height;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
function statusBarHeight() {
|
|
15
|
-
return _statusBarHeight;
|
|
16
|
-
}
|
|
17
|
-
function toolbarHeight() {
|
|
18
|
-
return TOOLBAR_HEIGHT;
|
|
19
|
-
}
|
|
20
|
-
function topBarHeight() {
|
|
21
|
-
return statusBarHeight() + toolbarHeight();
|
|
22
|
-
}
|
|
23
4
|
export default Navigation;
|
|
24
|
-
export { statusBarHeight, toolbarHeight, topBarHeight };
|
|
25
5
|
export { RESULT_OK, RESULT_CANCEL } from './Navigation';
|
|
6
|
+
export { statusBarHeight, toolbarHeight, topBarHeight } from './GardenModule';
|
|
26
7
|
export { withNavigationItem } from './NavigationComponentWrap';
|
|
27
8
|
export * from './Navigator';
|
|
28
9
|
export * from './Garden';
|
package/lib/router/index.d.ts
CHANGED
|
@@ -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
|
|
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;
|