hybrid-navigation 5.1.1 → 5.3.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.
Files changed (101) hide show
  1. package/README.md +9 -20
  2. package/android/src/main/java/com/navigation/androidx/AwesomeFragment.java +5 -13
  3. package/android/src/main/java/com/navigation/androidx/DefaultTabBarProvider.java +2 -2
  4. package/android/src/main/java/com/navigation/androidx/TabBarFragment.java +0 -50
  5. package/android/src/main/java/com/navigation/androidx/TabBarItem.java +0 -4
  6. package/android/src/main/java/com/reactnative/hybridnavigation/GlobalStyle.java +0 -7
  7. package/android/src/main/java/com/reactnative/hybridnavigation/HybridFragment.java +7 -43
  8. package/android/src/main/java/com/reactnative/hybridnavigation/NativeNavigation.java +5 -39
  9. package/android/src/main/java/com/reactnative/hybridnavigation/ReactFragment.java +62 -135
  10. package/android/src/main/java/com/reactnative/hybridnavigation/ReactManager.java +0 -20
  11. package/android/src/main/java/com/reactnative/hybridnavigation/ReactTabBarFragment.java +10 -21
  12. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/ScreenNavigator.java +39 -87
  13. package/android/src/main/java/com/reactnative/hybridnavigation/navigator/TabNavigator.java +2 -16
  14. package/dist/NativeEvent.d.ts +1 -11
  15. package/dist/NativeNavigation.d.ts +7 -6
  16. package/dist/Navigation.d.ts +8 -20
  17. package/dist/Navigation.js +32 -163
  18. package/dist/NavigationComponentWrap.d.ts +3 -3
  19. package/dist/Navigator.d.ts +4 -5
  20. package/dist/Navigator.js +13 -36
  21. package/dist/Options.d.ts +2 -2
  22. package/dist/Route.d.ts +12 -33
  23. package/dist/handler/DispatchCommandHandler.d.ts +3 -17
  24. package/dist/handler/DispatchCommandHandler.js +17 -62
  25. package/dist/handler/LayoutCommandHandler.d.ts +2 -3
  26. package/dist/handler/LayoutCommandHandler.js +0 -3
  27. package/dist/handler/LeaveGuardHandler.d.ts +2 -2
  28. package/dist/handler/LeaveGuardHandler.js +88 -46
  29. package/dist/handler/LifecycleEventHandler.d.ts +2 -14
  30. package/dist/handler/LifecycleEventHandler.js +2 -79
  31. package/dist/handler/ResultEventHandler.d.ts +0 -1
  32. package/dist/handler/ResultEventHandler.js +0 -3
  33. package/dist/handler/SceneExitHandler.d.ts +3 -0
  34. package/dist/handler/SceneExitHandler.js +76 -0
  35. package/dist/hooks.d.ts +2 -2
  36. package/dist/hooks.js +39 -22
  37. package/dist/index.d.ts +1 -12
  38. package/dist/index.js +0 -3
  39. package/dist/router/index.d.ts +0 -1
  40. package/dist/router/index.js +43 -11
  41. package/dist/sceneCoverage.d.ts +2 -0
  42. package/dist/sceneCoverage.js +25 -0
  43. package/dist/store.d.ts +0 -2
  44. package/dist/store.js +0 -4
  45. package/ios/HBDGlobalStyle.h +0 -1
  46. package/ios/HBDGlobalStyle.mm +0 -7
  47. package/ios/HybridNavigation.h +0 -1
  48. package/ios/Navigator/HBDScreenNavigator.mm +89 -237
  49. package/ios/Navigator/HBDStackNavigator.mm +1 -1
  50. package/ios/Navigator/HBDTabNavigator.mm +15 -30
  51. package/ios/React/HBDNativeNavigation.mm +4 -31
  52. package/ios/React/HBDReactBridgeManager.h +0 -5
  53. package/ios/React/HBDReactBridgeManager.mm +0 -17
  54. package/ios/ViewController/HBDReactViewController.h +1 -1
  55. package/ios/ViewController/HBDReactViewController.mm +34 -9
  56. package/ios/ViewController/HBDTabBarController.h +2 -11
  57. package/ios/ViewController/HBDTabBarController.mm +14 -170
  58. package/ios/ViewController/HBDViewController.h +0 -1
  59. package/ios/ViewController/HBDViewController.mm +9 -57
  60. package/ios/ViewController/UIViewController+HBD.h +2 -0
  61. package/ios/ViewController/UIViewController+HBD.mm +5 -0
  62. package/package.json +1 -3
  63. package/src/NativeEvent.ts +1 -12
  64. package/src/NativeNavigation.ts +8 -7
  65. package/src/Navigation.ts +49 -257
  66. package/src/NavigationComponentWrap.tsx +3 -11
  67. package/src/Navigator.ts +15 -45
  68. package/src/Options.ts +2 -3
  69. package/src/Route.ts +17 -54
  70. package/src/handler/DispatchCommandHandler.ts +29 -109
  71. package/src/handler/LayoutCommandHandler.ts +2 -6
  72. package/src/handler/LeaveGuardHandler.ts +97 -46
  73. package/src/handler/LifecycleEventHandler.ts +22 -122
  74. package/src/handler/ResultEventHandler.ts +0 -6
  75. package/src/handler/SceneExitHandler.ts +86 -0
  76. package/src/hooks.ts +39 -22
  77. package/src/index.ts +0 -14
  78. package/src/router/index.ts +45 -12
  79. package/src/sceneCoverage.ts +30 -0
  80. package/src/store.ts +0 -5
  81. package/dist/defineRoutes.d.ts +0 -19
  82. package/dist/defineRoutes.js +0 -6
  83. package/dist/handler/PresentationCoordinator.d.ts +0 -24
  84. package/dist/handler/PresentationCoordinator.js +0 -456
  85. package/dist/handler/TabEventHandler.d.ts +0 -8
  86. package/dist/handler/TabEventHandler.js +0 -25
  87. package/dist/reveal.d.ts +0 -46
  88. package/dist/reveal.js +0 -431
  89. package/dist/routeGraph.d.ts +0 -12
  90. package/dist/routeGraph.js +0 -68
  91. package/dist/testing.d.ts +0 -79
  92. package/dist/testing.js +0 -251
  93. package/ios/ViewController/HBDTabBarRenderer.h +0 -28
  94. package/src/defineRoutes.ts +0 -46
  95. package/src/handler/PresentationCoordinator.ts +0 -566
  96. package/src/handler/TabEventHandler.ts +0 -31
  97. package/src/reveal.ts +0 -565
  98. package/src/routeGraph.ts +0 -87
  99. package/src/testing.ts +0 -395
  100. package/testing.d.ts +0 -1
  101. package/testing.js +0 -3
