hybrid-navigation 5.2.0 → 5.4.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/README.md +9 -20
- package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +5 -13
- package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
- package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +0 -50
- package/android/src/main/java/com/navigation/androidx/TabBarItem.java +0 -4
- package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +0 -7
- package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +7 -43
- package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +5 -39
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +72 -136
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +0 -20
- package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +10 -21
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +39 -87
- package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +2 -16
- package/dist/NativeEvent.d.ts +1 -11
- package/dist/NativeNavigation.d.ts +7 -6
- package/dist/Navigation.d.ts +8 -22
- package/dist/Navigation.js +33 -175
- package/dist/NavigationComponentWrap.d.ts +3 -3
- package/dist/Navigator.d.ts +4 -5
- package/dist/Navigator.js +13 -37
- package/dist/Options.d.ts +3 -2
- package/dist/Route.d.ts +10 -35
- package/dist/handler/DispatchCommandHandler.d.ts +3 -18
- package/dist/handler/DispatchCommandHandler.js +17 -64
- package/dist/handler/LayoutCommandHandler.d.ts +2 -3
- package/dist/handler/LayoutCommandHandler.js +0 -3
- package/dist/handler/LeaveGuardHandler.d.ts +3 -3
- package/dist/handler/LeaveGuardHandler.js +57 -32
- package/dist/handler/LifecycleEventHandler.d.ts +2 -14
- package/dist/handler/LifecycleEventHandler.js +2 -79
- package/dist/handler/ResultEventHandler.d.ts +0 -1
- package/dist/handler/ResultEventHandler.js +0 -3
- package/dist/handler/SceneExitHandler.d.ts +3 -0
- package/dist/handler/SceneExitHandler.js +76 -0
- package/dist/hooks.d.ts +0 -3
- package/dist/hooks.js +21 -46
- package/dist/index.d.ts +1 -12
- package/dist/index.js +0 -3
- package/dist/router/index.d.ts +0 -1
- package/dist/router/index.js +43 -11
- package/dist/router/stack.d.ts +1 -1
- package/dist/sceneCoverage.d.ts +2 -0
- package/dist/sceneCoverage.js +25 -0
- package/dist/store.d.ts +0 -2
- package/dist/store.js +0 -4
- package/ios/HBDGlobalStyle.h +0 -1
- package/ios/HBDGlobalStyle.mm +0 -7
- package/ios/HybridNavigation.h +0 -1
- package/ios/Navigator/HBDScreenNavigator.mm +89 -237
- package/ios/Navigator/HBDStackNavigator.mm +3 -3
- package/ios/Navigator/HBDTabNavigator.mm +15 -30
- package/ios/React/HBDNativeNavigation.mm +4 -31
- package/ios/React/HBDReactBridgeManager.h +0 -5
- package/ios/React/HBDReactBridgeManager.mm +0 -17
- package/ios/ViewController/HBDReactViewController.h +3 -1
- package/ios/ViewController/HBDReactViewController.mm +42 -9
- package/ios/ViewController/HBDTabBarController.h +2 -11
- package/ios/ViewController/HBDTabBarController.mm +14 -170
- package/ios/ViewController/HBDViewController.h +0 -1
- package/ios/ViewController/HBDViewController.mm +9 -57
- package/ios/ViewController/UIViewController+HBD.h +2 -0
- package/ios/ViewController/UIViewController+HBD.mm +5 -0
- package/package.json +1 -3
- package/src/NativeEvent.ts +1 -12
- package/src/NativeNavigation.ts +8 -7
- package/src/Navigation.ts +50 -281
- package/src/NavigationComponentWrap.tsx +3 -11
- package/src/Navigator.ts +15 -46
- package/src/Options.ts +3 -3
- package/src/Route.ts +13 -56
- package/src/handler/DispatchCommandHandler.ts +29 -111
- package/src/handler/LayoutCommandHandler.ts +2 -6
- package/src/handler/LeaveGuardHandler.ts +65 -32
- package/src/handler/LifecycleEventHandler.ts +22 -122
- package/src/handler/ResultEventHandler.ts +0 -6
- package/src/handler/SceneExitHandler.ts +86 -0
- package/src/hooks.ts +18 -53
- package/src/index.ts +0 -14
- package/src/router/index.ts +45 -12
- package/src/router/stack.ts +1 -1
- package/src/sceneCoverage.ts +30 -0
- package/src/store.ts +0 -5
- package/dist/defineRoutes.d.ts +0 -19
- package/dist/defineRoutes.js +0 -6
- package/dist/handler/PresentationCoordinator.d.ts +0 -39
- package/dist/handler/PresentationCoordinator.js +0 -673
- package/dist/handler/TabEventHandler.d.ts +0 -8
- package/dist/handler/TabEventHandler.js +0 -25
- package/dist/reveal.d.ts +0 -46
- package/dist/reveal.js +0 -431
- package/dist/routeGraph.d.ts +0 -12
- package/dist/routeGraph.js +0 -68
- package/dist/testing.d.ts +0 -82
- package/dist/testing.js +0 -253
- package/ios/ViewController/HBDTabBarRenderer.h +0 -28
- package/src/defineRoutes.ts +0 -46
- package/src/handler/PresentationCoordinator.ts +0 -806
- package/src/handler/TabEventHandler.ts +0 -31
- package/src/reveal.ts +0 -565
- package/src/routeGraph.ts +0 -87
- package/src/testing.ts +0 -402
- package/testing.d.ts +0 -1
- package/testing.js +0 -3
|
@@ -57,8 +57,10 @@
|
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
BOOL closeSelf = [action isEqualToString:@"close"];
|
|
61
|
+
if (closeSelf || [action isEqualToString:@"dismiss"] || [action isEqualToString:@"hideModal"]) {
|
|
62
|
+
NSDictionary *result = closeSelf ? extras[@"result"] : nil;
|
|
63
|
+
[self handleDismissWithViewController:vc closeSelf:closeSelf selfOnly:(closeSelf || [extras[@"target"] isEqual:@"self"]) result:result retryCount:0 completion:completion];
|
|
62
64
|
return;
|
|
63
65
|
}
|
|
64
66
|
|
|
@@ -67,11 +69,6 @@
|
|
|
67
69
|
return;
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
if ([action isEqualToString:@"hideModal"]) {
|
|
71
|
-
[self handleDismissWithViewController:vc extras:extras completion:completion];
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
72
|
if ([action isEqualToString:@"presentLayout"]) {
|
|
76
73
|
[self handlePresentLayoutWithViewController:vc extras:extras completion:completion];
|
|
77
74
|
return;
|
|
@@ -82,11 +79,6 @@
|
|
|
82
79
|
return;
|
|
83
80
|
}
|
|
84
81
|
|
|
85
|
-
if ([action isEqualToString:@"close"]) {
|
|
86
|
-
[self handleCloseWithViewController:vc extras:extras completion:completion];
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
82
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Unsupported screen action: %@", action]));
|
|
91
83
|
}
|
|
92
84
|
|
|
@@ -109,76 +101,11 @@
|
|
|
109
101
|
return vc.hbd_sceneId;
|
|
110
102
|
}
|
|
111
103
|
|
|
112
|
-
- (BOOL)waitForTransitionIfNeededForViewController:(nullable UIViewController *)vc
|
|
113
|
-
retryCount:(NSUInteger)retryCount
|
|
114
|
-
retry:(void (^)(NSUInteger nextRetryCount))retry {
|
|
115
|
-
if (!vc || (!vc.isBeingPresented && !vc.isBeingDismissed)) {
|
|
116
|
-
return NO;
|
|
117
|
-
}
|
|
118
|
-
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
119
|
-
NSUInteger commandId = manager.activeCommandId;
|
|
120
|
-
id<UIViewControllerTransitionCoordinator> coordinator = vc.transitionCoordinator;
|
|
121
|
-
if (coordinator) {
|
|
122
|
-
[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
123
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
124
|
-
if (commandId != 0 && manager.activeCommandId != commandId) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
retry(0);
|
|
128
|
-
});
|
|
129
|
-
}];
|
|
130
|
-
return YES;
|
|
131
|
-
}
|
|
132
|
-
if (retryCount >= 3) {
|
|
133
|
-
return NO;
|
|
134
|
-
}
|
|
135
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
136
|
-
if (commandId != 0 && manager.activeCommandId != commandId) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
retry(retryCount + 1);
|
|
140
|
-
});
|
|
141
|
-
return YES;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
- (BOOL)waitForDismissalIfNeededForViewController:(UIViewController *)presenting retry:(dispatch_block_t)retry {
|
|
145
|
-
UIViewController *presented = presenting.presentedViewController;
|
|
146
|
-
if (!presented || !presented.isBeingDismissed) {
|
|
147
|
-
return NO;
|
|
148
|
-
}
|
|
149
|
-
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
150
|
-
NSUInteger commandId = manager.activeCommandId;
|
|
151
|
-
id<UIViewControllerTransitionCoordinator> coordinator = presented.transitionCoordinator;
|
|
152
|
-
if (coordinator) {
|
|
153
|
-
[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
|
|
154
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
155
|
-
if (commandId != 0 && manager.activeCommandId != commandId) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
retry();
|
|
159
|
-
});
|
|
160
|
-
}];
|
|
161
|
-
} else {
|
|
162
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
163
|
-
if (commandId != 0 && manager.activeCommandId != commandId) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
retry();
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
return YES;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
104
|
- (void)handlePresentWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
173
105
|
if ([self isInsideModalViewController:presenting]) {
|
|
174
106
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Cannot present a scene on top of a modal."));
|
|
175
107
|
return;
|
|
176
108
|
}
|
|
177
|
-
if ([self waitForDismissalIfNeededForViewController:presenting retry:^{
|
|
178
|
-
[self handlePresentWithViewController:presenting extras:extras completion:completion];
|
|
179
|
-
}]) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
109
|
if (![presenting hbd_canPresentViewController]) {
|
|
183
110
|
completion(HBDDispatchResultFail(HBDDispatchCodeAlreadyPresenting, @"Target scene is already presenting another scene."));
|
|
184
111
|
return;
|
|
@@ -210,181 +137,116 @@
|
|
|
210
137
|
return host;
|
|
211
138
|
}
|
|
212
139
|
|
|
213
|
-
- (
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
id rawData = pendingResult[@"data"];
|
|
224
|
-
NSDictionary *resultData = [rawData isKindOfClass:[NSDictionary class]] ? rawData : nil;
|
|
225
|
-
[vc hbd_setResultCode:resultCode resultData:resultData];
|
|
226
|
-
return YES;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
- (BOOL)viewController:(UIViewController *)viewController hasAncestorOrSelf:(nullable UIViewController *)ancestor {
|
|
230
|
-
if (!viewController || !ancestor) {
|
|
231
|
-
return NO;
|
|
232
|
-
}
|
|
233
|
-
for (UIViewController *current = viewController; current != nil; current = current.parentViewController) {
|
|
234
|
-
if (current == ancestor) {
|
|
235
|
-
return YES;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return NO;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
- (void)handleCloseWithViewController:(UIViewController *)vc extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
242
|
-
[self handleCloseWithViewController:vc extras:extras retryCount:0 completion:completion];
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
- (void)handleCloseWithViewController:(UIViewController *)vc extras:(NSDictionary *)extras retryCount:(NSUInteger)retryCount completion:(HBDDispatchCompletion)completion {
|
|
246
|
-
UIViewController *modalHost = [self modalHostViewControllerForViewController:vc];
|
|
247
|
-
if ([self waitForDismissalIfNeededForViewController:modalHost retry:^{
|
|
248
|
-
[self handleCloseWithViewController:vc extras:extras retryCount:0 completion:completion];
|
|
249
|
-
}]) {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
if ([self waitForTransitionIfNeededForViewController:modalHost retryCount:retryCount retry:^(NSUInteger nextRetryCount) {
|
|
253
|
-
[self handleCloseWithViewController:vc extras:extras retryCount:nextRetryCount completion:completion];
|
|
254
|
-
}]) {
|
|
140
|
+
- (void)handleDismissWithViewController:(UIViewController *)vc
|
|
141
|
+
closeSelf:(BOOL)closeSelf
|
|
142
|
+
selfOnly:(BOOL)selfOnly
|
|
143
|
+
result:(NSDictionary *)result
|
|
144
|
+
retryCount:(NSUInteger)retryCount
|
|
145
|
+
completion:(HBDDispatchCompletion)completion {
|
|
146
|
+
UIViewController *host = [self modalHostViewControllerForViewController:vc];
|
|
147
|
+
UIViewController *presented = host.presentedViewController;
|
|
148
|
+
if (selfOnly && presented) {
|
|
149
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered by a presented scene."));
|
|
255
150
|
return;
|
|
256
151
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
152
|
+
UIViewController *transitioning = nil;
|
|
153
|
+
if (host.isBeingPresented || host.isBeingDismissed) {
|
|
154
|
+
transitioning = host;
|
|
155
|
+
} else if (presented.isBeingPresented || presented.isBeingDismissed) {
|
|
156
|
+
transitioning = presented;
|
|
157
|
+
}
|
|
158
|
+
if (transitioning) {
|
|
159
|
+
HBDReactBridgeManager *manager = [HBDReactBridgeManager get];
|
|
160
|
+
NSUInteger commandId = manager.activeCommandId;
|
|
161
|
+
dispatch_block_t retry = ^{
|
|
162
|
+
if (commandId == 0 || manager.activeCommandId == commandId) {
|
|
163
|
+
[self handleDismissWithViewController:vc closeSelf:closeSelf selfOnly:selfOnly result:result retryCount:retryCount + 1 completion:completion];
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
id<UIViewControllerTransitionCoordinator> coordinator = transitioning.transitionCoordinator;
|
|
167
|
+
if (coordinator) {
|
|
168
|
+
[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
|
|
169
|
+
dispatch_async(dispatch_get_main_queue(), retry);
|
|
170
|
+
}];
|
|
171
|
+
} else if (retryCount < 3) {
|
|
172
|
+
dispatch_async(dispatch_get_main_queue(), retry);
|
|
173
|
+
} else {
|
|
174
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeNotReady, @"Dismiss transition is still in progress."));
|
|
277
175
|
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (modalHost.presentingViewController != nil) {
|
|
281
|
-
NSMutableDictionary *dismissExtras = extras ? [extras mutableCopy] : [NSMutableDictionary dictionary];
|
|
282
|
-
dismissExtras[@"target"] = @"self";
|
|
283
|
-
[self handleDismissWithViewController:vc extras:[dismissExtras copy] completion:completion];
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Target scene cannot be closed."));
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
- (void)handleDismissWithViewController:(UIViewController *)vc extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
291
|
-
[self handleDismissWithViewController:vc extras:extras retryCount:0 completion:completion];
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
- (void)handleDismissWithViewController:(UIViewController *)vc extras:(NSDictionary *)extras retryCount:(NSUInteger)retryCount completion:(HBDDispatchCompletion)completion {
|
|
295
|
-
UIViewController *modalHost = [self modalHostViewControllerForViewController:vc];
|
|
296
|
-
if ([self waitForDismissalIfNeededForViewController:modalHost retry:^{
|
|
297
|
-
[self handleDismissWithViewController:vc extras:extras retryCount:0 completion:completion];
|
|
298
|
-
}]) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
if ([self waitForTransitionIfNeededForViewController:modalHost retryCount:retryCount retry:^(NSUInteger nextRetryCount) {
|
|
302
|
-
[self handleDismissWithViewController:vc extras:extras retryCount:nextRetryCount completion:completion];
|
|
303
|
-
}]) {
|
|
304
176
|
return;
|
|
305
177
|
}
|
|
306
178
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered by another presented scene."));
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
if (!presenting) {
|
|
325
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Target scene is not presented."));
|
|
326
|
-
return;
|
|
179
|
+
if (closeSelf) {
|
|
180
|
+
UINavigationController *popStack = nil;
|
|
181
|
+
for (UIViewController *child = vc; child.parentViewController; child = child.parentViewController) {
|
|
182
|
+
if (![child.parentViewController isKindOfClass:UINavigationController.class]) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
UINavigationController *stack = (UINavigationController *)child.parentViewController;
|
|
186
|
+
if (stack.topViewController != child) {
|
|
187
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered in its stack."));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (!popStack && stack.viewControllers.count > 1) {
|
|
191
|
+
popStack = stack;
|
|
192
|
+
}
|
|
327
193
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
194
|
+
if (popStack) {
|
|
195
|
+
if (popStack.transitionCoordinator) {
|
|
196
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeNotReady, @"Navigation stack is transitioning."));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
UIViewController *top = popStack.topViewController;
|
|
200
|
+
NSInteger oldCode = top.hbd_resultCode;
|
|
201
|
+
NSDictionary *oldData = top.hbd_resultData;
|
|
202
|
+
[self applyCloseResult:result toViewController:top];
|
|
203
|
+
[[HBDReactBridgeManager get] handleNavigationWithViewController:top action:@"pop" extras:@{} completion:^(NSDictionary *reply) {
|
|
204
|
+
if ([popStack.viewControllers containsObject:top]) {
|
|
205
|
+
if (result) {
|
|
206
|
+
[top hbd_setLocalResultCode:oldCode resultData:oldData];
|
|
207
|
+
}
|
|
208
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeNotReady, @"Target scene was not popped."));
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
completion(reply);
|
|
212
|
+
}];
|
|
331
213
|
return;
|
|
332
214
|
}
|
|
333
215
|
}
|
|
334
216
|
|
|
335
|
-
|
|
336
|
-
|
|
217
|
+
UIViewController *target = presented ?: host;
|
|
218
|
+
UIViewController *presenter = target.presentingViewController;
|
|
219
|
+
if (!presenter) {
|
|
337
220
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Nothing to dismiss."));
|
|
338
221
|
return;
|
|
339
222
|
}
|
|
340
223
|
|
|
341
|
-
BOOL
|
|
342
|
-
if (
|
|
343
|
-
|
|
344
|
-
}]) {
|
|
345
|
-
return;
|
|
224
|
+
BOOL animated = target.modalPresentationStyle != UIModalPresentationOverFullScreen;
|
|
225
|
+
if (animated && target == host && [vc isKindOfClass:[HBDViewController class]]) {
|
|
226
|
+
animated = ((HBDViewController *)vc).animatedTransition;
|
|
346
227
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
UIViewController *revealed = dismissPresented ? modalHost : presenting;
|
|
351
|
-
BOOL dismissAnimated = dismissPresented ? (presented.modalPresentationStyle != UIModalPresentationOverFullScreen) : animated;
|
|
352
|
-
|
|
353
|
-
NSInteger previousResultCode = vc.hbd_resultCode;
|
|
354
|
-
NSDictionary *previousResultData = vc.hbd_resultData;
|
|
355
|
-
BOOL appliedPendingResult = NO;
|
|
356
|
-
if (!dismissPresented) {
|
|
357
|
-
appliedPendingResult = [self applyPendingResultIfPresentToViewController:vc extras:extras];
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
__weak UIViewController *weakDismissedTarget = dismissedTarget;
|
|
361
|
-
[dismissReceiver dismissViewControllerAnimated:dismissAnimated completion:^{
|
|
362
|
-
UIViewController *remainingTarget = weakDismissedTarget;
|
|
363
|
-
if (remainingTarget != nil && remainingTarget.presentingViewController != nil) {
|
|
364
|
-
if (appliedPendingResult) {
|
|
365
|
-
[vc hbd_setResultCode:previousResultCode resultData:previousResultData];
|
|
366
|
-
}
|
|
367
|
-
RCTLogWarn(@"[Navigation] dismissViewControllerAnimated completed but target scene is still presented. sceneId=%@", vc.hbd_sceneId);
|
|
368
|
-
NSString *code = remainingTarget.presentedViewController != nil ? HBDDispatchCodeCovered : HBDDispatchCodeNotReady;
|
|
369
|
-
completion(HBDDispatchResultFail(code, @"Target scene was not dismissed."));
|
|
228
|
+
[presenter dismissViewControllerAnimated:animated completion:^{
|
|
229
|
+
if (target.presentingViewController != nil) {
|
|
230
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeNotReady, @"Target scene was not dismissed."));
|
|
370
231
|
return;
|
|
371
232
|
}
|
|
233
|
+
[self applyCloseResult:result toViewController:target];
|
|
234
|
+
HBDViewController *revealed = [[HBDReactBridgeManager get] primaryViewControllerWithViewController:presenter];
|
|
372
235
|
if (revealed != nil) {
|
|
373
|
-
|
|
374
|
-
if (hbdvc != nil) {
|
|
375
|
-
[[HBDOrientationCoordinator shared] applyOrientationForViewController:hbdvc];
|
|
376
|
-
}
|
|
236
|
+
[[HBDOrientationCoordinator shared] applyOrientationForViewController:revealed];
|
|
377
237
|
}
|
|
378
238
|
completion(HBDDispatchResultOk());
|
|
379
239
|
}];
|
|
380
240
|
}
|
|
381
241
|
|
|
382
|
-
- (void)
|
|
383
|
-
if ([
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
return;
|
|
242
|
+
- (void)applyCloseResult:(NSDictionary *)result toViewController:(UIViewController *)vc {
|
|
243
|
+
if ([result[@"code"] isKindOfClass:NSNumber.class]) {
|
|
244
|
+
NSDictionary *data = result[@"data"];
|
|
245
|
+
[vc hbd_setLocalResultCode:[result[@"code"] integerValue] resultData:[data isKindOfClass:NSDictionary.class] ? data : nil];
|
|
387
246
|
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
- (void)handleShowModalWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
388
250
|
if (![presenting hbd_canPresentViewController]) {
|
|
389
251
|
completion(HBDDispatchResultFail(HBDDispatchCodeAlreadyPresenting, @"Target scene is already presenting another scene."));
|
|
390
252
|
return;
|
|
@@ -412,11 +274,6 @@
|
|
|
412
274
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Cannot present a scene on top of a modal."));
|
|
413
275
|
return;
|
|
414
276
|
}
|
|
415
|
-
if ([self waitForDismissalIfNeededForViewController:presenting retry:^{
|
|
416
|
-
[self handlePresentLayoutWithViewController:presenting extras:extras completion:completion];
|
|
417
|
-
}]) {
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
277
|
if (![presenting hbd_canPresentViewController]) {
|
|
421
278
|
completion(HBDDispatchResultFail(HBDDispatchCodeAlreadyPresenting, @"Target scene is already presenting another scene."));
|
|
422
279
|
return;
|
|
@@ -440,11 +297,6 @@
|
|
|
440
297
|
}
|
|
441
298
|
|
|
442
299
|
- (void)handleShowModalLayoutWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
443
|
-
if ([self waitForDismissalIfNeededForViewController:presenting retry:^{
|
|
444
|
-
[self handleShowModalLayoutWithViewController:presenting extras:extras completion:completion];
|
|
445
|
-
}]) {
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
300
|
if (![presenting hbd_canPresentViewController]) {
|
|
449
301
|
completion(HBDDispatchResultFail(HBDDispatchCodeAlreadyPresenting, @"Target scene is already presenting another scene."));
|
|
450
302
|
return;
|
|
@@ -147,8 +147,8 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
147
147
|
|
|
148
148
|
NSString *sceneId = vc.hbd_sceneId;
|
|
149
149
|
if (animated) {
|
|
150
|
-
BOOL canPrewarm = [
|
|
151
|
-
[vc
|
|
150
|
+
BOOL canPrewarm = [vc isKindOfClass:[HBDReactViewController class]] &&
|
|
151
|
+
[(HBDReactViewController *)vc shouldPrewarmPush] &&
|
|
152
152
|
nav.tabBarController == nil &&
|
|
153
153
|
nav.presentingViewController == nil &&
|
|
154
154
|
nav.view.window != nil &&
|
|
@@ -159,7 +159,7 @@ static const NSTimeInterval HBDPushPrewarmTimeoutSeconds = 0.18;
|
|
|
159
159
|
NSUInteger commandId = manager.activeCommandId;
|
|
160
160
|
__weak HBDStackNavigator *weakSelf = self;
|
|
161
161
|
__weak UINavigationController *weakNav = nav;
|
|
162
|
-
BOOL prewarming = [reactVC
|
|
162
|
+
BOOL prewarming = [reactVC prepareForAnimatedPushInView:nav.view
|
|
163
163
|
timeout:HBDPushPrewarmTimeoutSeconds
|
|
164
164
|
completion:^{
|
|
165
165
|
HBDStackNavigator *strongSelf = weakSelf;
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
#import "HBDUtils.h"
|
|
6
6
|
#import "HBDGlobalStyle.h"
|
|
7
7
|
|
|
8
|
-
#import <React/RCTLog.h>
|
|
9
8
|
#import <React/RCTUtils.h>
|
|
10
9
|
|
|
11
10
|
@implementation HBDTabNavigator
|
|
@@ -38,17 +37,6 @@
|
|
|
38
37
|
|
|
39
38
|
NSDictionary *options = model[@"options"];
|
|
40
39
|
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
|
-
}
|
|
52
40
|
[tabBarController setViewControllers:viewControllers];
|
|
53
41
|
|
|
54
42
|
if (options) {
|
|
@@ -76,17 +64,12 @@
|
|
|
76
64
|
}
|
|
77
65
|
}
|
|
78
66
|
|
|
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
|
-
|
|
84
67
|
return @{
|
|
85
68
|
@"layout": self.name,
|
|
86
69
|
@"sceneId": tabBarController.hbd_sceneId,
|
|
87
70
|
@"children": children,
|
|
88
|
-
@"tabKeys": tabKeys,
|
|
89
71
|
@"mode": [tabBarController hbd_mode],
|
|
72
|
+
@"tabKeys": [tabBarController tabKeys],
|
|
90
73
|
@"selectedIndex": @(tabBarController.selectedIndex)
|
|
91
74
|
};
|
|
92
75
|
}
|
|
@@ -109,22 +92,24 @@
|
|
|
109
92
|
|
|
110
93
|
- (void)handleSwitchTabWithTabBarController:(UITabBarController *)tabBarController extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
|
|
111
94
|
BOOL popToRoot = [extras[@"popToRoot"] boolValue];
|
|
112
|
-
|
|
113
|
-
NSString *
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
return;
|
|
95
|
+
NSNumber *toNumber = extras[@"to"];
|
|
96
|
+
NSString *key = extras[@"tabKey"];
|
|
97
|
+
if ([key isKindOfClass:NSString.class]) {
|
|
98
|
+
NSUInteger index = NSNotFound;
|
|
99
|
+
if ([tabBarController isKindOfClass:HBDTabBarController.class]) {
|
|
100
|
+
index = [[(HBDTabBarController *)tabBarController tabKeys] indexOfObject:key];
|
|
119
101
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (![toNumber isKindOfClass:[NSNumber class]]) {
|
|
123
|
-
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Tab index or tabKey is required for switchTab."));
|
|
102
|
+
if (index == NSNotFound) {
|
|
103
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeSceneNotFound, @"Tab key was not found."));
|
|
124
104
|
return;
|
|
125
105
|
}
|
|
126
|
-
|
|
106
|
+
toNumber = @(index);
|
|
107
|
+
}
|
|
108
|
+
if (![toNumber isKindOfClass:[NSNumber class]]) {
|
|
109
|
+
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"Tab index is required for switchTab."));
|
|
110
|
+
return;
|
|
127
111
|
}
|
|
112
|
+
NSInteger toIndex = [toNumber integerValue];
|
|
128
113
|
if (toIndex < 0 || (NSUInteger)toIndex >= tabBarController.viewControllers.count) {
|
|
129
114
|
completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, [NSString stringWithFormat:@"Tab index out of bounds: %ld", (long)toIndex]));
|
|
130
115
|
return;
|
|
@@ -270,7 +270,8 @@ static HBDDispatchCompletion HBDOnceDispatchResolve(RCTPromiseResolveBlock resol
|
|
|
270
270
|
|
|
271
271
|
- (void)updateTabBar:(nonnull NSString *)sceneId item:(nonnull NSDictionary *)item {
|
|
272
272
|
RCTLogInfo(@"[Navigation] updateTabBar: %@", item);
|
|
273
|
-
|
|
273
|
+
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
274
|
+
UITabBarController *tabBarVC = [self tabBarControllerWithViewController:vc];
|
|
274
275
|
if ([tabBarVC isKindOfClass:[HBDTabBarController class]]) {
|
|
275
276
|
[(HBDTabBarController *)tabBarVC updateTabBar:item];
|
|
276
277
|
}
|
|
@@ -278,41 +279,13 @@ static HBDDispatchCompletion HBDOnceDispatchResolve(RCTPromiseResolveBlock resol
|
|
|
278
279
|
|
|
279
280
|
- (void)setTabItem:(nonnull NSString *)sceneId items:(nonnull NSArray *)items {
|
|
280
281
|
RCTLogInfo(@"[Navigation] setTabItem: %@", items);
|
|
281
|
-
|
|
282
|
+
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
283
|
+
UITabBarController *tabBarVC = [self tabBarControllerWithViewController:vc];
|
|
282
284
|
if ([tabBarVC isKindOfClass:[HBDTabBarController class]]) {
|
|
283
285
|
[(HBDTabBarController *)tabBarVC setTabItem:items];
|
|
284
286
|
}
|
|
285
287
|
}
|
|
286
288
|
|
|
287
|
-
- (nullable UITabBarController *)resolveTabBarControllerForSceneId:(NSString *)sceneId {
|
|
288
|
-
if (sceneId.length > 0) {
|
|
289
|
-
UIViewController *vc = [self.bridgeManager viewControllerBySceneId:sceneId];
|
|
290
|
-
return [self tabBarControllerWithViewController:vc];
|
|
291
|
-
}
|
|
292
|
-
UIViewController *root = [self.bridgeManager mainWindow].rootViewController;
|
|
293
|
-
return [self findTabBarControllerInViewController:root];
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
- (nullable UITabBarController *)findTabBarControllerInViewController:(nullable UIViewController *)vc {
|
|
297
|
-
if (!vc) {
|
|
298
|
-
return nil;
|
|
299
|
-
}
|
|
300
|
-
if ([vc isKindOfClass:[UITabBarController class]]) {
|
|
301
|
-
return (UITabBarController *)vc;
|
|
302
|
-
}
|
|
303
|
-
for (UIViewController *child in vc.childViewControllers) {
|
|
304
|
-
UITabBarController *found = [self findTabBarControllerInViewController:child];
|
|
305
|
-
if (found) {
|
|
306
|
-
return found;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
UIViewController *presented = vc.presentedViewController;
|
|
310
|
-
if (presented && presented != vc && !presented.isBeingDismissed) {
|
|
311
|
-
return [self findTabBarControllerInViewController:presented];
|
|
312
|
-
}
|
|
313
|
-
return nil;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
289
|
- (UITabBarController *)tabBarControllerWithViewController:(UIViewController *)vc {
|
|
317
290
|
if ([vc isKindOfClass:[UITabBarController class]]) {
|
|
318
291
|
return (UITabBarController *)vc;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#import "HBDNavigator.h"
|
|
2
|
-
#import "HBDTabBarRenderer.h"
|
|
3
2
|
#import <ReactCommon/RCTHost.h>
|
|
4
3
|
|
|
5
4
|
NS_ASSUME_NONNULL_BEGIN
|
|
@@ -88,10 +87,6 @@ extern const NSInteger HBDResultBlock;
|
|
|
88
87
|
|
|
89
88
|
- (void)registerNavigator:(id<HBDNavigator>)navigator;
|
|
90
89
|
|
|
91
|
-
- (void)registerTabBarRendererFactory:(HBDTabBarRendererFactory)factory forName:(NSString *)name;
|
|
92
|
-
|
|
93
|
-
- (nullable id<HBDTabBarRenderer>)tabBarRendererWithName:(NSString *)name;
|
|
94
|
-
|
|
95
90
|
- (void)invalidate;
|
|
96
91
|
|
|
97
92
|
@end
|
|
@@ -48,7 +48,6 @@ typedef NS_ENUM(NSInteger, HBDCommandType) {
|
|
|
48
48
|
|
|
49
49
|
@property(nonatomic, strong) NSMutableDictionary *nativeModules;
|
|
50
50
|
@property(nonatomic, strong) NSMutableDictionary *reactModules;
|
|
51
|
-
@property(nonatomic, strong) NSMutableDictionary<NSString *, HBDTabBarRendererFactory> *tabBarRendererFactories;
|
|
52
51
|
@property(nonatomic, assign, readwrite, getter=isReactModuleRegisterCompleted) BOOL reactModuleRegisterCompleted;
|
|
53
52
|
@property(nonatomic, strong) HBDNavigatorRegistry *navigatorRegistry;
|
|
54
53
|
|
|
@@ -81,7 +80,6 @@ typedef NS_ENUM(NSInteger, HBDCommandType) {
|
|
|
81
80
|
if (self = [super init]) {
|
|
82
81
|
_nativeModules = [[NSMutableDictionary alloc] init];
|
|
83
82
|
_reactModules = [[NSMutableDictionary alloc] init];
|
|
84
|
-
_tabBarRendererFactories = [[NSMutableDictionary alloc] init];
|
|
85
83
|
_reactModuleRegisterCompleted = NO;
|
|
86
84
|
_navigatorRegistry = [[HBDNavigatorRegistry alloc] init];
|
|
87
85
|
_globalStyle = [[HBDGlobalStyle alloc] initWithOptions:@{}];
|
|
@@ -741,19 +739,4 @@ typedef NS_ENUM(NSInteger, HBDCommandType) {
|
|
|
741
739
|
[self.navigatorRegistry registerNavigator:navigator];
|
|
742
740
|
}
|
|
743
741
|
|
|
744
|
-
- (void)registerTabBarRendererFactory:(HBDTabBarRendererFactory)factory forName:(NSString *)name {
|
|
745
|
-
if (name.length == 0 || !factory) {
|
|
746
|
-
return;
|
|
747
|
-
}
|
|
748
|
-
self.tabBarRendererFactories[name] = [factory copy];
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
- (nullable id<HBDTabBarRenderer>)tabBarRendererWithName:(NSString *)name {
|
|
752
|
-
if (name.length == 0) {
|
|
753
|
-
return nil;
|
|
754
|
-
}
|
|
755
|
-
HBDTabBarRendererFactory factory = self.tabBarRendererFactories[name];
|
|
756
|
-
return factory ? factory() : nil;
|
|
757
|
-
}
|
|
758
|
-
|
|
759
742
|
@end
|
|
@@ -6,7 +6,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
6
6
|
|
|
7
7
|
- (void)signalFirstRenderComplete;
|
|
8
8
|
|
|
9
|
-
- (BOOL)
|
|
9
|
+
- (BOOL)shouldPrewarmPush;
|
|
10
|
+
|
|
11
|
+
- (BOOL)prepareForAnimatedPushInView:(UIView *)hostView timeout:(NSTimeInterval)timeout completion:(dispatch_block_t)completion;
|
|
10
12
|
|
|
11
13
|
@end
|
|
12
14
|
|