hybrid-navigation 4.1.0 → 5.1.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 +4 -4
- package/android/proguard-rules.pro +0 -14
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +116 -27
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +162 -13
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +83 -18
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +185 -25
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +18 -0
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +563 -143
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +39 -12
- package/android/src/main/java/com/navigation/androidx/PresentableActivity.java +3 -0
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +10 -7
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +29 -9
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +31 -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 +74 -7
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +4 -0
- package/android/src/main/java/com/navigation/androidx/TabView.java +11 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/DispatchResult.java +71 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +18 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +34 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +20 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +179 -13
- 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 +283 -183
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +507 -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 +421 -92
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +227 -78
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +6 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +26 -0
- 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 +188 -26
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +67 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +42 -14
- package/dist/DeepLink.d.ts +3 -2
- package/dist/DeepLink.js +37 -14
- package/dist/NativeEvent.d.ts +17 -10
- package/dist/NativeNavigation.d.ts +24 -18
- package/dist/Navigation.d.ts +34 -19
- package/dist/Navigation.js +225 -90
- package/dist/NavigationComponentWrap.d.ts +5 -3
- package/dist/NavigationComponentWrap.js +3 -6
- package/dist/Navigator.d.ts +32 -42
- package/dist/Navigator.js +117 -91
- package/dist/Options.d.ts +15 -3
- package/dist/Route.d.ts +149 -17
- package/dist/defineRoutes.d.ts +19 -0
- package/dist/defineRoutes.js +6 -0
- package/dist/handler/DispatchCommandHandler.d.ts +25 -6
- package/dist/handler/DispatchCommandHandler.js +99 -17
- package/dist/handler/LayoutCommandHandler.d.ts +8 -7
- package/dist/handler/LayoutCommandHandler.js +24 -15
- package/dist/handler/LeaveGuardHandler.d.ts +17 -0
- package/dist/handler/LeaveGuardHandler.js +350 -0
- package/dist/handler/LifecycleEventHandler.d.ts +30 -0
- package/dist/handler/LifecycleEventHandler.js +169 -0
- package/dist/handler/PresentationCoordinator.d.ts +24 -0
- package/dist/handler/PresentationCoordinator.js +449 -0
- package/dist/handler/ResultEventHandler.d.ts +21 -9
- package/dist/handler/ResultEventHandler.js +96 -13
- package/dist/handler/TabEventHandler.d.ts +8 -0
- package/dist/handler/TabEventHandler.js +25 -0
- package/dist/hooks.d.ts +7 -2
- package/dist/hooks.js +46 -4
- package/dist/index.d.ts +24 -0
- package/dist/index.js +3 -2
- package/dist/reveal.d.ts +46 -0
- package/dist/reveal.js +431 -0
- package/dist/routeConfigRegistry.d.ts +6 -0
- package/dist/routeConfigRegistry.js +19 -0
- package/dist/routeGraph.d.ts +12 -0
- package/dist/routeGraph.js +68 -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 +106 -58
- 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 +3 -2
- package/dist/router/tabs.js +4 -1
- package/dist/store.d.ts +4 -2
- package/dist/store.js +4 -0
- package/dist/testing.d.ts +79 -0
- package/dist/testing.js +251 -0
- package/ios/HBDGlobalStyle.h +29 -0
- package/ios/{GlobalStyle.mm → HBDGlobalStyle.mm} +43 -29
- package/ios/HybridNavigation.h +5 -1
- package/ios/Navigator/HBDDrawerNavigator.mm +24 -8
- package/ios/Navigator/HBDNavigatorRegistry.mm +1 -0
- package/ios/Navigator/HBDScreenNavigator.mm +278 -58
- package/ios/Navigator/HBDStackNavigator.mm +152 -61
- package/ios/Navigator/HBDTabNavigator.mm +60 -14
- package/ios/React/HBDNativeNavigation.mm +162 -123
- package/ios/React/HBDNavigator.h +37 -5
- package/ios/React/HBDOrientationCoordinator.h +29 -0
- package/ios/React/HBDOrientationCoordinator.mm +309 -0
- package/ios/React/HBDReactBridgeManager.h +46 -20
- package/ios/React/HBDReactBridgeManager.mm +496 -108
- 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 +126 -5
- package/ios/ViewController/HBDNavigationController.mm +31 -4
- package/ios/ViewController/HBDReactViewController.h +6 -0
- package/ios/ViewController/HBDReactViewController.mm +220 -106
- package/ios/ViewController/HBDTabBarController.h +15 -0
- package/ios/ViewController/HBDTabBarController.mm +227 -45
- package/ios/ViewController/HBDTabBarRenderer.h +28 -0
- package/ios/ViewController/HBDViewController.h +11 -3
- package/ios/ViewController/HBDViewController.mm +209 -159
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +3 -3
- package/ios/ViewController/UIViewController+HBD.h +18 -10
- package/ios/ViewController/UIViewController+HBD.mm +90 -65
- package/package.json +3 -1
- package/src/DeepLink.ts +41 -14
- package/src/NativeEvent.ts +18 -11
- package/src/NativeNavigation.ts +29 -31
- package/src/Navigation.ts +377 -120
- package/src/NavigationComponentWrap.tsx +18 -9
- package/src/Navigator.ts +219 -152
- package/src/Options.ts +12 -3
- package/src/Route.ts +228 -17
- package/src/defineRoutes.ts +46 -0
- package/src/handler/DispatchCommandHandler.ts +154 -21
- package/src/handler/LayoutCommandHandler.ts +40 -17
- package/src/handler/LeaveGuardHandler.ts +436 -0
- package/src/handler/LifecycleEventHandler.ts +219 -0
- package/src/handler/PresentationCoordinator.ts +560 -0
- package/src/handler/ResultEventHandler.ts +126 -19
- package/src/handler/TabEventHandler.ts +31 -0
- package/src/hooks.ts +75 -7
- package/src/index.ts +37 -2
- package/src/reveal.ts +565 -0
- package/src/routeConfigRegistry.ts +26 -0
- package/src/routeGraph.ts +87 -0
- package/src/router/drawer.ts +8 -5
- package/src/router/index.ts +139 -63
- package/src/router/screen.ts +3 -3
- package/src/router/stack.ts +80 -29
- package/src/router/tabs.ts +16 -7
- package/src/store.ts +6 -1
- package/src/testing.ts +395 -0
- package/testing.d.ts +1 -0
- package/testing.js +3 -0
- 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,11 +1,15 @@
|
|
|
1
1
|
#import "HBDStackNavigator.h"
|
|
2
2
|
|
|
3
|
-
#import "
|
|
3
|
+
#import "HBDGlobalStyle.h"
|
|
4
4
|
#import "HBDNavigationController.h"
|
|
5
|
+
#import "HBDReactBridgeManager.h"
|
|
6
|
+
#import "HBDReactViewController.h"
|
|
5
7
|
#import "UINavigationController+HBD.h"
|
|
6
8
|
|
|
7
9
|
#import <React/RCTLog.h>
|
|
8
10
|
|
|
11
|
+
static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
12
|
+
|
|
9
13
|
@implementation HBDStackNavigator
|
|
10
14
|
|
|
11
15
|
- (NSString *)name {
|
|
@@ -23,7 +27,13 @@
|
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
NSArray *children = model[@"children"];
|
|
30
|
+
if (![children isKindOfClass:[NSArray class]] || children.count == 0) {
|
|
31
|
+
return nil;
|
|
32
|
+
}
|
|
26
33
|
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:children.firstObject];
|
|
34
|
+
if (!vc) {
|
|
35
|
+
return nil;
|
|
36
|
+
}
|
|
27
37
|
return [[HBDNavigationController alloc] initWithRootViewController:vc];
|
|
28
38
|
}
|
|
29
39
|
|
|
@@ -32,18 +42,20 @@
|
|
|
32
42
|
return nil;
|
|
33
43
|
}
|
|
34
44
|
|
|
35
|
-
HBDNavigationController *nav = (HBDNavigationController *)
|
|
45
|
+
HBDNavigationController *nav = (HBDNavigationController *)vc;
|
|
36
46
|
|
|
37
47
|
NSMutableArray *children = [[NSMutableArray alloc] init];
|
|
38
48
|
for (NSUInteger i = 0; i < nav.childViewControllers.count; i++) {
|
|
39
49
|
UIViewController *child = nav.childViewControllers[i];
|
|
40
50
|
NSDictionary *graph = [[HBDReactBridgeManager get] routeGraphWithViewController:child];
|
|
41
|
-
|
|
51
|
+
if (graph) {
|
|
52
|
+
[children addObject:graph];
|
|
53
|
+
}
|
|
42
54
|
}
|
|
43
55
|
|
|
44
56
|
return @{
|
|
45
57
|
@"layout": @"stack",
|
|
46
|
-
@"sceneId": nav.
|
|
58
|
+
@"sceneId": nav.hbd_sceneId,
|
|
47
59
|
@"children": children,
|
|
48
60
|
@"mode": [nav hbd_mode],
|
|
49
61
|
};
|
|
@@ -57,102 +69,144 @@
|
|
|
57
69
|
return [[HBDReactBridgeManager get] primaryViewControllerWithViewController:nav.topViewController];
|
|
58
70
|
}
|
|
59
71
|
|
|
60
|
-
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras
|
|
72
|
+
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
61
73
|
UINavigationController *nav = [self navigationControllerForViewController:vc];
|
|
62
74
|
if (!nav) {
|
|
63
75
|
RCTLogInfo(@"[Navigation] 找不到对应的 UINavigationController from:%@", extras[@"from"]);
|
|
64
|
-
|
|
76
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Target scene is not inside a navigation stack."));
|
|
65
77
|
return;
|
|
66
78
|
}
|
|
67
79
|
|
|
68
80
|
if (nav.transitionCoordinator) {
|
|
69
81
|
RCTLogInfo(@"[Navigation] 等待上个 action 执行完成 from:%@ %@ to:%@", extras[@"from"], action, extras[@"to"]);
|
|
82
|
+
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
83
|
+
NSUInteger commandId = manager.activeCommandId;
|
|
70
84
|
[nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
71
85
|
// empty
|
|
72
86
|
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
73
|
-
// 确保最后执行
|
|
74
87
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
75
|
-
|
|
88
|
+
if (commandId != 0 && manager.activeCommandId != commandId) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
[self handleNavigationWithViewController:vc action:action extras:extras completion:completion];
|
|
76
92
|
});
|
|
77
93
|
}];
|
|
78
94
|
return;
|
|
79
95
|
}
|
|
80
96
|
|
|
81
97
|
if ([action isEqualToString:@"push"]) {
|
|
82
|
-
[self handlePushWithNavigationController:nav extras:extras
|
|
98
|
+
[self handlePushWithNavigationController:nav extras:extras completion:completion];
|
|
83
99
|
return;
|
|
84
100
|
}
|
|
85
101
|
|
|
86
102
|
if ([action isEqualToString:@"pop"]) {
|
|
87
|
-
[self handlePopWithNavigationController:nav viewController:vc
|
|
103
|
+
[self handlePopWithNavigationController:nav viewController:vc completion:completion];
|
|
88
104
|
return;
|
|
89
105
|
}
|
|
90
106
|
|
|
91
107
|
if ([action isEqualToString:@"popTo"]) {
|
|
92
|
-
[self handlePopToWithNavigationController:nav extras:extras
|
|
108
|
+
[self handlePopToWithNavigationController:nav extras:extras completion:completion];
|
|
93
109
|
return;
|
|
94
110
|
}
|
|
95
111
|
|
|
96
112
|
if ([action isEqualToString:@"popToRoot"]) {
|
|
97
|
-
[self handlePopToRootWithNavigationController:nav extras:extras
|
|
113
|
+
[self handlePopToRootWithNavigationController:nav extras:extras completion:completion];
|
|
98
114
|
return;
|
|
99
115
|
}
|
|
100
116
|
|
|
101
117
|
if ([action isEqualToString:@"redirectTo"]) {
|
|
102
|
-
[self handleRedirectToWithNavigationController:nav target:vc extras:extras
|
|
118
|
+
[self handleRedirectToWithNavigationController:nav target:vc extras:extras completion:completion];
|
|
103
119
|
return;
|
|
104
120
|
}
|
|
105
121
|
|
|
106
122
|
if ([action isEqualToString:@"pushLayout"]) {
|
|
107
|
-
[self handlePushLayoutWithNavigationController:nav extras:extras
|
|
123
|
+
[self handlePushLayoutWithNavigationController:nav extras:extras completion:completion];
|
|
108
124
|
return;
|
|
109
125
|
}
|
|
126
|
+
|
|
127
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Unsupported stack action: %@", action]));
|
|
110
128
|
}
|
|
111
129
|
|
|
112
|
-
- (void)handlePushWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras
|
|
130
|
+
- (void)handlePushWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
113
131
|
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
114
132
|
if (!vc) {
|
|
115
133
|
RCTLogInfo(@"[Navigation] 无法创建对应的页面 %@", extras[@"moduleName"]);
|
|
116
|
-
|
|
134
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create target screen for push."));
|
|
117
135
|
return;
|
|
118
136
|
}
|
|
137
|
+
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
138
|
+
if (requestCode != 0) {
|
|
139
|
+
[vc setHbd_requestCode:requestCode];
|
|
140
|
+
}
|
|
119
141
|
|
|
120
142
|
BOOL animated = YES;
|
|
121
143
|
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
122
|
-
HBDViewController *
|
|
123
|
-
|
|
144
|
+
HBDViewController *hbdvc = (HBDViewController *)vc;
|
|
145
|
+
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
124
146
|
}
|
|
125
147
|
|
|
148
|
+
NSString *sceneId = vc.hbd_sceneId;
|
|
126
149
|
if (animated) {
|
|
150
|
+
BOOL canPrewarm = [HBDReactBridgeManager get].globalStyle.prewarmPush &&
|
|
151
|
+
[vc isKindOfClass:[HBDReactViewController class]] &&
|
|
152
|
+
nav.tabBarController == nil &&
|
|
153
|
+
nav.presentingViewController == nil &&
|
|
154
|
+
nav.view.window != nil &&
|
|
155
|
+
CGSizeEqualToSize(nav.view.bounds.size, nav.view.window.bounds.size);
|
|
156
|
+
if (canPrewarm) {
|
|
157
|
+
HBDReactViewController *reactVC = (HBDReactViewController *)vc;
|
|
158
|
+
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
159
|
+
NSUInteger commandId = manager.activeCommandId;
|
|
160
|
+
__weak HBDStackNavigator *weakSelf = self;
|
|
161
|
+
__weak UINavigationController *weakNav = nav;
|
|
162
|
+
BOOL prewarming = [reactVC prepareForAnimatedPushWithBounds:nav.view.bounds
|
|
163
|
+
timeout:HBDPushPrewarmTimeoutSeconds
|
|
164
|
+
completion:^{
|
|
165
|
+
HBDStackNavigator *strongSelf = weakSelf;
|
|
166
|
+
UINavigationController *strongNav = weakNav;
|
|
167
|
+
if (commandId != 0 && manager.activeCommandId != commandId) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (!strongSelf || !strongNav || !strongNav.view.window || vc.navigationController != nil) {
|
|
171
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeHostUnavailable, @"Navigation stack is unavailable after push prewarm."));
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
[strongNav pushViewController:vc animated:YES];
|
|
175
|
+
[strongSelf animateAlongsideTransition:strongNav result:HBDDispatchResultOkWithSceneId(sceneId) completion:completion];
|
|
176
|
+
}];
|
|
177
|
+
if (prewarming) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
127
181
|
[nav pushViewController:vc animated:YES];
|
|
128
|
-
[self animateAlongsideTransition:nav
|
|
182
|
+
[self animateAlongsideTransition:nav result:HBDDispatchResultOkWithSceneId(sceneId) completion:completion];
|
|
129
183
|
} else {
|
|
130
184
|
[nav pushViewController:vc animated:NO];
|
|
131
|
-
|
|
185
|
+
completion(HBDDispatchResultOkWithSceneId(sceneId));
|
|
132
186
|
}
|
|
133
187
|
}
|
|
134
188
|
|
|
135
|
-
- (void)handlePopWithNavigationController:(UINavigationController *)nav viewController:(UIViewController *)vc
|
|
189
|
+
- (void)handlePopWithNavigationController:(UINavigationController *)nav viewController:(UIViewController *)vc completion:(HBDDispatchCompletion)completion {
|
|
136
190
|
BOOL animated = YES;
|
|
137
191
|
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
138
|
-
HBDViewController *
|
|
139
|
-
|
|
192
|
+
HBDViewController *hbdvc = (HBDViewController *)vc;
|
|
193
|
+
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
140
194
|
}
|
|
141
195
|
|
|
142
196
|
if (animated) {
|
|
143
197
|
[nav popViewControllerAnimated:YES];
|
|
144
|
-
[self animateAlongsideTransition:nav
|
|
198
|
+
[self animateAlongsideTransition:nav completion:completion];
|
|
145
199
|
} else {
|
|
146
200
|
[nav popViewControllerAnimated:NO];
|
|
147
|
-
|
|
201
|
+
completion(HBDDispatchResultOk());
|
|
148
202
|
}
|
|
149
203
|
}
|
|
150
204
|
|
|
151
|
-
- (void)handlePopToWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras
|
|
205
|
+
- (void)handlePopToWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
152
206
|
UIViewController *vc = [self findViewControllerWithNavigationController:nav extras:extras];
|
|
153
207
|
if (!vc) {
|
|
154
208
|
RCTLogInfo(@"[Navigation] 找不到要 popTo 的页面 %@", extras[@"moduleName"]);
|
|
155
|
-
|
|
209
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeSceneNotFound, [NSString stringWithFormat:@"Can't find target scene to popTo: %@", extras[@"moduleName"]]));
|
|
156
210
|
return;
|
|
157
211
|
}
|
|
158
212
|
|
|
@@ -161,17 +215,16 @@
|
|
|
161
215
|
BOOL animated = YES;
|
|
162
216
|
if ([from_vc isKindOfClass:[HBDViewController class]]) {
|
|
163
217
|
HBDViewController *hbdvc = (HBDViewController *)from_vc;
|
|
164
|
-
animated = hbdvc.animatedTransition || hbdvc.
|
|
218
|
+
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
165
219
|
}
|
|
166
220
|
|
|
167
221
|
if (animated) {
|
|
168
222
|
[nav popToViewController:vc animated:YES];
|
|
169
|
-
[self animateAlongsideTransition:nav
|
|
170
|
-
}else {
|
|
223
|
+
[self animateAlongsideTransition:nav completion:completion];
|
|
224
|
+
} else {
|
|
171
225
|
[nav popToViewController:vc animated:NO];
|
|
172
|
-
|
|
226
|
+
completion(HBDDispatchResultOk());
|
|
173
227
|
}
|
|
174
|
-
|
|
175
228
|
}
|
|
176
229
|
|
|
177
230
|
- (UIViewController *)findFromViewControllerWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras {
|
|
@@ -181,8 +234,9 @@
|
|
|
181
234
|
|
|
182
235
|
for (NSUInteger i = children.count; i > 0; i--) {
|
|
183
236
|
NSUInteger index = i - 1;
|
|
184
|
-
|
|
185
|
-
|
|
237
|
+
UIViewController *vc = children[index];
|
|
238
|
+
NSString *vcModuleName = [vc isKindOfClass:[HBDViewController class]] ? ((HBDViewController *)vc).moduleName : nil;
|
|
239
|
+
if ([moduleName isEqualToString:vcModuleName] || [moduleName isEqualToString:vc.hbd_sceneId]) {
|
|
186
240
|
if (inclusive && index > 0) {
|
|
187
241
|
return children[index - 1];
|
|
188
242
|
}
|
|
@@ -200,8 +254,9 @@
|
|
|
200
254
|
|
|
201
255
|
for (NSUInteger i = children.count; i > 0; i--) {
|
|
202
256
|
NSUInteger index = i - 1;
|
|
203
|
-
|
|
204
|
-
|
|
257
|
+
UIViewController *vc = children[index];
|
|
258
|
+
NSString *vcModuleName = [vc isKindOfClass:[HBDViewController class]] ? ((HBDViewController *)vc).moduleName : nil;
|
|
259
|
+
if ([moduleName isEqualToString:vcModuleName] || [moduleName isEqualToString:vc.hbd_sceneId]) {
|
|
205
260
|
if (inclusive && index > 0) {
|
|
206
261
|
return children[index - 1];
|
|
207
262
|
}
|
|
@@ -212,73 +267,84 @@
|
|
|
212
267
|
return nil;
|
|
213
268
|
}
|
|
214
269
|
|
|
215
|
-
- (void)handlePopToRootWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras
|
|
216
|
-
|
|
270
|
+
- (void)handlePopToRootWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
217
271
|
UIViewController *from_vc = [self findFromViewControllerWithNavigationController:nav extras:extras];
|
|
218
272
|
|
|
219
273
|
BOOL animated = YES;
|
|
220
|
-
|
|
221
274
|
if ([from_vc isKindOfClass:[HBDViewController class]]) {
|
|
222
275
|
HBDViewController *hbdvc = (HBDViewController *)from_vc;
|
|
223
|
-
animated = hbdvc.animatedTransition || hbdvc.
|
|
276
|
+
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
224
277
|
}
|
|
225
278
|
|
|
226
279
|
if (animated) {
|
|
227
280
|
[nav popToRootViewControllerAnimated:YES];
|
|
228
|
-
[self animateAlongsideTransition:nav
|
|
229
|
-
}else {
|
|
281
|
+
[self animateAlongsideTransition:nav completion:completion];
|
|
282
|
+
} else {
|
|
230
283
|
[nav popToRootViewControllerAnimated:NO];
|
|
231
|
-
|
|
284
|
+
completion(HBDDispatchResultOk());
|
|
232
285
|
}
|
|
233
286
|
}
|
|
234
287
|
|
|
235
|
-
- (void)handleRedirectToWithNavigationController:(UINavigationController *)nav target:(UIViewController *)target extras:(NSDictionary *)extras
|
|
288
|
+
- (void)handleRedirectToWithNavigationController:(UINavigationController *)nav target:(UIViewController *)target extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
236
289
|
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
237
290
|
if (!vc) {
|
|
238
291
|
RCTLogInfo(@"[Navigation] 无法创建对应的页面 %@", extras[@"moduleName"]);
|
|
239
|
-
|
|
292
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create target screen for redirectTo."));
|
|
240
293
|
return;
|
|
241
294
|
}
|
|
242
|
-
|
|
295
|
+
if (vc.hbd_requestCode == 0 && target.hbd_requestCode != 0) {
|
|
296
|
+
[vc setHbd_requestCode:target.hbd_requestCode];
|
|
297
|
+
}
|
|
243
298
|
|
|
299
|
+
BOOL animated = YES;
|
|
244
300
|
if ([vc isKindOfClass:[HBDViewController class]]) {
|
|
245
301
|
HBDViewController *hbdvc = (HBDViewController *)vc;
|
|
246
|
-
animated = hbdvc.animatedTransition || hbdvc.
|
|
302
|
+
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
247
303
|
}
|
|
248
304
|
|
|
305
|
+
NSString *sceneId = vc.hbd_sceneId;
|
|
249
306
|
if (animated) {
|
|
250
|
-
[nav
|
|
251
|
-
[self animateAlongsideTransition:nav
|
|
252
|
-
}else {
|
|
253
|
-
[nav
|
|
254
|
-
|
|
307
|
+
[nav hbd_redirectToViewController:vc target:target animated:YES];
|
|
308
|
+
[self animateAlongsideTransition:nav result:HBDDispatchResultOkWithSceneId(sceneId) completion:completion];
|
|
309
|
+
} else {
|
|
310
|
+
[nav hbd_redirectToViewController:vc target:target animated:NO];
|
|
311
|
+
completion(HBDDispatchResultOkWithSceneId(sceneId));
|
|
255
312
|
}
|
|
256
|
-
|
|
257
313
|
}
|
|
258
314
|
|
|
259
|
-
- (void)handlePushLayoutWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras
|
|
315
|
+
- (void)handlePushLayoutWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
260
316
|
NSDictionary *layout = extras[@"layout"];
|
|
261
317
|
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
|
|
262
318
|
if (!vc) {
|
|
263
319
|
RCTLogInfo(@"[Navigation] 无法创建对应的 vc");
|
|
264
|
-
|
|
320
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create layout for pushLayout."));
|
|
265
321
|
return;
|
|
266
322
|
}
|
|
323
|
+
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
324
|
+
if (requestCode != 0) {
|
|
325
|
+
[vc setHbd_requestCode:requestCode];
|
|
326
|
+
}
|
|
327
|
+
HBDViewController *primary = [[HBDReactBridgeManager get] primaryViewControllerWithViewController:vc];
|
|
328
|
+
NSString *sceneId = primary.hbd_sceneId.length > 0 ? primary.hbd_sceneId : vc.hbd_sceneId;
|
|
267
329
|
|
|
268
330
|
[nav pushViewController:vc animated:YES];
|
|
269
|
-
[self animateAlongsideTransition:nav
|
|
331
|
+
[self animateAlongsideTransition:nav result:HBDDispatchResultOkWithSceneId(sceneId) completion:completion];
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
- (void)animateAlongsideTransition:(UINavigationController *)nav completion:(HBDDispatchCompletion)completion {
|
|
335
|
+
[self animateAlongsideTransition:nav result:HBDDispatchResultOk() completion:completion];
|
|
270
336
|
}
|
|
271
337
|
|
|
272
|
-
- (void)animateAlongsideTransition:(UINavigationController *)nav
|
|
338
|
+
- (void)animateAlongsideTransition:(UINavigationController *)nav result:(NSDictionary *)result completion:(HBDDispatchCompletion)completion {
|
|
273
339
|
if (!nav.transitionCoordinator) {
|
|
274
|
-
|
|
340
|
+
completion(result);
|
|
275
341
|
return;
|
|
276
342
|
}
|
|
277
343
|
|
|
278
344
|
[nav.transitionCoordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
279
345
|
// empty
|
|
280
346
|
} completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
281
|
-
|
|
347
|
+
completion(result);
|
|
282
348
|
}];
|
|
283
349
|
}
|
|
284
350
|
|
|
@@ -294,11 +360,36 @@
|
|
|
294
360
|
return (UINavigationController *)vc;
|
|
295
361
|
}
|
|
296
362
|
|
|
297
|
-
|
|
363
|
+
if (vc.navigationController) {
|
|
364
|
+
return vc.navigationController;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return [self navigationControllerFromDrawerIfExist:vc];
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
- (nullable UINavigationController *)navigationControllerFromDrawerIfExist:(UIViewController *)vc {
|
|
371
|
+
HBDDrawerController *drawer = [vc hbd_drawerController];
|
|
372
|
+
if (!drawer) {
|
|
373
|
+
return nil;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
UIViewController *content = drawer.contentController;
|
|
377
|
+
if ([content isKindOfClass:[UITabBarController class]]) {
|
|
378
|
+
UIViewController *selected = ((UITabBarController *)content).selectedViewController;
|
|
379
|
+
if ([selected isKindOfClass:[UINavigationController class]]) {
|
|
380
|
+
return (UINavigationController *)selected;
|
|
381
|
+
}
|
|
382
|
+
return selected.navigationController;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if ([content isKindOfClass:[UINavigationController class]]) {
|
|
386
|
+
return (UINavigationController *)content;
|
|
387
|
+
}
|
|
388
|
+
return content.navigationController;
|
|
298
389
|
}
|
|
299
390
|
|
|
300
391
|
- (void)invalidate {
|
|
301
|
-
|
|
392
|
+
//
|
|
302
393
|
}
|
|
303
394
|
|
|
304
395
|
@end
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
#import "HBDTabBarController.h"
|
|
4
4
|
#import "HBDReactBridgeManager.h"
|
|
5
5
|
#import "HBDUtils.h"
|
|
6
|
-
#import "
|
|
6
|
+
#import "HBDGlobalStyle.h"
|
|
7
7
|
|
|
8
|
+
#import <React/RCTLog.h>
|
|
8
9
|
#import <React/RCTUtils.h>
|
|
9
10
|
|
|
10
11
|
@implementation HBDTabNavigator
|
|
@@ -27,11 +28,27 @@
|
|
|
27
28
|
NSMutableArray *viewControllers = [[NSMutableArray alloc] initWithCapacity:4];
|
|
28
29
|
for (NSDictionary *tab in children) {
|
|
29
30
|
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:tab];
|
|
30
|
-
|
|
31
|
+
if (vc) {
|
|
32
|
+
[viewControllers addObject:vc];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (viewControllers.count == 0) {
|
|
36
|
+
return nil;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
NSDictionary *options = model[@"options"];
|
|
34
40
|
HBDTabBarController *tabBarController = [[HBDTabBarController alloc] init];
|
|
41
|
+
if ([options isKindOfClass:[NSDictionary class]]) {
|
|
42
|
+
NSString *rendererName = options[@"renderer"];
|
|
43
|
+
if ([rendererName isKindOfClass:[NSString class]] && rendererName.length > 0) {
|
|
44
|
+
id<HBDTabBarRenderer> renderer = [[HBDReactBridgeManager get] tabBarRendererWithName:rendererName];
|
|
45
|
+
if (renderer) {
|
|
46
|
+
tabBarController.tabBarRenderer = renderer;
|
|
47
|
+
} else {
|
|
48
|
+
RCTLogWarn(@"[Navigation] Unknown tab bar renderer '%@', falling back to default TabBar.", rendererName);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
35
52
|
[tabBarController setViewControllers:viewControllers];
|
|
36
53
|
|
|
37
54
|
if (options) {
|
|
@@ -54,13 +71,21 @@
|
|
|
54
71
|
for (NSUInteger i = 0; i < tabBarController.childViewControllers.count; i++) {
|
|
55
72
|
UIViewController *child = tabBarController.childViewControllers[i];
|
|
56
73
|
NSDictionary *graph = [[HBDReactBridgeManager get] routeGraphWithViewController:child];
|
|
57
|
-
|
|
74
|
+
if (graph) {
|
|
75
|
+
[children addObject:graph];
|
|
76
|
+
}
|
|
58
77
|
}
|
|
59
78
|
|
|
79
|
+
NSMutableArray *tabKeys = [NSMutableArray arrayWithCapacity:children.count];
|
|
80
|
+
for (NSString *key in [tabBarController tabKeys]) {
|
|
81
|
+
[tabKeys addObject:key.length > 0 ? key : [NSNull null]];
|
|
82
|
+
}
|
|
83
|
+
|
|
60
84
|
return @{
|
|
61
85
|
@"layout": self.name,
|
|
62
|
-
@"sceneId": tabBarController.
|
|
86
|
+
@"sceneId": tabBarController.hbd_sceneId,
|
|
63
87
|
@"children": children,
|
|
88
|
+
@"tabKeys": tabKeys,
|
|
64
89
|
@"mode": [tabBarController hbd_mode],
|
|
65
90
|
@"selectedIndex": @(tabBarController.selectedIndex)
|
|
66
91
|
};
|
|
@@ -82,13 +107,32 @@
|
|
|
82
107
|
}
|
|
83
108
|
}
|
|
84
109
|
|
|
85
|
-
- (void)handleSwitchTabWithTabBarController:(UITabBarController *)tabBarController extras:(NSDictionary *)extras
|
|
110
|
+
- (void)handleSwitchTabWithTabBarController:(UITabBarController *)tabBarController extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
86
111
|
BOOL popToRoot = [extras[@"popToRoot"] boolValue];
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
112
|
+
NSInteger toIndex = NSNotFound;
|
|
113
|
+
NSString *tabKey = [extras[@"tabKey"] isKindOfClass:[NSString class]] ? extras[@"tabKey"] : nil;
|
|
114
|
+
if (tabKey.length > 0 && [tabBarController isKindOfClass:[HBDTabBarController class]]) {
|
|
115
|
+
toIndex = [(HBDTabBarController *)tabBarController indexForTabKey:tabKey];
|
|
116
|
+
if (toIndex == NSNotFound) {
|
|
117
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeSceneNotFound, [NSString stringWithFormat:@"Can't find tab for key: %@", tabKey]));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
NSNumber *toNumber = extras[@"to"];
|
|
122
|
+
if (![toNumber isKindOfClass:[NSNumber class]]) {
|
|
123
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Tab index or tabKey is required for switchTab."));
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
toIndex = [toNumber integerValue];
|
|
127
|
+
}
|
|
128
|
+
if (toIndex < 0 || (NSUInteger)toIndex >= tabBarController.viewControllers.count) {
|
|
129
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Tab index out of bounds: %ld", (long)toIndex]));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
NSUInteger to = (NSUInteger)toIndex;
|
|
133
|
+
|
|
134
|
+
if (tabBarController.selectedIndex == to) {
|
|
135
|
+
completion(HBDDispatchResultOk());
|
|
92
136
|
return;
|
|
93
137
|
}
|
|
94
138
|
|
|
@@ -108,21 +152,23 @@
|
|
|
108
152
|
|
|
109
153
|
tabBarController.selectedIndex = to;
|
|
110
154
|
|
|
111
|
-
|
|
155
|
+
completion(HBDDispatchResultOk());
|
|
112
156
|
}
|
|
113
157
|
|
|
114
|
-
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras
|
|
158
|
+
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
115
159
|
UITabBarController *tabBarController = [self tabBarControllerForViewController:vc];
|
|
116
160
|
|
|
117
161
|
if (!tabBarController) {
|
|
118
|
-
|
|
162
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Target scene is not inside a tab bar."));
|
|
119
163
|
return;
|
|
120
164
|
}
|
|
121
165
|
|
|
122
166
|
if ([action isEqualToString:@"switchTab"]) {
|
|
123
|
-
[self handleSwitchTabWithTabBarController:tabBarController extras:extras
|
|
167
|
+
[self handleSwitchTabWithTabBarController:tabBarController extras:extras completion:completion];
|
|
124
168
|
return;
|
|
125
169
|
}
|
|
170
|
+
|
|
171
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Unsupported tab action: %@", action]));
|
|
126
172
|
}
|
|
127
173
|
|
|
128
174
|
- (void)invalidate {
|