hybrid-navigation 2.12.3 → 2.13.0-beta.1
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 +63 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/GardenModule.java +6 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationModule.java +29 -30
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +2 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactBridgeManager.java +4 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +24 -33
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +22 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +8 -8
- package/ios/HybridNavigation/GlobalStyle.h +0 -8
- package/ios/HybridNavigation/GlobalStyle.m +2 -8
- package/ios/HybridNavigation/HBDUtils.h +5 -13
- package/ios/HybridNavigation/HBDUtils.m +2 -12
- package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDDrawerNavigator.m +91 -67
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.h +2 -7
- package/ios/HybridNavigation/Navigator/HBDNavigatorRegistry.m +28 -26
- package/ios/HybridNavigation/Navigator/HBDScreenNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDScreenNavigator.m +127 -99
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDStackNavigator.m +199 -142
- package/ios/HybridNavigation/Navigator/HBDTabNavigator.h +0 -9
- package/ios/HybridNavigation/Navigator/HBDTabNavigator.m +144 -124
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.h +1 -11
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDEventEmitter.m +4 -10
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.h +6 -0
- package/ios/HybridNavigation/ReactBridge/HBDGardenModule.m +161 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.h +6 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigationModule.m +237 -0
- package/ios/HybridNavigation/ReactBridge/HBDNavigator.h +20 -0
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.h +12 -20
- package/ios/HybridNavigation/{Bridge → ReactBridge}/HBDReactBridgeManager.m +91 -91
- package/ios/HybridNavigation/View/HBDBarButtonItem.h +0 -8
- package/ios/HybridNavigation/View/HBDBarButtonItem.m +1 -11
- package/ios/HybridNavigation/View/HBDNavigationBar.h +0 -8
- package/ios/HybridNavigation/View/HBDNavigationBar.m +13 -20
- package/ios/HybridNavigation/View/HBDReactTabBar.h +0 -8
- package/ios/HybridNavigation/View/HBDReactTabBar.m +1 -8
- package/ios/HybridNavigation/View/HBDRootView.h +3 -10
- package/ios/HybridNavigation/View/HBDRootView.m +14 -25
- package/ios/HybridNavigation/View/HBDTitleView.h +0 -9
- package/ios/HybridNavigation/View/HBDTitleView.m +1 -26
- package/ios/HybridNavigation/View/UITabBar+Badge.h +0 -8
- package/ios/HybridNavigation/View/UITabBar+Badge.m +0 -7
- package/ios/HybridNavigation/ViewController/HBDDrawerController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDDrawerController.m +2 -9
- package/ios/HybridNavigation/ViewController/HBDFadeAnimation.h +9 -0
- package/ios/HybridNavigation/ViewController/HBDFadeAnimation.m +22 -0
- package/ios/HybridNavigation/ViewController/HBDNavigationController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDNavigationController.m +17 -120
- package/ios/HybridNavigation/ViewController/HBDPopAnimation.h +0 -7
- package/ios/HybridNavigation/ViewController/HBDPopAnimation.m +1 -8
- package/ios/HybridNavigation/ViewController/HBDPushAnimation.h +0 -7
- package/ios/HybridNavigation/ViewController/HBDPushAnimation.m +1 -8
- package/ios/HybridNavigation/ViewController/HBDReactViewController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDReactViewController.m +60 -27
- package/ios/HybridNavigation/ViewController/HBDTabBarController.h +0 -8
- package/ios/HybridNavigation/ViewController/HBDTabBarController.m +15 -11
- package/ios/HybridNavigation/ViewController/HBDViewController+Garden.m +23 -33
- package/ios/HybridNavigation/ViewController/HBDViewController.h +1 -8
- package/ios/HybridNavigation/ViewController/HBDViewController.m +6 -23
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.h +0 -8
- package/ios/HybridNavigation/ViewController/UINavigationController+HBD.m +0 -8
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.h +2 -16
- package/ios/HybridNavigation/ViewController/UIViewController+HBD.m +32 -46
- package/lib/Garden.d.ts +3 -0
- package/lib/Garden.js +12 -1
- package/lib/NavigationModule.d.ts +0 -2
- package/lib/NavigationModule.js +0 -3
- package/lib/Navigator.d.ts +25 -25
- package/lib/Navigator.js +116 -73
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/package.json +4 -6
- package/src/Garden.ts +15 -1
- package/src/NavigationModule.ts +0 -4
- package/src/Navigator.ts +96 -58
- package/src/index.ts +1 -1
- package/ios/HybridNavigation/Bridge/HBDGardenModule.h +0 -14
- package/ios/HybridNavigation/Bridge/HBDGardenModule.m +0 -155
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.h +0 -15
- package/ios/HybridNavigation/Bridge/HBDNavigationModule.m +0 -272
- package/ios/HybridNavigation/Navigator/HBDNavigator.h +0 -26
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
//
|
|
2
|
-
// HBDScreenNavigator.m
|
|
3
|
-
// HybridNavigation
|
|
4
|
-
//
|
|
5
|
-
// Created by Listen on 2018/6/28.
|
|
6
|
-
// Copyright © 2018年 Listen. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
1
|
#import "HBDScreenNavigator.h"
|
|
2
|
+
|
|
10
3
|
#import "HBDReactBridgeManager.h"
|
|
11
4
|
#import "HBDNavigationController.h"
|
|
5
|
+
|
|
12
6
|
#import <React/RCTLog.h>
|
|
13
7
|
|
|
14
8
|
@implementation HBDScreenNavigator
|
|
@@ -21,28 +15,30 @@
|
|
|
21
15
|
return @[@"present", @"presentLayout", @"dismiss", @"showModal", @"showModalLayout", @"hideModal"];
|
|
22
16
|
}
|
|
23
17
|
|
|
24
|
-
- (UIViewController *)
|
|
25
|
-
NSDictionary *
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
NSDictionary *props = screen[@"props"];
|
|
29
|
-
NSDictionary *options = screen[@"options"];
|
|
30
|
-
return [[HBDReactBridgeManager get] controllerWithModuleName:moduleName props:props options:options];
|
|
18
|
+
- (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
|
|
19
|
+
NSDictionary *model = layout[self.name];
|
|
20
|
+
if (!model) {
|
|
21
|
+
return nil;
|
|
31
22
|
}
|
|
32
|
-
|
|
23
|
+
|
|
24
|
+
NSString *moduleName = model[@"moduleName"];
|
|
25
|
+
NSDictionary *props = model[@"props"];
|
|
26
|
+
NSDictionary *options = model[@"options"];
|
|
27
|
+
return [[HBDReactBridgeManager get] viewControllerWithModuleName:moduleName props:props options:options];
|
|
33
28
|
}
|
|
34
29
|
|
|
35
|
-
- (NSDictionary *)
|
|
36
|
-
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
37
|
-
|
|
38
|
-
return @{
|
|
39
|
-
@"layout": @"screen",
|
|
40
|
-
@"sceneId": screen.sceneId,
|
|
41
|
-
@"moduleName": RCTNullIfNil(screen.moduleName),
|
|
42
|
-
@"mode": [vc hbd_mode],
|
|
43
|
-
};
|
|
30
|
+
- (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
|
|
31
|
+
if (![vc isKindOfClass:[HBDViewController class]]) {
|
|
32
|
+
return nil;
|
|
44
33
|
}
|
|
45
|
-
|
|
34
|
+
|
|
35
|
+
HBDViewController *screen = (HBDViewController *) vc;
|
|
36
|
+
return @{
|
|
37
|
+
@"layout": @"screen",
|
|
38
|
+
@"sceneId": screen.sceneId,
|
|
39
|
+
@"moduleName": RCTNullIfNil(screen.moduleName),
|
|
40
|
+
@"mode": [screen hbd_mode],
|
|
41
|
+
};
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
- (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
|
|
@@ -52,88 +48,120 @@
|
|
|
52
48
|
return nil;
|
|
53
49
|
}
|
|
54
50
|
|
|
55
|
-
- (void)handleNavigationWithViewController:(UIViewController *)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
52
|
+
if (!vc.hbd_inViewHierarchy) {
|
|
53
|
+
callback(@[NSNull.null, @NO]);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!vc.hbd_viewAppeared) {
|
|
58
|
+
[self performSelector:@selector(handleNavigation:) withObject:@{
|
|
59
|
+
@"viewController": vc,
|
|
60
|
+
@"action": action,
|
|
61
|
+
@"extras": extras,
|
|
62
|
+
@"callback": callback,
|
|
63
|
+
} afterDelay:0.05];
|
|
61
64
|
return;
|
|
62
65
|
}
|
|
63
|
-
|
|
64
|
-
UIViewController *viewController = nil;
|
|
65
66
|
|
|
66
67
|
if ([action isEqualToString:@"present"]) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
[
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}];
|
|
85
|
-
}
|
|
86
|
-
} else if ([action isEqualToString:@"showModal"]) {
|
|
87
|
-
viewController = [self createViewControllerWithExtras:extras];
|
|
88
|
-
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
89
|
-
viewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
90
|
-
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
91
|
-
[viewController setRequestCode:requestCode];
|
|
92
|
-
[target presentViewController:viewController animated:YES completion:^{
|
|
93
|
-
resolve(@(YES));
|
|
94
|
-
}];
|
|
95
|
-
} else if ([action isEqualToString:@"hideModal"]) {
|
|
96
|
-
UIViewController *presenting = target.presentingViewController;
|
|
97
|
-
if (presenting) {
|
|
98
|
-
[presenting dismissViewControllerAnimated:YES completion:^{
|
|
99
|
-
resolve(@(YES));
|
|
100
|
-
}];
|
|
101
|
-
} else {
|
|
102
|
-
[target dismissViewControllerAnimated:YES completion:^{
|
|
103
|
-
resolve(@(YES));
|
|
104
|
-
}];
|
|
105
|
-
}
|
|
106
|
-
} else if ([action isEqualToString:@"presentLayout"]) {
|
|
107
|
-
NSDictionary *layout = extras[@"layout"];
|
|
108
|
-
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
109
|
-
viewController = [[HBDReactBridgeManager get] controllerWithLayout:layout];
|
|
110
|
-
[viewController setRequestCode:requestCode];
|
|
111
|
-
viewController.modalPresentationStyle = UIModalPresentationCurrentContext;
|
|
112
|
-
[target presentViewController:viewController animated:YES completion:^{
|
|
113
|
-
resolve(@(YES));
|
|
114
|
-
}];
|
|
115
|
-
} else if ([action isEqualToString:@"showModalLayout"]) {
|
|
116
|
-
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
117
|
-
NSDictionary *layout = extras[@"layout"];
|
|
118
|
-
viewController = [[HBDReactBridgeManager get] controllerWithLayout:layout];
|
|
119
|
-
viewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
120
|
-
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
121
|
-
[viewController setRequestCode:requestCode];
|
|
122
|
-
[target presentViewController:viewController animated:YES completion:^{
|
|
123
|
-
resolve(@(YES));
|
|
124
|
-
}];
|
|
68
|
+
[self handlePresentWithViewController:vc extras:extras callback:callback];
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if ([action isEqualToString:@"dismiss"]) {
|
|
73
|
+
[self handleDismissWithViewController:vc callback:callback];
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if ([action isEqualToString:@"showModal"]) {
|
|
78
|
+
[self handleShowModalWithViewController:vc extras:extras callback:callback];
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if ([action isEqualToString:@"hideModal"]) {
|
|
83
|
+
[self handleDismissWithViewController:vc callback:callback];
|
|
84
|
+
return;
|
|
125
85
|
}
|
|
86
|
+
|
|
87
|
+
if ([action isEqualToString:@"presentLayout"]) {
|
|
88
|
+
[self handlePresentLayoutWithViewController:vc extras:extras callback:callback];
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if ([action isEqualToString:@"showModalLayout"]) {
|
|
93
|
+
[self handleShowModalLayoutWithViewController:vc extras:extras callback:callback];
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
- (void)handlePresentWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
99
|
+
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
100
|
+
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
101
|
+
HBDNavigationController *nav = [[HBDNavigationController alloc] initWithRootViewController:vc];
|
|
102
|
+
nav.modalPresentationStyle = UIModalPresentationCurrentContext;
|
|
103
|
+
[nav setRequestCode:requestCode];
|
|
104
|
+
[presenting presentViewController:nav animated:YES completion:^{
|
|
105
|
+
callback(@[NSNull.null, @YES]);
|
|
106
|
+
}];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
- (void)handleDismissWithViewController:(UIViewController *) vc callback:(RCTResponseSenderBlock)callback {
|
|
110
|
+
[vc dismissViewControllerAnimated:YES completion:^{
|
|
111
|
+
callback(@[NSNull.null, @YES]);
|
|
112
|
+
}];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
- (void)handleShowModalWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
116
|
+
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
117
|
+
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
118
|
+
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
119
|
+
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
120
|
+
[vc setRequestCode:requestCode];
|
|
121
|
+
[presenting presentViewController:vc animated:YES completion:^{
|
|
122
|
+
callback(@[NSNull.null, @YES]);
|
|
123
|
+
}];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
- (void)handlePresentLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
127
|
+
NSDictionary *layout = extras[@"layout"];
|
|
128
|
+
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
129
|
+
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
|
|
130
|
+
[vc setRequestCode:requestCode];
|
|
131
|
+
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
|
|
132
|
+
[presenting presentViewController:vc animated:YES completion:^{
|
|
133
|
+
callback(@[NSNull.null, @YES]);
|
|
134
|
+
}];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
- (void)handleShowModalLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
138
|
+
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
139
|
+
NSDictionary *layout = extras[@"layout"];
|
|
140
|
+
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
|
|
141
|
+
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
142
|
+
vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
|
|
143
|
+
[vc setRequestCode:requestCode];
|
|
144
|
+
[presenting presentViewController:vc animated:YES completion:^{
|
|
145
|
+
callback(@[NSNull.null, @YES]);
|
|
146
|
+
}];
|
|
126
147
|
}
|
|
127
148
|
|
|
128
|
-
- (UIViewController *)
|
|
149
|
+
- (UIViewController *)viewControllerWithExtras:(NSDictionary *)extras {
|
|
129
150
|
NSString *moduleName = extras[@"moduleName"];
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
NSDictionary *props = extras[@"props"];
|
|
133
|
-
NSDictionary *options = extras[@"options"];
|
|
134
|
-
viewController = [[HBDReactBridgeManager get] controllerWithModuleName:moduleName props:props options:options];
|
|
151
|
+
if (!moduleName) {
|
|
152
|
+
return nil;
|
|
135
153
|
}
|
|
136
|
-
|
|
154
|
+
NSDictionary *props = extras[@"props"];
|
|
155
|
+
NSDictionary *options = extras[@"options"];
|
|
156
|
+
return [[HBDReactBridgeManager get] viewControllerWithModuleName:moduleName props:props options:options];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
-(void)handleNavigation:(NSDictionary *)params {
|
|
160
|
+
[self handleNavigationWithViewController:params[@"viewController"] action:params[@"action"] extras:params[@"extras"] callback:params[@"callback"]];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
- (void)invalidate {
|
|
164
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self];
|
|
137
165
|
}
|
|
138
166
|
|
|
139
167
|
@end
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
//
|
|
2
|
-
// HBDStackNavigator.h
|
|
3
|
-
// HybridNavigation
|
|
4
|
-
//
|
|
5
|
-
// Created by Listen on 2018/6/28.
|
|
6
|
-
// Copyright © 2018年 Listen. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
#import <Foundation/Foundation.h>
|
|
10
1
|
#import "HBDNavigator.h"
|
|
11
2
|
|
|
12
3
|
@interface HBDStackNavigator : NSObject <HBDNavigator>
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
// HBDStackNavigator.m
|
|
3
|
-
// HybridNavigation
|
|
4
|
-
//
|
|
5
|
-
// Created by Listen on 2018/6/28.
|
|
6
|
-
// Copyright © 2018年 Listen. All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
|
|
9
1
|
#import "HBDStackNavigator.h"
|
|
2
|
+
|
|
10
3
|
#import "HBDReactBridgeManager.h"
|
|
11
4
|
#import "HBDNavigationController.h"
|
|
12
5
|
#import "UINavigationController+HBD.h"
|
|
@@ -21,177 +14,241 @@
|
|
|
21
14
|
return @[@"push", @"pushLayout", @"pop", @"popTo", @"popToRoot", @"redirectTo"];
|
|
22
15
|
}
|
|
23
16
|
|
|
24
|
-
- (UIViewController *)
|
|
25
|
-
NSDictionary *
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
UIViewController *root = [[HBDReactBridgeManager get] controllerWithLayout:children.firstObject];
|
|
29
|
-
if (root) {
|
|
30
|
-
return [[HBDNavigationController alloc] initWithRootViewController:root];
|
|
31
|
-
}
|
|
17
|
+
- (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
|
|
18
|
+
NSDictionary *model = layout[self.name];
|
|
19
|
+
if (!model) {
|
|
20
|
+
return nil;
|
|
32
21
|
}
|
|
33
|
-
|
|
22
|
+
|
|
23
|
+
NSArray *children = model[@"children"];
|
|
24
|
+
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:children.firstObject];
|
|
25
|
+
return [[HBDNavigationController alloc] initWithRootViewController:vc];
|
|
34
26
|
}
|
|
35
27
|
|
|
36
|
-
- (NSDictionary *)
|
|
37
|
-
if ([vc isKindOfClass:[HBDNavigationController class]]) {
|
|
38
|
-
|
|
39
|
-
NSMutableArray *children = [[NSMutableArray alloc] init];
|
|
40
|
-
for (NSUInteger i = 0; i < nav.childViewControllers.count; i++) {
|
|
41
|
-
UIViewController *child = nav.childViewControllers[i];
|
|
42
|
-
NSDictionary *graph = [[HBDReactBridgeManager get] buildRouteGraphWithViewController:child];
|
|
43
|
-
[children addObject:graph];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return @{
|
|
47
|
-
@"layout": @"stack",
|
|
48
|
-
@"sceneId": vc.sceneId,
|
|
49
|
-
@"children": children,
|
|
50
|
-
@"mode": [vc hbd_mode],
|
|
51
|
-
};
|
|
28
|
+
- (NSDictionary *)routeGraphWithViewController:(UIViewController *)vc {
|
|
29
|
+
if (![vc isKindOfClass:[HBDNavigationController class]]) {
|
|
30
|
+
return nil;
|
|
52
31
|
}
|
|
53
|
-
|
|
32
|
+
|
|
33
|
+
HBDNavigationController *nav = (HBDNavigationController *) vc;
|
|
34
|
+
|
|
35
|
+
NSMutableArray *children = [[NSMutableArray alloc] init];
|
|
36
|
+
for (NSUInteger i = 0; i < nav.childViewControllers.count; i++) {
|
|
37
|
+
UIViewController *child = nav.childViewControllers[i];
|
|
38
|
+
NSDictionary *graph = [[HBDReactBridgeManager get] routeGraphWithViewController:child];
|
|
39
|
+
[children addObject:graph];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return @{
|
|
43
|
+
@"layout": @"stack",
|
|
44
|
+
@"sceneId": nav.sceneId,
|
|
45
|
+
@"children": children,
|
|
46
|
+
@"mode": [nav hbd_mode],
|
|
47
|
+
};
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
- (HBDViewController *)primaryViewControllerWithViewController:(UIViewController *)vc {
|
|
57
|
-
if ([vc isKindOfClass:[UINavigationController class]]) {
|
|
58
|
-
|
|
59
|
-
return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:nav.topViewController];
|
|
51
|
+
if (![vc isKindOfClass:[UINavigationController class]]) {
|
|
52
|
+
return nil;
|
|
60
53
|
}
|
|
61
|
-
|
|
54
|
+
UINavigationController *nav = (UINavigationController *)vc;
|
|
55
|
+
return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:nav.topViewController];
|
|
62
56
|
}
|
|
63
57
|
|
|
64
|
-
- (void)handleNavigationWithViewController:(UIViewController *)
|
|
65
|
-
|
|
58
|
+
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
59
|
+
if (!vc.hbd_inViewHierarchy) {
|
|
60
|
+
callback(@[NSNull.null, @NO]);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
UINavigationController *nav = [self navigationControllerForViewController:vc];
|
|
66
65
|
if (!nav) {
|
|
67
|
-
|
|
66
|
+
callback(@[NSNull.null, @NO]);
|
|
68
67
|
return;
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
if (nav.transitionCoordinator) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
[selfObj handleNavigationWithViewController:target action:action extras:extras resolver:resolve rejecter:reject];
|
|
71
|
+
[nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
72
|
+
// empty
|
|
73
|
+
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
74
|
+
[self handleNavigationWithViewController:vc action:action extras:extras callback:callback];
|
|
77
75
|
}];
|
|
78
76
|
return;
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
if (!nav.hbd_viewAppeared) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
[self performSelector:@selector(handleNavigation:) withObject:@{
|
|
81
|
+
@"viewController": vc,
|
|
82
|
+
@"action": action,
|
|
83
|
+
@"extras": extras,
|
|
84
|
+
@"callback": callback,
|
|
85
|
+
} afterDelay:0.05];
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
UIViewController *viewController = nil;
|
|
90
|
-
|
|
91
89
|
if ([action isEqualToString:@"push"]) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
90
|
+
[self handlePushWithNavigationController:nav extras:extras callback:callback];
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ([action isEqualToString:@"pop"]) {
|
|
95
|
+
[self handlePopWithNavigationController:nav callback:callback];
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if ([action isEqualToString:@"popTo"]) {
|
|
100
|
+
[self handlePopToWithNavigationController:nav extras:extras callback:callback];
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if ([action isEqualToString:@"popToRoot"]) {
|
|
105
|
+
[self handlePopToRootWithNavigationController:nav extras:extras callback:callback];
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if ([action isEqualToString:@"redirectTo"]) {
|
|
110
|
+
[self handleRedirectToWithNavigationController:nav target:vc extras:extras callback:callback];
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if ([action isEqualToString:@"pushLayout"]) {
|
|
115
|
+
[self handlePushLayoutWithNavigationController:nav extras:extras callback:callback];
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
- (void)handlePushWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
121
|
+
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
122
|
+
if (!vc) {
|
|
123
|
+
callback(@[NSNull.null, @NO]);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
vc.hidesBottomBarWhenPushed = nav.hidesBottomBarWhenPushed;
|
|
128
|
+
[nav pushViewController:vc animated:YES];
|
|
129
|
+
[self animateAlongsideTransition:nav callback:callback];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
- (void)handlePopWithNavigationController:(UINavigationController *)nav callback:(RCTResponseSenderBlock)callback {
|
|
133
|
+
[nav popViewControllerAnimated:YES];
|
|
134
|
+
[self animateAlongsideTransition:nav callback:callback];
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
- (void)handlePopToWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
138
|
+
UIViewController *vc = [self findViewControllerWithNavigationController:nav extras:extras];
|
|
139
|
+
if (!vc) {
|
|
140
|
+
callback(@[NSNull.null, @NO]);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
[nav popToViewController:vc animated:YES];
|
|
145
|
+
[self animateAlongsideTransition:nav callback:callback];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
- (UIViewController *)findViewControllerWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras {
|
|
149
|
+
NSArray *children = nav.childViewControllers;
|
|
150
|
+
NSString *moduleName = extras[@"moduleName"];
|
|
151
|
+
BOOL inclusive = [extras[@"inclusive"] boolValue];
|
|
152
|
+
|
|
153
|
+
for (NSUInteger i = children.count; i > 0; i--) {
|
|
154
|
+
NSUInteger index = i - 1;
|
|
155
|
+
HBDViewController *vc = children[index];
|
|
156
|
+
if ([moduleName isEqualToString:vc.moduleName] || [moduleName isEqualToString:vc.sceneId]) {
|
|
157
|
+
if (inclusive && index > 0) {
|
|
158
|
+
return children[index - 1];
|
|
121
159
|
}
|
|
160
|
+
return vc;
|
|
122
161
|
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return nil;
|
|
165
|
+
}
|
|
123
166
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
resolve(@(YES));
|
|
135
|
-
};
|
|
136
|
-
[nav popToRootViewControllerAnimated:YES];
|
|
137
|
-
} else if ([action isEqualToString:@"redirectTo"]) {
|
|
138
|
-
viewController = [self createViewControllerWithExtras:extras];
|
|
139
|
-
if (!viewController) {
|
|
140
|
-
resolve(@(NO));
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
viewController.didShowActionBlock = ^{
|
|
144
|
-
resolve(@(YES));
|
|
145
|
-
};
|
|
146
|
-
[nav redirectToViewController:viewController target:target animated:YES];
|
|
147
|
-
} else if ([action isEqualToString:@"pushLayout"]) {
|
|
148
|
-
NSDictionary *layout = extras[@"layout"];
|
|
149
|
-
viewController = [[HBDReactBridgeManager get] controllerWithLayout:layout];
|
|
150
|
-
if (viewController) {
|
|
151
|
-
viewController.hidesBottomBarWhenPushed = nav.hidesBottomBarWhenPushed;
|
|
152
|
-
viewController.didShowActionBlock = ^{
|
|
153
|
-
resolve(@(YES));
|
|
154
|
-
};
|
|
155
|
-
[nav pushViewController:viewController animated:YES];
|
|
156
|
-
} else {
|
|
157
|
-
resolve(@(NO));
|
|
158
|
-
}
|
|
167
|
+
- (void)handlePopToRootWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
168
|
+
[nav popToRootViewControllerAnimated:YES];
|
|
169
|
+
[self animateAlongsideTransition:nav callback:callback];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
- (void)handleRedirectToWithNavigationController:(UINavigationController *)nav target:(UIViewController *)target extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
173
|
+
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
174
|
+
if (!vc) {
|
|
175
|
+
callback(@[NSNull.null, @NO]);
|
|
176
|
+
return;
|
|
159
177
|
}
|
|
178
|
+
|
|
179
|
+
[nav redirectToViewController:vc target:target animated:YES];
|
|
180
|
+
[self animateAlongsideTransition:nav callback:callback];
|
|
160
181
|
}
|
|
161
182
|
|
|
162
|
-
- (
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
viewController = [[HBDReactBridgeManager get] controllerWithModuleName:moduleName props:props options:options];
|
|
183
|
+
- (void)handlePushLayoutWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras callback:(RCTResponseSenderBlock)callback {
|
|
184
|
+
NSDictionary *layout = extras[@"layout"];
|
|
185
|
+
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
|
|
186
|
+
if (!vc) {
|
|
187
|
+
callback(@[NSNull.null, @NO]);
|
|
188
|
+
return;
|
|
169
189
|
}
|
|
170
|
-
|
|
190
|
+
|
|
191
|
+
vc.hidesBottomBarWhenPushed = nav.hidesBottomBarWhenPushed;
|
|
192
|
+
[nav pushViewController:vc animated:YES];
|
|
193
|
+
[self animateAlongsideTransition:nav callback:callback];
|
|
171
194
|
}
|
|
172
195
|
|
|
173
|
-
- (UINavigationController *)
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
} else {
|
|
178
|
-
nav = controller.navigationController;
|
|
196
|
+
- (void)animateAlongsideTransition:(UINavigationController *)nav callback:(RCTResponseSenderBlock)callback {
|
|
197
|
+
if (!nav.transitionCoordinator) {
|
|
198
|
+
callback(@[NSNull.null, @YES]);
|
|
199
|
+
return;
|
|
179
200
|
}
|
|
201
|
+
|
|
202
|
+
[nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
203
|
+
// empty
|
|
204
|
+
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
205
|
+
callback(@[NSNull.null, @YES]);
|
|
206
|
+
}];
|
|
207
|
+
}
|
|
180
208
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
209
|
+
- (UIViewController *)viewControllerWithExtras:(NSDictionary *)extras {
|
|
210
|
+
NSString *moduleName = extras[@"moduleName"];
|
|
211
|
+
NSDictionary *props = extras[@"props"];
|
|
212
|
+
NSDictionary *options = extras[@"options"];
|
|
213
|
+
return [[HBDReactBridgeManager get] viewControllerWithModuleName:moduleName props:props options:options];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
- (UINavigationController *)navigationControllerForViewController:(UIViewController *)vc {
|
|
217
|
+
if ([vc isKindOfClass:[UINavigationController class]]) {
|
|
218
|
+
return (UINavigationController *)vc;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
UINavigationController *nav = vc.navigationController;
|
|
222
|
+
if (nav) {
|
|
223
|
+
return nav;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
HBDDrawerController *drawer = vc.drawerController;
|
|
227
|
+
if (!drawer) {
|
|
228
|
+
return nil;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if ([drawer.contentController isKindOfClass:[UITabBarController class]]) {
|
|
232
|
+
UITabBarController *tabBar = (UITabBarController *) drawer.contentController;
|
|
233
|
+
if ([tabBar.selectedViewController isKindOfClass:[UINavigationController class]]) {
|
|
234
|
+
return (UINavigationController *)tabBar.selectedViewController;
|
|
192
235
|
}
|
|
236
|
+
return nil;
|
|
193
237
|
}
|
|
194
|
-
|
|
238
|
+
|
|
239
|
+
if ([drawer.contentController isKindOfClass:[UINavigationController class]]) {
|
|
240
|
+
return (UINavigationController *) drawer.contentController;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return nil;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
-(void)handleNavigation:(NSDictionary *)params {
|
|
247
|
+
[self handleNavigationWithViewController:params[@"viewController"] action:params[@"action"] extras:params[@"extras"] callback:params[@"callback"]];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
- (void)invalidate {
|
|
251
|
+
[NSObject cancelPreviousPerformRequestsWithTarget:self];
|
|
195
252
|
}
|
|
196
253
|
|
|
197
254
|
@end
|