@@ -57,8 +57,10 @@
57
57
  return;
58
58
  }
59
59
 
60
- if ([action isEqualToString:@"dismiss"]) {
61
- [self handleDismissWithViewController:vc extras:extras completion:completion];
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
- - (BOOL)applyPendingResultIfPresentToViewController:(UIViewController *)vc extras:(NSDictionary *)extras {
214
- NSDictionary *pendingResult = [extras[@"result"] isKindOfClass:[NSDictionary class]] ? extras[@"result"] : nil;
215
- if (!pendingResult) {
216
- return NO;
217
- }
218
- id codeObj = pendingResult[@"code"];
219
- if (![codeObj isKindOfClass:[NSNumber class]]) {
220
- return NO;
221
- }
222
- NSInteger resultCode = [codeObj integerValue];
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
- UIViewController *presented = modalHost.presentedViewController;
259
- if (presented != nil) {
260
- completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered by another presented scene."));
261
- return;
262
- }
263
-
264
- UINavigationController *nav = vc.navigationController;
265
- if (nav != nil && nav.viewControllers.count > 1) {
266
- UIViewController *topVC = nav.topViewController;
267
- if (![self viewController:vc hasAncestorOrSelf:topVC]) {
268
- completion(HBDDispatchResultFail(HBDDispatchCodeCovered, @"Target scene is covered by another screen in the stack."));
269
- return;
270
- }
271
- UIViewController *stackRoot = nav.viewControllers.firstObject;
272
- if (![self viewController:vc hasAncestorOrSelf:stackRoot]) {
273
- UIViewController *resultTarget = topVC ?: vc;
274
- [self applyPendingResultIfPresentToViewController:resultTarget extras:extras];
275
- [[HBDReactBridgeManager get] handleNavigationWithViewController:vc action:@"pop" extras:extras completion:completion];
276
- return;
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
- BOOL isModal = modalHost.modalPresentationStyle == UIModalPresentationOverFullScreen;
308
- BOOL animated = !isModal;
309
- if (!isModal && [vc isKindOfClass:[HBDViewController class]]) {
310
- HBDViewController *hbdvc = (HBDViewController *)vc;
311
- animated = hbdvc.animatedTransition;
312
- }
313
-
314
- UIViewController *presenting = modalHost.presentingViewController;
315
- UIViewController *presented = modalHost.presentedViewController;
316
- BOOL hasActivePresented = presented != nil && !presented.isBeingDismissed;
317
- NSString *target = [extras[@"target"] isKindOfClass:[NSString class]] ? extras[@"target"] : nil;
318
-
319
- if ([target isEqualToString:@"self"]) {
320
- if (hasActivePresented) {
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
- } else if ([target isEqualToString:@"presented"]) {
329
- if (!hasActivePresented) {
330
- completion(HBDDispatchResultFail(HBDDispatchCodeInvalidAction, @"No presented scene to dismiss."));
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
- if (!presenting && !modalHost.presentedViewController) {
336
- RCTLogInfo(@"[Navigation] Nothing to dismiss for sceneId: %@", vc.hbd_sceneId);
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 dismissPresented = [target isEqualToString:@"presented"] || (target == nil && hasActivePresented);
342
- if (dismissPresented && [self waitForTransitionIfNeededForViewController:presented retryCount:retryCount retry:^(NSUInteger nextRetryCount) {
343
- [self handleDismissWithViewController:vc extras:extras retryCount:nextRetryCount completion:completion];
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
- UIViewController *dismissedTarget = dismissPresented ? presented : modalHost;
349
- UIViewController *dismissReceiver = dismissPresented ? modalHost : ((presenting.presentedViewController == modalHost) ? presenting : modalHost);
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
- HBDViewController *hbdvc = [[HBDReactBridgeManager get] primaryViewControllerWithViewController:revealed];
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)handleShowModalWithViewController:(UIViewController *)presenting extras:(NSDictionary *)extras completion:(HBDDispatchCompletion)completion {
383
- if ([self waitForDismissalIfNeededForViewController:presenting retry:^{
384
- [self handleShowModalWithViewController:presenting extras:extras completion:completion];
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;
@@ -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 prepareForAnimatedPushWithBounds:nav.view.bounds
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
- 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;
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
- } else {
121
- NSNumber *toNumber = extras[@"to"];
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
- toIndex = [toNumber integerValue];
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
- UITabBarController *tabBarVC = [self resolveTabBarControllerForSceneId:sceneId];
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
- UITabBarController *tabBarVC = [self resolveTabBarControllerForSceneId:sceneId];
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,7 @@ NS_ASSUME_NONNULL_BEGIN
6
6
 
7
7
  - (void)signalFirstRenderComplete;
8
8
 
9
- - (BOOL)prepareForAnimatedPushWithBounds:(CGRect)bounds timeout:(NSTimeInterval)timeout completion:(dispatch_block_t)completion;
9
+ - (BOOL)prepareForAnimatedPushInView:(UIView *)hostView timeout:(NSTimeInterval)timeout completion:(dispatch_block_t)completion;
10
10
 
11
11
  @end
12
12