hybrid-navigation 4.0.8 → 5.0.0
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/HybridNavigation.podspec +9 -1
- package/README.md +12 -4
- package/android/build.gradle +5 -4
- package/android/proguard-rules.pro +3 -0
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +114 -23
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +116 -13
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +192 -28
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +11 -0
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +563 -143
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +47 -15
- package/android/src/main/java/com/navigation/androidx/PresentableActivity.java +3 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +8 -3
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +28 -3
- package/android/src/main/java/com/navigation/androidx/SystemUI.java +59 -90
- package/android/src/main/java/com/navigation/androidx/TabBar.java +21 -2
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +24 -7
- package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +59 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +15 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +3 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +113 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridNavigationPackage.java +13 -24
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +5 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +196 -194
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +499 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +4 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +162 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +103 -66
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +50 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +156 -77
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactSurfaceCleanup.java +3 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +8 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleState.java +21 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +116 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/ScreenOrientation.java +42 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +17 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +14 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +62 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +35 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +16 -13
- package/dist/DeepLink.d.ts +3 -2
- package/dist/DeepLink.js +37 -14
- package/dist/NativeEvent.d.ts +4 -12
- package/dist/NativeNavigation.d.ts +17 -19
- package/dist/Navigation.d.ts +21 -19
- package/dist/Navigation.js +83 -89
- package/dist/NavigationComponentWrap.d.ts +4 -3
- package/dist/NavigationComponentWrap.js +3 -6
- package/dist/Navigator.d.ts +31 -42
- package/dist/Navigator.js +97 -90
- package/dist/Options.d.ts +3 -1
- package/dist/Route.d.ts +85 -18
- package/dist/handler/DispatchCommandHandler.d.ts +10 -6
- package/dist/handler/DispatchCommandHandler.js +41 -17
- package/dist/handler/LayoutCommandHandler.d.ts +7 -7
- package/dist/handler/LayoutCommandHandler.js +21 -15
- package/dist/handler/LifecycleEventHandler.d.ts +26 -0
- package/dist/handler/LifecycleEventHandler.js +136 -0
- package/dist/handler/ResultEventHandler.d.ts +14 -9
- package/dist/handler/ResultEventHandler.js +88 -13
- package/dist/hooks.d.ts +5 -2
- package/dist/hooks.js +26 -4
- package/dist/index.d.ts +13 -0
- package/dist/index.js +0 -2
- package/dist/routeConfigRegistry.d.ts +6 -0
- package/dist/routeConfigRegistry.js +19 -0
- package/dist/router/drawer.d.ts +2 -2
- package/dist/router/drawer.js +6 -3
- package/dist/router/index.d.ts +8 -5
- package/dist/router/index.js +127 -43
- package/dist/router/screen.d.ts +2 -2
- package/dist/router/screen.js +1 -1
- package/dist/router/stack.d.ts +2 -2
- package/dist/router/stack.js +59 -30
- package/dist/router/tabs.d.ts +2 -2
- package/dist/router/tabs.js +4 -1
- package/dist/store.d.ts +2 -2
- package/ios/HBDGlobalStyle.h +26 -0
- package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +30 -27
- package/ios/HybridNavigation.h +4 -1
- package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
- package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +106 -52
- package/ios/Navigator/HBDStackNavigator.mm +109 -61
- package/ios/Navigator/HBDTabNavigator.mm +32 -14
- package/ios/React/HBDNativeNavigation.mm +109 -131
- package/ios/React/HBDNavigator.h +29 -5
- package/ios/React/HBDOrientationCoordinator.h +27 -0
- package/ios/React/HBDOrientationCoordinator.mm +282 -0
- package/ios/React/HBDReactBridgeManager.h +37 -19
- package/ios/React/HBDReactBridgeManager.mm +490 -96
- package/ios/React/HBDSceneLifecycleStateMachine.h +38 -0
- package/ios/React/HBDSceneLifecycleStateMachine.mm +180 -0
- package/ios/View/HBDRootView.h +2 -0
- package/ios/View/HBDRootView.mm +148 -0
- package/ios/View/UIImage+WithBadge.h +3 -3
- package/ios/View/UIImage+WithBadge.mm +10 -15
- package/ios/ViewController/HBDDrawerController.mm +127 -6
- package/ios/ViewController/HBDNavigationController.mm +17 -4
- package/ios/ViewController/HBDReactViewController.mm +59 -121
- package/ios/ViewController/HBDTabBarController.h +4 -0
- package/ios/ViewController/HBDTabBarController.mm +59 -44
- package/ios/ViewController/HBDViewController.h +10 -3
- package/ios/ViewController/HBDViewController.mm +161 -147
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +3 -3
- package/ios/ViewController/UIViewController+HBD.h +17 -10
- package/ios/ViewController/UIViewController+HBD.mm +85 -69
- package/package.json +1 -1
- package/src/DeepLink.ts +41 -14
- package/src/NativeEvent.ts +4 -14
- package/src/NativeNavigation.ts +22 -33
- package/src/Navigation.ts +162 -121
- package/src/NavigationComponentWrap.tsx +9 -9
- package/src/Navigator.ts +191 -153
- package/src/Options.ts +3 -1
- package/src/Route.ts +134 -19
- package/src/handler/DispatchCommandHandler.ts +55 -21
- package/src/handler/LayoutCommandHandler.ts +36 -17
- package/src/handler/LifecycleEventHandler.ts +172 -0
- package/src/handler/ResultEventHandler.ts +112 -19
- package/src/hooks.ts +39 -7
- package/src/index.ts +26 -2
- package/src/routeConfigRegistry.ts +26 -0
- package/src/router/drawer.ts +8 -5
- package/src/router/index.ts +161 -50
- package/src/router/screen.ts +3 -3
- package/src/router/stack.ts +80 -29
- package/src/router/tabs.ts +15 -7
- package/src/store.ts +1 -1
- package/android/src/main/java/androidx/fragment/app/InternalFragment.java +0 -22
- package/android/src/main/java/com/navigation/androidx/SystemUI30.java +0 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeGarden.java +0 -176
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBar.java +0 -130
- package/android/src/main/res/layout/nav_tab_bar_react.xml +0 -32
- package/android/src/main/res/layout/nav_tab_bar_react_indeterminate.xml +0 -32
- package/dist/NativeGarden.d.ts +0 -13
- package/dist/NativeGarden.js +0 -2
- package/dist/handler/VisibilityEventHandler.d.ts +0 -13
- package/dist/handler/VisibilityEventHandler.js +0 -39
- package/ios/GlobalStyle.h +0 -15
- package/ios/React/HBDNativeGarden.h +0 -10
- package/ios/React/HBDNativeGarden.mm +0 -111
- package/src/NativeGarden.ts +0 -16
- package/src/handler/VisibilityEventHandler.ts +0 -52
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#import "HBDStackNavigator.h"
|
|
2
2
|
|
|
3
|
-
#import "HBDReactBridgeManager.h"
|
|
4
3
|
#import "HBDNavigationController.h"
|
|
4
|
+
#import "HBDReactBridgeManager.h"
|
|
5
5
|
#import "UINavigationController+HBD.h"
|
|
6
6
|
|
|
7
7
|
#import <React/RCTLog.h>
|
|
@@ -23,7 +23,13 @@
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
NSArray *children = model[@"children"];
|
|
26
|
+
if (![children isKindOfClass:[NSArray class]] || children.count == 0) {
|
|
27
|
+
return nil;
|
|
28
|
+
}
|
|
26
29
|
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:children.firstObject];
|
|
30
|
+
if (!vc) {
|
|
31
|
+
return nil;
|
|
32
|
+
}
|
|
27
33
|
return [[HBDNavigationController alloc] initWithRootViewController:vc];
|
|
28
34
|
}
|
|
29
35
|
|
|
@@ -32,18 +38,20 @@
|
|
|
32
38
|
return nil;
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
HBDNavigationController *nav = (HBDNavigationController *)
|
|
41
|
+
HBDNavigationController *nav = (HBDNavigationController *)vc;
|
|
36
42
|
|
|
37
43
|
NSMutableArray *children = [[NSMutableArray alloc] init];
|
|
38
44
|
for (NSUInteger i = 0; i < nav.childViewControllers.count; i++) {
|
|
39
45
|
UIViewController *child = nav.childViewControllers[i];
|
|
40
46
|
NSDictionary *graph = [[HBDReactBridgeManager get] routeGraphWithViewController:child];
|
|
41
|
-
|
|
47
|
+
if (graph) {
|
|
48
|
+
[children addObject:graph];
|
|
49
|
+
}
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
return @{
|
|
45
53
|
@"layout": @"stack",
|
|
46
|
-
@"sceneId": nav.
|
|
54
|
+
@"sceneId": nav.hbd_sceneId,
|
|
47
55
|
@"children": children,
|
|
48
56
|
@"mode": [nav hbd_mode],
|
|
49
57
|
};
|
|
@@ -57,102 +65,112 @@
|
|
|
57
65
|
return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:nav.topViewController];
|
|
58
66
|
}
|
|
59
67
|
|
|
60
|
-
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras
|
|
68
|
+
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
61
69
|
UINavigationController *nav = [self navigationControllerForViewController:vc];
|
|
62
70
|
if (!nav) {
|
|
63
71
|
RCTLogInfo(@"[Navigation] 找不到对应的 UINavigationController from:%@", extras[@"from"]);
|
|
64
|
-
|
|
72
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Target scene is not inside a navigation stack."));
|
|
65
73
|
return;
|
|
66
74
|
}
|
|
67
75
|
|
|
68
76
|
if (nav.transitionCoordinator) {
|
|
69
77
|
RCTLogInfo(@"[Navigation] 等待上个 action 执行完成 from:%@ %@ to:%@", extras[@"from"], action, extras[@"to"]);
|
|
78
|
+
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
79
|
+
NSUInteger commandId = manager.activeCommandId;
|
|
70
80
|
[nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
71
81
|
// empty
|
|
72
82
|
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
73
|
-
// 确保最后执行
|
|
74
83
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
75
|
-
|
|
84
|
+
if (commandId != 0 && manager.activeCommandId != commandId) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
[self handleNavigationWithViewController:vc action:action extras:extras completion:completion];
|
|
76
88
|
});
|
|
77
89
|
}];
|
|
78
90
|
return;
|
|
79
91
|
}
|
|
80
92
|
|
|
81
93
|
if ([action isEqualToString:@"push"]) {
|
|
82
|
-
[self handlePushWithNavigationController:nav extras:extras
|
|
94
|
+
[self handlePushWithNavigationController:nav extras:extras completion:completion];
|
|
83
95
|
return;
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
if ([action isEqualToString:@"pop"]) {
|
|
87
|
-
[self handlePopWithNavigationController:nav viewController:vc
|
|
99
|
+
[self handlePopWithNavigationController:nav viewController:vc completion:completion];
|
|
88
100
|
return;
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
if ([action isEqualToString:@"popTo"]) {
|
|
92
|
-
[self handlePopToWithNavigationController:nav extras:extras
|
|
104
|
+
[self handlePopToWithNavigationController:nav extras:extras completion:completion];
|
|
93
105
|
return;
|
|
94
106
|
}
|
|
95
107
|
|
|
96
108
|
if ([action isEqualToString:@"popToRoot"]) {
|
|
97
|
-
[self handlePopToRootWithNavigationController:nav extras:extras
|
|
109
|
+
[self handlePopToRootWithNavigationController:nav extras:extras completion:completion];
|
|
98
110
|
return;
|
|
99
111
|
}
|
|
100
112
|
|
|
101
113
|
if ([action isEqualToString:@"redirectTo"]) {
|
|
102
|
-
[self handleRedirectToWithNavigationController:nav target:vc extras:extras
|
|
114
|
+
[self handleRedirectToWithNavigationController:nav target:vc extras:extras completion:completion];
|
|
103
115
|
return;
|
|
104
116
|
}
|
|
105
117
|
|
|
106
118
|
if ([action isEqualToString:@"pushLayout"]) {
|
|
107
|
-
[self handlePushLayoutWithNavigationController:nav extras:extras
|
|
119
|
+
[self handlePushLayoutWithNavigationController:nav extras:extras completion:completion];
|
|
108
120
|
return;
|
|
109
121
|
}
|
|
122
|
+
|
|
123
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Unsupported stack action: %@", action]));
|
|
110
124
|
}
|
|
111
125
|
|
|
112
|
-
- (void)handlePushWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras
|
|
126
|
+
- (void)handlePushWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
113
127
|
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
114
128
|
if (!vc) {
|
|
115
129
|
RCTLogInfo(@"[Navigation] 无法创建对应的页面 %@", extras[@"moduleName"]);
|
|
116
|
-
|
|
130
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create target screen for push."));
|
|
117
131
|
return;
|
|
118
132
|
}
|
|
133
|
+
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
134
|
+
if (requestCode != 0) {
|
|
135
|
+
[vc setHbd_requestCode:requestCode];
|
|
136
|
+
}
|
|
119
137
|
|
|
120
138
|
BOOL animated = YES;
|
|
121
139
|
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
122
|
-
HBDViewController *
|
|
123
|
-
|
|
140
|
+
HBDViewController *hbdvc = (HBDViewController *)vc;
|
|
141
|
+
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
124
142
|
}
|
|
125
143
|
|
|
126
144
|
if (animated) {
|
|
127
145
|
[nav pushViewController:vc animated:YES];
|
|
128
|
-
[self animateAlongsideTransition:nav
|
|
146
|
+
[self animateAlongsideTransition:nav completion:completion];
|
|
129
147
|
} else {
|
|
130
148
|
[nav pushViewController:vc animated:NO];
|
|
131
|
-
|
|
149
|
+
completion(HBDDispatchResultOk());
|
|
132
150
|
}
|
|
133
151
|
}
|
|
134
152
|
|
|
135
|
-
- (void)handlePopWithNavigationController:(UINavigationController *)nav viewController:(UIViewController *)vc
|
|
153
|
+
- (void)handlePopWithNavigationController:(UINavigationController *)nav viewController:(UIViewController *)vc completion:(HBDDispatchCompletion)completion {
|
|
136
154
|
BOOL animated = YES;
|
|
137
155
|
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
138
|
-
HBDViewController *
|
|
139
|
-
|
|
156
|
+
HBDViewController *hbdvc = (HBDViewController *)vc;
|
|
157
|
+
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
140
158
|
}
|
|
141
159
|
|
|
142
160
|
if (animated) {
|
|
143
161
|
[nav popViewControllerAnimated:YES];
|
|
144
|
-
[self animateAlongsideTransition:nav
|
|
162
|
+
[self animateAlongsideTransition:nav completion:completion];
|
|
145
163
|
} else {
|
|
146
164
|
[nav popViewControllerAnimated:NO];
|
|
147
|
-
|
|
165
|
+
completion(HBDDispatchResultOk());
|
|
148
166
|
}
|
|
149
167
|
}
|
|
150
168
|
|
|
151
|
-
- (void)handlePopToWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras
|
|
169
|
+
- (void)handlePopToWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
152
170
|
UIViewController *vc = [self findViewControllerWithNavigationController:nav extras:extras];
|
|
153
171
|
if (!vc) {
|
|
154
172
|
RCTLogInfo(@"[Navigation] 找不到要 popTo 的页面 %@", extras[@"moduleName"]);
|
|
155
|
-
|
|
173
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeSceneNotFound, [NSString stringWithFormat:@"Can't find target scene to popTo: %@", extras[@"moduleName"]]));
|
|
156
174
|
return;
|
|
157
175
|
}
|
|
158
176
|
|
|
@@ -161,17 +179,16 @@
|
|
|
161
179
|
BOOL animated = YES;
|
|
162
180
|
if ([from_vc isKindOfClass:[HBDViewController class]]) {
|
|
163
181
|
HBDViewController *hbdvc = (HBDViewController *)from_vc;
|
|
164
|
-
animated = hbdvc.animatedTransition || hbdvc.
|
|
182
|
+
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
165
183
|
}
|
|
166
184
|
|
|
167
185
|
if (animated) {
|
|
168
186
|
[nav popToViewController:vc animated:YES];
|
|
169
|
-
[self animateAlongsideTransition:nav
|
|
170
|
-
}else {
|
|
187
|
+
[self animateAlongsideTransition:nav completion:completion];
|
|
188
|
+
} else {
|
|
171
189
|
[nav popToViewController:vc animated:NO];
|
|
172
|
-
|
|
190
|
+
completion(HBDDispatchResultOk());
|
|
173
191
|
}
|
|
174
|
-
|
|
175
192
|
}
|
|
176
193
|
|
|
177
194
|
- (UIViewController *)findFromViewControllerWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras {
|
|
@@ -181,8 +198,9 @@
|
|
|
181
198
|
|
|
182
199
|
for (NSUInteger i = children.count; i > 0; i--) {
|
|
183
200
|
NSUInteger index = i - 1;
|
|
184
|
-
|
|
185
|
-
|
|
201
|
+
UIViewController *vc = children[index];
|
|
202
|
+
NSString *vcModuleName = [vc isKindOfClass:[HBDViewController class]] ? ((HBDViewController *)vc).moduleName : nil;
|
|
203
|
+
if ([moduleName isEqualToString:vcModuleName] || [moduleName isEqualToString:vc.hbd_sceneId]) {
|
|
186
204
|
if (inclusive && index > 0) {
|
|
187
205
|
return children[index - 1];
|
|
188
206
|
}
|
|
@@ -200,8 +218,9 @@
|
|
|
200
218
|
|
|
201
219
|
for (NSUInteger i = children.count; i > 0; i--) {
|
|
202
220
|
NSUInteger index = i - 1;
|
|
203
|
-
|
|
204
|
-
|
|
221
|
+
UIViewController *vc = children[index];
|
|
222
|
+
NSString *vcModuleName = [vc isKindOfClass:[HBDViewController class]] ? ((HBDViewController *)vc).moduleName : nil;
|
|
223
|
+
if ([moduleName isEqualToString:vcModuleName] || [moduleName isEqualToString:vc.hbd_sceneId]) {
|
|
205
224
|
if (inclusive && index > 0) {
|
|
206
225
|
return children[index - 1];
|
|
207
226
|
}
|
|
@@ -212,73 +231,77 @@
|
|
|
212
231
|
return nil;
|
|
213
232
|
}
|
|
214
233
|
|
|
215
|
-
- (void)handlePopToRootWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras
|
|
216
|
-
|
|
234
|
+
- (void)handlePopToRootWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
217
235
|
UIViewController *from_vc = [self findFromViewControllerWithNavigationController:nav extras:extras];
|
|
218
236
|
|
|
219
237
|
BOOL animated = YES;
|
|
220
|
-
|
|
221
238
|
if ([from_vc isKindOfClass:[HBDViewController class]]) {
|
|
222
239
|
HBDViewController *hbdvc = (HBDViewController *)from_vc;
|
|
223
|
-
animated = hbdvc.animatedTransition || hbdvc.
|
|
240
|
+
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
224
241
|
}
|
|
225
242
|
|
|
226
243
|
if (animated) {
|
|
227
244
|
[nav popToRootViewControllerAnimated:YES];
|
|
228
|
-
[self animateAlongsideTransition:nav
|
|
229
|
-
}else {
|
|
245
|
+
[self animateAlongsideTransition:nav completion:completion];
|
|
246
|
+
} else {
|
|
230
247
|
[nav popToRootViewControllerAnimated:NO];
|
|
231
|
-
|
|
248
|
+
completion(HBDDispatchResultOk());
|
|
232
249
|
}
|
|
233
250
|
}
|
|
234
251
|
|
|
235
|
-
- (void)handleRedirectToWithNavigationController:(UINavigationController *)nav target:(UIViewController *)target extras:(NSDictionary *)extras
|
|
252
|
+
- (void)handleRedirectToWithNavigationController:(UINavigationController *)nav target:(UIViewController *)target extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
236
253
|
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
237
254
|
if (!vc) {
|
|
238
255
|
RCTLogInfo(@"[Navigation] 无法创建对应的页面 %@", extras[@"moduleName"]);
|
|
239
|
-
|
|
256
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create target screen for redirectTo."));
|
|
240
257
|
return;
|
|
241
258
|
}
|
|
242
|
-
|
|
259
|
+
if (vc.hbd_requestCode == 0 && target.hbd_requestCode != 0) {
|
|
260
|
+
[vc setHbd_requestCode:target.hbd_requestCode];
|
|
261
|
+
}
|
|
243
262
|
|
|
263
|
+
BOOL animated = YES;
|
|
244
264
|
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
245
265
|
HBDViewController *hbdvc = (HBDViewController *)vc;
|
|
246
|
-
animated = hbdvc.animatedTransition || hbdvc.
|
|
266
|
+
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
247
267
|
}
|
|
248
268
|
|
|
249
269
|
if (animated) {
|
|
250
|
-
[nav
|
|
251
|
-
[self animateAlongsideTransition:nav
|
|
252
|
-
}else {
|
|
253
|
-
[nav
|
|
254
|
-
|
|
270
|
+
[nav hbd_redirectToViewController:vc target:target animated:YES];
|
|
271
|
+
[self animateAlongsideTransition:nav completion:completion];
|
|
272
|
+
} else {
|
|
273
|
+
[nav hbd_redirectToViewController:vc target:target animated:NO];
|
|
274
|
+
completion(HBDDispatchResultOk());
|
|
255
275
|
}
|
|
256
|
-
|
|
257
276
|
}
|
|
258
277
|
|
|
259
|
-
- (void)handlePushLayoutWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras
|
|
278
|
+
- (void)handlePushLayoutWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
260
279
|
NSDictionary *layout = extras[@"layout"];
|
|
261
280
|
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
|
|
262
281
|
if (!vc) {
|
|
263
282
|
RCTLogInfo(@"[Navigation] 无法创建对应的 vc");
|
|
264
|
-
|
|
283
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create layout for pushLayout."));
|
|
265
284
|
return;
|
|
266
285
|
}
|
|
286
|
+
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
287
|
+
if (requestCode != 0) {
|
|
288
|
+
[vc setHbd_requestCode:requestCode];
|
|
289
|
+
}
|
|
267
290
|
|
|
268
291
|
[nav pushViewController:vc animated:YES];
|
|
269
|
-
[self animateAlongsideTransition:nav
|
|
292
|
+
[self animateAlongsideTransition:nav completion:completion];
|
|
270
293
|
}
|
|
271
294
|
|
|
272
|
-
- (void)animateAlongsideTransition:(UINavigationController *)nav
|
|
295
|
+
- (void)animateAlongsideTransition:(UINavigationController *)nav completion:(HBDDispatchCompletion)completion {
|
|
273
296
|
if (!nav.transitionCoordinator) {
|
|
274
|
-
|
|
297
|
+
completion(HBDDispatchResultOk());
|
|
275
298
|
return;
|
|
276
299
|
}
|
|
277
300
|
|
|
278
301
|
[nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
279
302
|
// empty
|
|
280
303
|
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
281
|
-
|
|
304
|
+
completion(HBDDispatchResultOk());
|
|
282
305
|
}];
|
|
283
306
|
}
|
|
284
307
|
|
|
@@ -294,11 +317,36 @@
|
|
|
294
317
|
return (UINavigationController *)vc;
|
|
295
318
|
}
|
|
296
319
|
|
|
297
|
-
|
|
320
|
+
if (vc.navigationController) {
|
|
321
|
+
return vc.navigationController;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return [self navigationControllerFromDrawerIfExist:vc];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
- (nullable UINavigationController *)navigationControllerFromDrawerIfExist:(UIViewController *)vc {
|
|
328
|
+
HBDDrawerController *drawer = [vc hbd_drawerController];
|
|
329
|
+
if (!drawer) {
|
|
330
|
+
return nil;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
UIViewController *content = drawer.contentController;
|
|
334
|
+
if ([content isKindOfClass:[UITabBarController class]]) {
|
|
335
|
+
UIViewController *selected = ((UITabBarController *)content).selectedViewController;
|
|
336
|
+
if ([selected isKindOfClass:[UINavigationController class]]) {
|
|
337
|
+
return (UINavigationController *)selected;
|
|
338
|
+
}
|
|
339
|
+
return selected.navigationController;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if ([content isKindOfClass:[UINavigationController class]]) {
|
|
343
|
+
return (UINavigationController *)content;
|
|
344
|
+
}
|
|
345
|
+
return content.navigationController;
|
|
298
346
|
}
|
|
299
347
|
|
|
300
348
|
- (void)invalidate {
|
|
301
|
-
|
|
349
|
+
//
|
|
302
350
|
}
|
|
303
351
|
|
|
304
352
|
@end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
#import "HBDTabBarController.h"
|
|
4
4
|
#import "HBDReactBridgeManager.h"
|
|
5
5
|
#import "HBDUtils.h"
|
|
6
|
-
#import "
|
|
6
|
+
#import "HBDGlobalStyle.h"
|
|
7
7
|
|
|
8
8
|
#import <React/RCTUtils.h>
|
|
9
9
|
|
|
@@ -27,7 +27,12 @@
|
|
|
27
27
|
NSMutableArray *viewControllers = [[NSMutableArray alloc] initWithCapacity:4];
|
|
28
28
|
for (NSDictionary *tab in children) {
|
|
29
29
|
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:tab];
|
|
30
|
-
|
|
30
|
+
if (vc) {
|
|
31
|
+
[viewControllers addObject:vc];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (viewControllers.count == 0) {
|
|
35
|
+
return nil;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
NSDictionary *options = model[@"options"];
|
|
@@ -54,12 +59,14 @@
|
|
|
54
59
|
for (NSUInteger i = 0; i < tabBarController.childViewControllers.count; i++) {
|
|
55
60
|
UIViewController *child = tabBarController.childViewControllers[i];
|
|
56
61
|
NSDictionary *graph = [[HBDReactBridgeManager get] routeGraphWithViewController:child];
|
|
57
|
-
|
|
62
|
+
if (graph) {
|
|
63
|
+
[children addObject:graph];
|
|
64
|
+
}
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
return @{
|
|
61
68
|
@"layout": self.name,
|
|
62
|
-
@"sceneId": tabBarController.
|
|
69
|
+
@"sceneId": tabBarController.hbd_sceneId,
|
|
63
70
|
@"children": children,
|
|
64
71
|
@"mode": [tabBarController hbd_mode],
|
|
65
72
|
@"selectedIndex": @(tabBarController.selectedIndex)
|
|
@@ -82,13 +89,22 @@
|
|
|
82
89
|
}
|
|
83
90
|
}
|
|
84
91
|
|
|
85
|
-
- (void)handleSwitchTabWithTabBarController:(UITabBarController *)tabBarController extras:(NSDictionary *)extras
|
|
92
|
+
- (void)handleSwitchTabWithTabBarController:(UITabBarController *)tabBarController extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
86
93
|
BOOL popToRoot = [extras[@"popToRoot"] boolValue];
|
|
87
|
-
NSNumber *
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
NSNumber *toNumber = extras[@"to"];
|
|
95
|
+
if (![toNumber isKindOfClass:[NSNumber class]]) {
|
|
96
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Tab index is required for switchTab."));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
NSInteger toIndex = [toNumber integerValue];
|
|
100
|
+
if (toIndex < 0 || (NSUInteger)toIndex >= tabBarController.viewControllers.count) {
|
|
101
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Tab index out of bounds: %ld", (long)toIndex]));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
NSUInteger to = (NSUInteger)toIndex;
|
|
105
|
+
|
|
106
|
+
if (tabBarController.selectedIndex == to) {
|
|
107
|
+
completion(HBDDispatchResultOk());
|
|
92
108
|
return;
|
|
93
109
|
}
|
|
94
110
|
|
|
@@ -108,21 +124,23 @@
|
|
|
108
124
|
|
|
109
125
|
tabBarController.selectedIndex = to;
|
|
110
126
|
|
|
111
|
-
|
|
127
|
+
completion(HBDDispatchResultOk());
|
|
112
128
|
}
|
|
113
129
|
|
|
114
|
-
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras
|
|
130
|
+
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
115
131
|
UITabBarController *tabBarController = [self tabBarControllerForViewController:vc];
|
|
116
132
|
|
|
117
133
|
if (!tabBarController) {
|
|
118
|
-
|
|
134
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Target scene is not inside a tab bar."));
|
|
119
135
|
return;
|
|
120
136
|
}
|
|
121
137
|
|
|
122
138
|
if ([action isEqualToString:@"switchTab"]) {
|
|
123
|
-
[self handleSwitchTabWithTabBarController:tabBarController extras:extras
|
|
139
|
+
[self handleSwitchTabWithTabBarController:tabBarController extras:extras completion:completion];
|
|
124
140
|
return;
|
|
125
141
|
}
|
|
142
|
+
|
|
143
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Unsupported tab action: %@", action]));
|
|
126
144
|
}
|
|
127
145
|
|
|
128
146
|
- (void)invalidate {
|