hybrid-navigation 5.4.0 → 5.5.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 +1 -0
- package/android/proguard-rules.pro +5 -0
- package/android/src/main/java/com/navigation/androidx/AppUtils.java +8 -1
- package/android/src/main/java/com/navigation/androidx/AwesomeActivity.java +115 -36
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +153 -100
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +1 -1
- package/android/src/main/java/com/navigation/androidx/DrawableUtils.java +5 -1
- package/android/src/main/java/com/navigation/androidx/DrawerFragment.java +95 -39
- package/android/src/main/java/com/navigation/androidx/FragmentHelper.java +195 -29
- package/android/src/main/java/com/navigation/androidx/HybridDrawerLayout.java +225 -27
- package/android/src/main/java/com/navigation/androidx/LifecycleDelegate.java +33 -9
- package/android/src/main/java/com/navigation/androidx/PresentationDelegate.java +5 -107
- package/android/src/main/java/com/navigation/androidx/StackDelegate.java +37 -10
- package/android/src/main/java/com/navigation/androidx/StackFragment.java +82 -19
- package/android/src/main/java/com/navigation/androidx/Style.java +8 -4
- package/android/src/main/java/com/navigation/androidx/SystemUI.java +17 -5
- package/android/src/main/java/com/navigation/androidx/TabBar.java +69 -29
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +48 -11
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +1 -2
- package/android/src/main/java/com/navigation/androidx/TabView.java +20 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/Constants.java +1 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/Garden.java +19 -15
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +10 -48
- package/android/src/main/java/com/reactnative/hybridnavigation/HBDRootView.java +22 -23
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +54 -22
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeEvent.java +4 -2
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +35 -64
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigationCommandQueue.java +185 -121
- package/android/src/main/java/com/reactnative/hybridnavigation/Navigator.java +21 -5
- package/android/src/main/java/com/reactnative/hybridnavigation/NavigatorRegistry.java +27 -30
- package/android/src/main/java/com/reactnative/hybridnavigation/OrientationCoordinator.java +41 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/Parameters.java +55 -154
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivity.java +30 -1
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactAppCompatActivityDelegate.java +12 -37
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +31 -190
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +115 -71
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactStackFragment.java +27 -16
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactSurfaceCleanup.java +50 -8
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +34 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarProvider.java +39 -10
- package/android/src/main/java/com/reactnative/hybridnavigation/RemovalPlan.java +76 -0
- package/android/src/main/java/com/reactnative/hybridnavigation/SceneLifecycleStateMachine.java +72 -6
- package/android/src/main/java/com/reactnative/hybridnavigation/Utils.java +19 -3
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/DrawerNavigator.java +11 -5
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +217 -99
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/StackNavigator.java +122 -59
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +87 -24
- package/dist/DeepLink.d.ts +3 -1
- package/dist/DeepLink.js +39 -19
- package/dist/NativeNavigation.d.ts +8 -5
- package/dist/Navigation.d.ts +9 -24
- package/dist/Navigation.js +32 -97
- package/dist/NavigationComponentWrap.d.ts +1 -2
- package/dist/NavigationComponentWrap.js +0 -15
- package/dist/Navigator.d.ts +7 -5
- package/dist/Navigator.js +38 -33
- package/dist/Options.d.ts +1 -7
- package/dist/Options.js +1 -2
- package/dist/Route.d.ts +24 -12
- package/dist/handler/DispatchCommandHandler.d.ts +4 -5
- package/dist/handler/DispatchCommandHandler.js +37 -16
- package/dist/handler/LayoutCommandHandler.js +18 -3
- package/dist/handler/LeaveGuardHandler.d.ts +12 -8
- package/dist/handler/LeaveGuardHandler.js +174 -281
- package/dist/handler/LifecycleEventHandler.d.ts +7 -4
- package/dist/handler/LifecycleEventHandler.js +119 -32
- package/dist/handler/ResultEventHandler.d.ts +2 -2
- package/dist/handler/ResultEventHandler.js +72 -36
- package/dist/handler/SceneExitHandler.d.ts +6 -0
- package/dist/handler/SceneExitHandler.js +48 -8
- package/dist/hooks.d.ts +1 -0
- package/dist/hooks.js +39 -23
- package/dist/index.d.ts +9 -8
- package/dist/index.js +5 -8
- package/dist/routeGraph.d.ts +5 -0
- package/dist/routeGraph.js +47 -0
- package/dist/router/drawer.d.ts +2 -2
- package/dist/router/drawer.js +19 -9
- package/dist/router/helpers.d.ts +17 -0
- package/dist/router/helpers.js +90 -0
- package/dist/router/index.d.ts +2 -2
- package/dist/router/index.js +169 -97
- package/dist/router/screen.d.ts +2 -2
- package/dist/router/screen.js +16 -7
- package/dist/router/stack.d.ts +2 -2
- package/dist/router/stack.js +24 -49
- package/dist/router/tabs.js +5 -1
- package/dist/store.d.ts +2 -0
- package/dist/store.js +4 -0
- package/ios/HBDGlobalStyle.h +0 -1
- package/ios/HBDGlobalStyle.mm +27 -39
- package/ios/HBDUtils.h +0 -2
- package/ios/HBDUtils.mm +81 -41
- package/ios/Navigator/HBDDrawerNavigator.mm +31 -26
- package/ios/Navigator/HBDNavigatorRegistry.mm +23 -26
- package/ios/Navigator/HBDScreenNavigator.mm +240 -137
- package/ios/Navigator/HBDStackNavigator.mm +147 -97
- package/ios/Navigator/HBDTabNavigator.mm +99 -46
- package/ios/React/HBDNativeEvent.mm +38 -5
- package/ios/React/HBDNativeNavigation.mm +49 -51
- package/ios/React/HBDNavigationCommandQueue.h +55 -0
- package/ios/React/HBDNavigationCommandQueue.mm +341 -0
- package/ios/React/HBDNavigator.h +20 -0
- package/ios/React/HBDOrientationCoordinator.mm +26 -3
- package/ios/React/HBDReactBridgeManager.h +18 -6
- package/ios/React/HBDReactBridgeManager.mm +536 -315
- package/ios/React/HBDSceneLifecycleStateMachine.h +2 -0
- package/ios/React/HBDSceneLifecycleStateMachine.mm +18 -0
- package/ios/View/HBDRootView.h +1 -0
- package/ios/View/HBDRootView.mm +112 -4
- package/ios/View/UIImage+WithBadge.mm +9 -7
- package/ios/ViewController/HBDDrawerController.h +10 -0
- package/ios/ViewController/HBDDrawerController.mm +103 -71
- package/ios/ViewController/HBDNavigationController.mm +166 -58
- package/ios/ViewController/HBDReactViewController.h +0 -4
- package/ios/ViewController/HBDReactViewController.mm +13 -110
- package/ios/ViewController/HBDTabBarController.mm +67 -33
- package/ios/ViewController/HBDViewController.h +6 -0
- package/ios/ViewController/HBDViewController.mm +94 -37
- package/ios/ViewController/UINavigationController+HBD.h +2 -2
- package/ios/ViewController/UINavigationController+HBD.mm +13 -13
- package/ios/ViewController/UIViewController+HBD.h +23 -1
- package/ios/ViewController/UIViewController+HBD.mm +298 -40
- package/package.json +1 -1
- package/src/DeepLink.ts +39 -19
- package/src/NativeNavigation.ts +17 -5
- package/src/Navigation.ts +49 -170
- package/src/NavigationComponentWrap.tsx +1 -16
- package/src/Navigator.ts +50 -52
- package/src/Options.ts +4 -10
- package/src/Route.ts +37 -19
- package/src/handler/DispatchCommandHandler.ts +42 -20
- package/src/handler/LayoutCommandHandler.ts +15 -3
- package/src/handler/LeaveGuardHandler.ts +224 -329
- package/src/handler/LifecycleEventHandler.ts +131 -37
- package/src/handler/ResultEventHandler.ts +71 -37
- package/src/handler/SceneExitHandler.ts +60 -9
- package/src/hooks.ts +54 -26
- package/src/index.ts +77 -8
- package/src/routeGraph.ts +50 -0
- package/src/router/drawer.ts +21 -10
- package/src/router/helpers.ts +113 -0
- package/src/router/index.ts +187 -112
- package/src/router/screen.ts +35 -8
- package/src/router/stack.ts +40 -53
- package/src/router/tabs.ts +5 -1
- package/src/store.ts +5 -0
- package/dist/sceneCoverage.d.ts +0 -2
- package/dist/sceneCoverage.js +0 -25
- package/src/sceneCoverage.ts +0 -30
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
#import "HBDStackNavigator.h"
|
|
2
2
|
|
|
3
|
-
#import "HBDGlobalStyle.h"
|
|
4
3
|
#import "HBDNavigationController.h"
|
|
5
4
|
#import "HBDReactBridgeManager.h"
|
|
6
|
-
#import "HBDReactViewController.h"
|
|
7
5
|
#import "UINavigationController+HBD.h"
|
|
8
6
|
|
|
9
7
|
#import <React/RCTLog.h>
|
|
10
8
|
|
|
11
|
-
static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
12
|
-
|
|
13
9
|
@implementation HBDStackNavigator
|
|
14
10
|
|
|
15
11
|
- (NSString *)name {
|
|
@@ -17,11 +13,15 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
- (NSArray<NSString *> *)supportActions {
|
|
20
|
-
return @[@"push", @"
|
|
16
|
+
return @[@"push", @"pop", @"popTo", @"popToRoot", @"redirectTo"];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
- (BOOL)handlesViewController:(UIViewController *)vc {
|
|
20
|
+
return [self isMemberOfClass:[HBDStackNavigator class]] && [vc isKindOfClass:[HBDNavigationController class]];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
- (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
|
|
24
|
-
NSDictionary *model = layout[self.name];
|
|
24
|
+
NSDictionary *model = [layout[self.name] isKindOfClass:[NSDictionary class]] ? layout[self.name] : nil;
|
|
25
25
|
if (!model) {
|
|
26
26
|
return nil;
|
|
27
27
|
}
|
|
@@ -30,7 +30,11 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
30
30
|
if (![children isKindOfClass:[NSArray class]] || children.count == 0) {
|
|
31
31
|
return nil;
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
NSDictionary *firstChild = [children.firstObject isKindOfClass:[NSDictionary class]] ? children.firstObject : nil;
|
|
34
|
+
if (!firstChild) {
|
|
35
|
+
return nil;
|
|
36
|
+
}
|
|
37
|
+
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:firstChild];
|
|
34
38
|
if (!vc) {
|
|
35
39
|
return nil;
|
|
36
40
|
}
|
|
@@ -54,7 +58,7 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
return @{
|
|
57
|
-
@"layout":
|
|
61
|
+
@"layout": self.name,
|
|
58
62
|
@"sceneId": nav.hbd_sceneId,
|
|
59
63
|
@"children": children,
|
|
60
64
|
@"mode": [nav hbd_mode],
|
|
@@ -66,7 +70,7 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
66
70
|
return nil;
|
|
67
71
|
}
|
|
68
72
|
UINavigationController *nav = (UINavigationController *)vc;
|
|
69
|
-
return [[HBDReactBridgeManager get]
|
|
73
|
+
return [[HBDReactBridgeManager get] primaryViewControllerInHierarchy:nav.topViewController];
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
@@ -80,22 +84,17 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
80
84
|
if (nav.transitionCoordinator) {
|
|
81
85
|
RCTLogInfo(@"[Navigation] 等待上个 action 执行完成 from:%@ %@ to:%@", extras[@"from"], action, extras[@"to"]);
|
|
82
86
|
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
[self handleNavigationWithViewController:vc action:action extras:extras completion:completion];
|
|
92
|
-
});
|
|
93
|
-
}];
|
|
87
|
+
[manager waitForTransitionOnViewController:nav
|
|
88
|
+
commandId:manager.activeCommandId
|
|
89
|
+
retryCount:0
|
|
90
|
+
action:^{
|
|
91
|
+
[self handleNavigationWithViewController:vc action:action extras:extras completion:completion];
|
|
92
|
+
} onTimeout:nil];
|
|
94
93
|
return;
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
if ([action isEqualToString:@"push"]) {
|
|
98
|
-
[self handlePushWithNavigationController:nav extras:extras completion:completion];
|
|
97
|
+
[self handlePushWithNavigationController:nav caller:vc extras:extras completion:completion];
|
|
99
98
|
return;
|
|
100
99
|
}
|
|
101
100
|
|
|
@@ -119,24 +118,88 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
119
118
|
return;
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
if ([action isEqualToString:@"pushLayout"]) {
|
|
123
|
-
[self handlePushLayoutWithNavigationController:nav extras:extras completion:completion];
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
121
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Unsupported stack action: %@", action]));
|
|
128
122
|
}
|
|
129
123
|
|
|
130
|
-
- (
|
|
124
|
+
- (BOOL)isCallerCoveredInNavigationController:(UINavigationController *)nav caller:(UIViewController *)caller {
|
|
125
|
+
return caller != nil && ([caller hbd_isCoveredByPresentation] || [caller hbd_isCoveredInContainers]);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
- (nullable NSDictionary *)removalPlanWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras {
|
|
129
|
+
UINavigationController *nav = [self navigationControllerForViewController:vc];
|
|
130
|
+
if (!nav) {
|
|
131
|
+
return HBDRemovalPlan(HBDDispatchCodeInvalidAction, @[], nil, nil);
|
|
132
|
+
}
|
|
133
|
+
NSArray<UIViewController *> *children = nav.viewControllers;
|
|
134
|
+
if ([action isEqualToString:@"pop"]) {
|
|
135
|
+
if ([self isCallerCoveredInNavigationController:nav caller:vc]) {
|
|
136
|
+
return HBDRemovalPlan(HBDDispatchCodeCovered, @[], nil, nil);
|
|
137
|
+
}
|
|
138
|
+
if (children.count <= 1) {
|
|
139
|
+
return HBDRemovalPlan(HBDDispatchCodeInvalidAction, @[], nil, nil);
|
|
140
|
+
}
|
|
141
|
+
return HBDRemovalPlan(HBDDispatchCodeOk, [children.lastObject hbd_collectLeafSceneIds], @"pop", nil);
|
|
142
|
+
}
|
|
143
|
+
if ([action isEqualToString:@"popTo"]) {
|
|
144
|
+
UIViewController *target = [self findViewControllerWithNavigationController:nav extras:extras];
|
|
145
|
+
if (!target) {
|
|
146
|
+
return HBDRemovalPlan(HBDDispatchCodeSceneNotFound, @[], nil, nil);
|
|
147
|
+
}
|
|
148
|
+
NSUInteger targetIndex = [children indexOfObject:target];
|
|
149
|
+
if (targetIndex == NSNotFound || targetIndex + 1 >= children.count) {
|
|
150
|
+
return HBDRemovalPlan(@"noop", @[], nil, nil);
|
|
151
|
+
}
|
|
152
|
+
NSMutableArray<NSString *> *sceneIds = [NSMutableArray array];
|
|
153
|
+
for (NSInteger i = (NSInteger)children.count - 1; i > (NSInteger)targetIndex; i--) {
|
|
154
|
+
[sceneIds addObjectsFromArray:[children[(NSUInteger)i] hbd_collectLeafSceneIds]];
|
|
155
|
+
}
|
|
156
|
+
return HBDRemovalPlan(HBDDispatchCodeOk, sceneIds, @"popTo", nil);
|
|
157
|
+
}
|
|
158
|
+
if ([action isEqualToString:@"popToRoot"]) {
|
|
159
|
+
if (children.count <= 1) {
|
|
160
|
+
return HBDRemovalPlan(@"noop", @[], nil, nil);
|
|
161
|
+
}
|
|
162
|
+
NSMutableArray<NSString *> *sceneIds = [NSMutableArray array];
|
|
163
|
+
for (NSInteger i = (NSInteger)children.count - 1; i > 0; i--) {
|
|
164
|
+
[sceneIds addObjectsFromArray:[children[(NSUInteger)i] hbd_collectLeafSceneIds]];
|
|
165
|
+
}
|
|
166
|
+
return HBDRemovalPlan(HBDDispatchCodeOk, sceneIds, @"popToRoot", nil);
|
|
167
|
+
}
|
|
168
|
+
if ([action isEqualToString:@"redirectTo"]) {
|
|
169
|
+
NSUInteger targetIndex = [children indexOfObject:vc];
|
|
170
|
+
if (targetIndex == NSNotFound) {
|
|
171
|
+
return HBDRemovalPlan(@"noop", @[], nil, nil);
|
|
172
|
+
}
|
|
173
|
+
NSMutableArray<NSString *> *sceneIds = [NSMutableArray array];
|
|
174
|
+
for (NSInteger i = (NSInteger)children.count - 1; i >= (NSInteger)targetIndex; i--) {
|
|
175
|
+
[sceneIds addObjectsFromArray:[children[(NSUInteger)i] hbd_collectLeafSceneIds]];
|
|
176
|
+
}
|
|
177
|
+
return HBDRemovalPlan(HBDDispatchCodeOk, sceneIds, @"redirectTo", nil);
|
|
178
|
+
}
|
|
179
|
+
return HBDRemovalPlan(@"noop", @[], nil, nil);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
- (void)handlePushWithNavigationController:(UINavigationController *)nav
|
|
183
|
+
caller:(UIViewController *)caller
|
|
184
|
+
extras:(NSDictionary *)extras
|
|
185
|
+
completion:(HBDDispatchCompletion)completion {
|
|
186
|
+
if ([self isCallerCoveredInNavigationController:nav caller:caller]) {
|
|
187
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered in its stack."));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
131
191
|
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
132
192
|
if (!vc) {
|
|
133
193
|
RCTLogInfo(@"[Navigation] 无法创建对应的页面 %@", extras[@"moduleName"]);
|
|
134
194
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create target screen for push."));
|
|
135
195
|
return;
|
|
136
196
|
}
|
|
137
|
-
NSInteger requestCode = [extras[@"requestCode"] integerValue];
|
|
197
|
+
NSInteger requestCode = [extras[@"requestCode"] isKindOfClass:[NSNumber class]] ? [extras[@"requestCode"] integerValue] : 0;
|
|
138
198
|
if (requestCode != 0) {
|
|
139
199
|
[vc setHbd_requestCode:requestCode];
|
|
200
|
+
if (caller && caller != nav && caller != nav.topViewController && caller.hbd_sceneId.length > 0) {
|
|
201
|
+
[vc setHbd_pushCallerSceneId:caller.hbd_sceneId];
|
|
202
|
+
}
|
|
140
203
|
}
|
|
141
204
|
|
|
142
205
|
BOOL animated = YES;
|
|
@@ -147,37 +210,6 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
147
210
|
|
|
148
211
|
NSString *sceneId = vc.hbd_sceneId;
|
|
149
212
|
if (animated) {
|
|
150
|
-
BOOL canPrewarm = [vc isKindOfClass:[HBDReactViewController class]] &&
|
|
151
|
-
[(HBDReactViewController *)vc shouldPrewarmPush] &&
|
|
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 prepareForAnimatedPushInView:nav.view
|
|
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
|
-
}
|
|
181
213
|
[nav pushViewController:vc animated:YES];
|
|
182
214
|
[self animateAlongsideTransition:nav result:HBDDispatchResultOkWithSceneId(sceneId) completion:completion];
|
|
183
215
|
} else {
|
|
@@ -187,9 +219,18 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
187
219
|
}
|
|
188
220
|
|
|
189
221
|
- (void)handlePopWithNavigationController:(UINavigationController *)nav viewController:(UIViewController *)vc completion:(HBDDispatchCompletion)completion {
|
|
222
|
+
if ([self isCallerCoveredInNavigationController:nav caller:vc]) {
|
|
223
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered."));
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (nav.viewControllers.count <= 1) {
|
|
227
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Cannot pop the root scene of a stack."));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
UIViewController *top = nav.topViewController ?: vc;
|
|
190
231
|
BOOL animated = YES;
|
|
191
|
-
if ([
|
|
192
|
-
HBDViewController *hbdvc = (HBDViewController *)
|
|
232
|
+
if ([top isKindOfClass:[HBDViewController class]]) {
|
|
233
|
+
HBDViewController *hbdvc = (HBDViewController *)top;
|
|
193
234
|
animated = hbdvc.animatedTransition || hbdvc.screenOrientation == HBDScreenOrientationLandscape;
|
|
194
235
|
}
|
|
195
236
|
|
|
@@ -203,10 +244,15 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
203
244
|
}
|
|
204
245
|
|
|
205
246
|
- (void)handlePopToWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
247
|
+
NSString *moduleName = [extras[@"moduleName"] isKindOfClass:[NSString class]] ? extras[@"moduleName"] : nil;
|
|
248
|
+
if (moduleName.length == 0) {
|
|
249
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Target moduleName or sceneId is required for popTo."));
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
206
252
|
UIViewController *vc = [self findViewControllerWithNavigationController:nav extras:extras];
|
|
207
253
|
if (!vc) {
|
|
208
|
-
RCTLogInfo(@"[Navigation] 找不到要 popTo 的页面 %@",
|
|
209
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeSceneNotFound, [NSString stringWithFormat:@"Can't find target scene to popTo: %@",
|
|
254
|
+
RCTLogInfo(@"[Navigation] 找不到要 popTo 的页面 %@", moduleName);
|
|
255
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeSceneNotFound, [NSString stringWithFormat:@"Can't find target scene to popTo: %@", moduleName]));
|
|
210
256
|
return;
|
|
211
257
|
}
|
|
212
258
|
|
|
@@ -229,28 +275,30 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
229
275
|
|
|
230
276
|
- (UIViewController *)findFromViewControllerWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras {
|
|
231
277
|
NSArray *children = nav.childViewControllers;
|
|
232
|
-
NSString *moduleName = extras[@"from"];
|
|
233
|
-
|
|
278
|
+
NSString *moduleName = [extras[@"from"] isKindOfClass:[NSString class]] ? extras[@"from"] : nil;
|
|
279
|
+
if (moduleName.length == 0) {
|
|
280
|
+
return nav.topViewController;
|
|
281
|
+
}
|
|
234
282
|
|
|
235
283
|
for (NSUInteger i = children.count; i > 0; i--) {
|
|
236
284
|
NSUInteger index = i - 1;
|
|
237
285
|
UIViewController *vc = children[index];
|
|
238
286
|
NSString *vcModuleName = [vc isKindOfClass:[HBDViewController class]] ? ((HBDViewController *)vc).moduleName : nil;
|
|
239
287
|
if ([moduleName isEqualToString:vcModuleName] || [moduleName isEqualToString:vc.hbd_sceneId]) {
|
|
240
|
-
if (inclusive && index > 0) {
|
|
241
|
-
return children[index - 1];
|
|
242
|
-
}
|
|
243
288
|
return vc;
|
|
244
289
|
}
|
|
245
290
|
}
|
|
246
291
|
|
|
247
|
-
return
|
|
292
|
+
return nav.topViewController;
|
|
248
293
|
}
|
|
249
294
|
|
|
250
295
|
- (UIViewController *)findViewControllerWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras {
|
|
251
296
|
NSArray *children = nav.childViewControllers;
|
|
252
|
-
NSString *moduleName = extras[@"moduleName"];
|
|
253
|
-
|
|
297
|
+
NSString *moduleName = [extras[@"moduleName"] isKindOfClass:[NSString class]] ? extras[@"moduleName"] : nil;
|
|
298
|
+
if (moduleName.length == 0) {
|
|
299
|
+
return nil;
|
|
300
|
+
}
|
|
301
|
+
BOOL inclusive = [extras[@"inclusive"] isKindOfClass:[NSNumber class]] && [extras[@"inclusive"] boolValue];
|
|
254
302
|
|
|
255
303
|
for (NSUInteger i = children.count; i > 0; i--) {
|
|
256
304
|
NSUInteger index = i - 1;
|
|
@@ -286,14 +334,26 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
286
334
|
}
|
|
287
335
|
|
|
288
336
|
- (void)handleRedirectToWithNavigationController:(UINavigationController *)nav target:(UIViewController *)target extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
337
|
+
if (nav.viewControllers.count == 0) {
|
|
338
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Navigation stack is empty."));
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
289
341
|
UIViewController *vc = [self viewControllerWithExtras:extras];
|
|
290
342
|
if (!vc) {
|
|
291
343
|
RCTLogInfo(@"[Navigation] 无法创建对应的页面 %@", extras[@"moduleName"]);
|
|
292
344
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create target screen for redirectTo."));
|
|
293
345
|
return;
|
|
294
346
|
}
|
|
295
|
-
|
|
296
|
-
|
|
347
|
+
BOOL targetInStack = target != nil && [nav.viewControllers containsObject:target];
|
|
348
|
+
if (targetInStack) {
|
|
349
|
+
if (vc.hbd_requestCode == 0 && target.hbd_requestCode != 0) {
|
|
350
|
+
[vc setHbd_requestCode:target.hbd_requestCode];
|
|
351
|
+
}
|
|
352
|
+
if (vc.hbd_pushCallerSceneId.length == 0 && target.hbd_pushCallerSceneId.length > 0) {
|
|
353
|
+
[vc setHbd_pushCallerSceneId:target.hbd_pushCallerSceneId];
|
|
354
|
+
}
|
|
355
|
+
[target setHbd_requestCode:0];
|
|
356
|
+
[target setHbd_pushCallerSceneId:nil];
|
|
297
357
|
}
|
|
298
358
|
|
|
299
359
|
BOOL animated = YES;
|
|
@@ -304,33 +364,20 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
304
364
|
|
|
305
365
|
NSString *sceneId = vc.hbd_sceneId;
|
|
306
366
|
if (animated) {
|
|
307
|
-
[nav hbd_redirectToViewController:vc target:target animated:YES]
|
|
367
|
+
if (![nav hbd_redirectToViewController:vc target:target animated:YES]) {
|
|
368
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to redirectTo on navigation stack."));
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
308
371
|
[self animateAlongsideTransition:nav result:HBDDispatchResultOkWithSceneId(sceneId) completion:completion];
|
|
309
372
|
} else {
|
|
310
|
-
[nav hbd_redirectToViewController:vc target:target animated:NO]
|
|
373
|
+
if (![nav hbd_redirectToViewController:vc target:target animated:NO]) {
|
|
374
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to redirectTo on navigation stack."));
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
311
377
|
completion(HBDDispatchResultOkWithSceneId(sceneId));
|
|
312
378
|
}
|
|
313
379
|
}
|
|
314
380
|
|
|
315
|
-
- (void)handlePushLayoutWithNavigationController:(UINavigationController *)nav extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
316
|
-
NSDictionary *layout = extras[@"layout"];
|
|
317
|
-
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:layout];
|
|
318
|
-
if (!vc) {
|
|
319
|
-
RCTLogInfo(@"[Navigation] 无法创建对应的 vc");
|
|
320
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Unable to create layout for pushLayout."));
|
|
321
|
-
return;
|
|
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;
|
|
329
|
-
|
|
330
|
-
[nav pushViewController:vc animated:YES];
|
|
331
|
-
[self animateAlongsideTransition:nav result:HBDDispatchResultOkWithSceneId(sceneId) completion:completion];
|
|
332
|
-
}
|
|
333
|
-
|
|
334
381
|
- (void)animateAlongsideTransition:(UINavigationController *)nav completion:(HBDDispatchCompletion)completion {
|
|
335
382
|
[self animateAlongsideTransition:nav result:HBDDispatchResultOk() completion:completion];
|
|
336
383
|
}
|
|
@@ -349,9 +396,12 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
349
396
|
}
|
|
350
397
|
|
|
351
398
|
- (UIViewController *)viewControllerWithExtras:(NSDictionary *)extras {
|
|
352
|
-
NSString *moduleName = extras[@"moduleName"];
|
|
353
|
-
|
|
354
|
-
|
|
399
|
+
NSString *moduleName = [extras[@"moduleName"] isKindOfClass:[NSString class]] ? extras[@"moduleName"] : nil;
|
|
400
|
+
if (moduleName.length == 0) {
|
|
401
|
+
return nil;
|
|
402
|
+
}
|
|
403
|
+
NSDictionary *props = [extras[@"props"] isKindOfClass:[NSDictionary class]] ? extras[@"props"] : nil;
|
|
404
|
+
NSDictionary *options = [extras[@"options"] isKindOfClass:[NSDictionary class]] ? extras[@"options"] : nil;
|
|
355
405
|
return [[HBDReactBridgeManager get] viewControllerWithModuleName:moduleName props:props options:options];
|
|
356
406
|
}
|
|
357
407
|
|
|
@@ -17,16 +17,23 @@
|
|
|
17
17
|
return @[@"switchTab"];
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
- (BOOL)handlesViewController:(UIViewController *)vc {
|
|
21
|
+
return [self isMemberOfClass:[HBDTabNavigator class]] && [vc isKindOfClass:[HBDTabBarController class]];
|
|
22
|
+
}
|
|
23
|
+
|
|
20
24
|
- (UIViewController *)viewControllerWithLayout:(NSDictionary *)layout {
|
|
21
|
-
NSDictionary *model = layout[self.name];
|
|
22
|
-
NSArray *children = model[@"children"];
|
|
25
|
+
NSDictionary *model = [layout[self.name] isKindOfClass:[NSDictionary class]] ? layout[self.name] : nil;
|
|
26
|
+
NSArray *children = [model[@"children"] isKindOfClass:[NSArray class]] ? model[@"children"] : nil;
|
|
23
27
|
if (!children) {
|
|
24
28
|
return nil;
|
|
25
29
|
}
|
|
26
|
-
|
|
30
|
+
|
|
27
31
|
NSMutableArray *viewControllers = [[NSMutableArray alloc] initWithCapacity:4];
|
|
28
|
-
for (
|
|
29
|
-
|
|
32
|
+
for (id tab in children) {
|
|
33
|
+
if (![tab isKindOfClass:[NSDictionary class]]) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
UIViewController *vc = [[HBDReactBridgeManager get] viewControllerWithLayout:(NSDictionary *)tab];
|
|
30
37
|
if (vc) {
|
|
31
38
|
[viewControllers addObject:vc];
|
|
32
39
|
}
|
|
@@ -34,15 +41,15 @@
|
|
|
34
41
|
if (viewControllers.count == 0) {
|
|
35
42
|
return nil;
|
|
36
43
|
}
|
|
37
|
-
|
|
38
|
-
NSDictionary *options = model[@"options"];
|
|
44
|
+
|
|
45
|
+
NSDictionary *options = [model[@"options"] isKindOfClass:[NSDictionary class]] ? model[@"options"] : nil;
|
|
39
46
|
HBDTabBarController *tabBarController = [[HBDTabBarController alloc] init];
|
|
40
47
|
[tabBarController setViewControllers:viewControllers];
|
|
41
48
|
|
|
42
|
-
if (options) {
|
|
43
|
-
|
|
44
|
-
if (selectedIndex) {
|
|
45
|
-
tabBarController.selectedIndex = (NSUInteger)
|
|
49
|
+
if (options && [options[@"selectedIndex"] isKindOfClass:[NSNumber class]]) {
|
|
50
|
+
NSInteger selectedIndex = [options[@"selectedIndex"] integerValue];
|
|
51
|
+
if (selectedIndex >= 0 && (NSUInteger)selectedIndex < viewControllers.count) {
|
|
52
|
+
tabBarController.selectedIndex = (NSUInteger)selectedIndex;
|
|
46
53
|
}
|
|
47
54
|
}
|
|
48
55
|
|
|
@@ -53,11 +60,10 @@
|
|
|
53
60
|
if (![vc isKindOfClass:[HBDTabBarController class]]) {
|
|
54
61
|
return nil;
|
|
55
62
|
}
|
|
56
|
-
|
|
63
|
+
|
|
57
64
|
HBDTabBarController *tabBarController = (HBDTabBarController *) vc;
|
|
58
65
|
NSMutableArray *children = [[NSMutableArray alloc] init];
|
|
59
|
-
for (
|
|
60
|
-
UIViewController *child = tabBarController.childViewControllers[i];
|
|
66
|
+
for (UIViewController *child in tabBarController.viewControllers) {
|
|
61
67
|
NSDictionary *graph = [[HBDReactBridgeManager get] routeGraphWithViewController:child];
|
|
62
68
|
if (graph) {
|
|
63
69
|
[children addObject:graph];
|
|
@@ -79,7 +85,7 @@
|
|
|
79
85
|
return nil;
|
|
80
86
|
}
|
|
81
87
|
UITabBarController *tabBarController = (UITabBarController *) vc;
|
|
82
|
-
return [[HBDReactBridgeManager get]
|
|
88
|
+
return [[HBDReactBridgeManager get] primaryViewControllerInHierarchy:tabBarController.selectedViewController];
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
- (UITabBarController *)tabBarControllerForViewController:(UIViewController *)vc {
|
|
@@ -90,26 +96,66 @@
|
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
|
|
93
|
-
- (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
if (index == NSNotFound) {
|
|
103
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeSceneNotFound, @"Tab key was not found."));
|
|
104
|
-
return;
|
|
99
|
+
- (NSInteger)resolveTargetTabIndexForTabBarController:(UITabBarController *)tabBarController extras:(NSDictionary *)extras {
|
|
100
|
+
id toValue = extras[@"to"];
|
|
101
|
+
if ([toValue isKindOfClass:[NSString class]]) {
|
|
102
|
+
if ([tabBarController isKindOfClass:[HBDTabBarController class]]) {
|
|
103
|
+
NSUInteger found = [[(HBDTabBarController *)tabBarController tabKeys] indexOfObject:(NSString *)toValue];
|
|
104
|
+
if (found != NSNotFound) {
|
|
105
|
+
return (NSInteger)found;
|
|
106
|
+
}
|
|
105
107
|
}
|
|
106
|
-
|
|
108
|
+
return NSNotFound;
|
|
109
|
+
}
|
|
110
|
+
if ([toValue isKindOfClass:[NSNumber class]]) {
|
|
111
|
+
return [(NSNumber *)toValue integerValue];
|
|
112
|
+
}
|
|
113
|
+
return NSNotFound;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
- (nullable NSDictionary *)removalPlanWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras {
|
|
117
|
+
if (![action isEqualToString:@"switchTab"]) {
|
|
118
|
+
return HBDRemovalPlan(@"noop", @[], nil, nil);
|
|
119
|
+
}
|
|
120
|
+
BOOL popToRoot = [extras[@"popToRoot"] isKindOfClass:[NSNumber class]] && [extras[@"popToRoot"] boolValue];
|
|
121
|
+
if (!popToRoot) {
|
|
122
|
+
return HBDRemovalPlan(@"noop", @[], nil, nil);
|
|
123
|
+
}
|
|
124
|
+
UITabBarController *tabBarController = [self tabBarControllerForViewController:vc];
|
|
125
|
+
if (!tabBarController) {
|
|
126
|
+
return HBDRemovalPlan(@"noop", @[], nil, nil);
|
|
127
|
+
}
|
|
128
|
+
NSInteger toIndex = [self resolveTargetTabIndexForTabBarController:tabBarController extras:extras];
|
|
129
|
+
if (toIndex == NSNotFound || toIndex < 0 || (NSUInteger)toIndex >= tabBarController.viewControllers.count || (NSUInteger)toIndex == tabBarController.selectedIndex) {
|
|
130
|
+
return HBDRemovalPlan(@"noop", @[], nil, nil);
|
|
107
131
|
}
|
|
108
|
-
|
|
109
|
-
|
|
132
|
+
UIViewController *previousTab = tabBarController.selectedViewController;
|
|
133
|
+
if (![previousTab isKindOfClass:[UINavigationController class]]) {
|
|
134
|
+
return HBDRemovalPlan(@"noop", @[], nil, nil);
|
|
135
|
+
}
|
|
136
|
+
NSArray<UIViewController *> *children = ((UINavigationController *)previousTab).viewControllers;
|
|
137
|
+
if (children.count <= 1) {
|
|
138
|
+
return HBDRemovalPlan(@"noop", @[], nil, nil);
|
|
139
|
+
}
|
|
140
|
+
NSMutableArray<NSString *> *sceneIds = [NSMutableArray array];
|
|
141
|
+
for (NSInteger i = (NSInteger)children.count - 1; i > 0; i--) {
|
|
142
|
+
[sceneIds addObjectsFromArray:[children[(NSUInteger)i] hbd_collectLeafSceneIds]];
|
|
143
|
+
}
|
|
144
|
+
return HBDRemovalPlan(HBDDispatchCodeOk, sceneIds, @"popToRoot", nil);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
- (void)handleSwitchTabWithTabBarController:(UITabBarController *)tabBarController extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
148
|
+
BOOL popToRoot = [extras[@"popToRoot"] isKindOfClass:[NSNumber class]] && [extras[@"popToRoot"] boolValue];
|
|
149
|
+
id toValue = extras[@"to"];
|
|
150
|
+
if (![toValue isKindOfClass:[NSString class]] && ![toValue isKindOfClass:[NSNumber class]]) {
|
|
151
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Tab index or key is required for switchTab."));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
NSInteger toIndex = [self resolveTargetTabIndexForTabBarController:tabBarController extras:extras];
|
|
155
|
+
if (toIndex == NSNotFound) {
|
|
156
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeSceneNotFound, [NSString stringWithFormat:@"Can't find tab for key: %@", toValue]));
|
|
110
157
|
return;
|
|
111
158
|
}
|
|
112
|
-
NSInteger toIndex = [toNumber integerValue];
|
|
113
159
|
if (toIndex < 0 || (NSUInteger)toIndex >= tabBarController.viewControllers.count) {
|
|
114
160
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Tab index out of bounds: %ld", (long)toIndex]));
|
|
115
161
|
return;
|
|
@@ -121,23 +167,30 @@
|
|
|
121
167
|
return;
|
|
122
168
|
}
|
|
123
169
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
nav =
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
[nav popToRootViewControllerAnimated:NO];
|
|
170
|
+
UIViewController *previousTab = popToRoot ? [tabBarController selectedViewController] : nil;
|
|
171
|
+
tabBarController.selectedIndex = to;
|
|
172
|
+
|
|
173
|
+
dispatch_block_t finalizeSwitchTab = ^{
|
|
174
|
+
if ([previousTab isKindOfClass:[UINavigationController class]] &&
|
|
175
|
+
tabBarController.selectedViewController != previousTab) {
|
|
176
|
+
UINavigationController *nav = (UINavigationController *)previousTab;
|
|
177
|
+
if (nav.viewControllers.count > 1) {
|
|
178
|
+
[nav popToRootViewControllerAnimated:NO];
|
|
179
|
+
}
|
|
135
180
|
}
|
|
181
|
+
completion(HBDDispatchResultOk());
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
if (tabBarController.transitionCoordinator) {
|
|
185
|
+
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
186
|
+
[manager waitForTransitionOnViewController:tabBarController
|
|
187
|
+
commandId:manager.activeCommandId
|
|
188
|
+
retryCount:0
|
|
189
|
+
action:finalizeSwitchTab
|
|
190
|
+
onTimeout:finalizeSwitchTab];
|
|
191
|
+
} else {
|
|
192
|
+
finalizeSwitchTab();
|
|
136
193
|
}
|
|
137
|
-
|
|
138
|
-
tabBarController.selectedIndex = to;
|
|
139
|
-
|
|
140
|
-
completion(HBDDispatchResultOk());
|
|
141
194
|
}
|
|
142
195
|
|
|
143
196
|
- (void)handleNavigationWithViewController:(UIViewController *)vc action:(NSString *)action extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
@@ -2,30 +2,63 @@
|
|
|
2
2
|
#import "HBDReactBridgeManager.h"
|
|
3
3
|
#import <ReactCommon/RCTHost.h>
|
|
4
4
|
#import <React/RCTLog.h>
|
|
5
|
+
#import <atomic>
|
|
5
6
|
|
|
6
|
-
@implementation HBDNativeEvent
|
|
7
|
+
@implementation HBDNativeEvent {
|
|
8
|
+
std::atomic<bool> _eventEmitterReady;
|
|
9
|
+
std::atomic<bool> _invalidated;
|
|
10
|
+
}
|
|
7
11
|
|
|
8
|
-
+ (NSString *)moduleName {
|
|
12
|
+
+ (NSString *)moduleName {
|
|
9
13
|
return @"HBDNativeEvent";
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
- (
|
|
16
|
+
- (instancetype)init {
|
|
17
|
+
if (self = [super init]) {
|
|
18
|
+
_eventEmitterReady.store(false, std::memory_order_relaxed);
|
|
19
|
+
_invalidated.store(false, std::memory_order_relaxed);
|
|
20
|
+
}
|
|
21
|
+
return self;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
13
25
|
return std::make_shared<facebook::react::NativeEventSpecJSI>(params);
|
|
14
26
|
}
|
|
15
27
|
|
|
28
|
+
- (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper {
|
|
29
|
+
[super setEventEmitterCallback:eventEmitterCallbackWrapper];
|
|
30
|
+
_eventEmitterReady.store(true, std::memory_order_release);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (BOOL)isEventEmitterReady {
|
|
34
|
+
return _eventEmitterReady.load(std::memory_order_acquire) && !_invalidated.load(std::memory_order_acquire);
|
|
35
|
+
}
|
|
36
|
+
|
|
16
37
|
- (void)initialize {
|
|
17
38
|
RCTLogInfo(@"[Navigation] HBDNativeEvent#initialize");
|
|
18
39
|
}
|
|
19
40
|
|
|
20
41
|
- (void)invalidate {
|
|
21
42
|
RCTLogInfo(@"[Navigation] HBDNativeEvent#invalidate");
|
|
43
|
+
_invalidated.store(true, std::memory_order_release);
|
|
22
44
|
}
|
|
23
45
|
|
|
24
46
|
+ (HBDNativeEvent *)getInstance {
|
|
25
47
|
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
26
48
|
RCTHost *rctHost = manager.rctHost;
|
|
27
|
-
|
|
28
|
-
|
|
49
|
+
RCTModuleRegistry *moduleRegistry = [rctHost moduleRegistry];
|
|
50
|
+
if (!moduleRegistry || ![moduleRegistry moduleIsInitialized:self.class]) {
|
|
51
|
+
return nil;
|
|
52
|
+
}
|
|
53
|
+
id module = [moduleRegistry moduleForName:"HBDNativeEvent" lazilyLoadIfNecessary:NO];
|
|
54
|
+
if (![module isKindOfClass:self.class]) {
|
|
55
|
+
return nil;
|
|
56
|
+
}
|
|
57
|
+
HBDNativeEvent *emitter = (HBDNativeEvent *)module;
|
|
58
|
+
if (![emitter isEventEmitterReady]) {
|
|
59
|
+
return nil;
|
|
60
|
+
}
|
|
61
|
+
return emitter;
|
|
29
62
|
}
|
|
30
63
|
|
|
31
64
|
@end
|