hybrid-navigation 5.1.0 → 5.1.1

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.
@@ -398,7 +398,14 @@ export default class PresentationCoordinator {
398
398
  };
399
399
  }
400
400
  }
401
- const result = await next(sceneId, action, entry.nativeParams);
401
+ let result;
402
+ try {
403
+ result = await next(sceneId, action, entry.nativeParams);
404
+ }
405
+ catch (error) {
406
+ registration?.onRestore?.('invalid_action');
407
+ throw error;
408
+ }
402
409
  if (result.ok) {
403
410
  this.presentingOwnerByChild.delete(sceneId);
404
411
  return result;
@@ -109,6 +109,38 @@
109
109
  return vc.hbd_sceneId;
110
110
  }
111
111
 
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
+
112
144
  - (BOOL)waitForDismissalIfNeededForViewController:(UIViewController *)presenting retry:(dispatch_block_t)retry {
113
145
  UIViewController *presented = presenting.presentedViewController;
114
146
  if (!presented || !presented.isBeingDismissed) {
@@ -178,19 +210,20 @@
178
210
  return host;
179
211
  }
180
212
 
181
- - (void)applyPendingResultIfPresentToViewController:(UIViewController *)vc extras:(NSDictionary *)extras {
213
+ - (BOOL)applyPendingResultIfPresentToViewController:(UIViewController *)vc extras:(NSDictionary *)extras {
182
214
  NSDictionary *pendingResult = [extras[@"result"] isKindOfClass:[NSDictionary class]] ? extras[@"result"] : nil;
183
215
  if (!pendingResult) {
184
- return;
216
+ return NO;
185
217
  }
186
218
  id codeObj = pendingResult[@"code"];
187
219
  if (![codeObj isKindOfClass:[NSNumber class]]) {
188
- return;
220
+ return NO;
189
221
  }
190
222
  NSInteger resultCode = [codeObj integerValue];
191
223
  id rawData = pendingResult[@"data"];
192
224
  NSDictionary *resultData = [rawData isKindOfClass:[NSDictionary class]] ? rawData : nil;
193
225
  [vc hbd_setResultCode:resultCode resultData:resultData];
226
+ return YES;
194
227
  }
195
228
 
196
229
  - (BOOL)viewController:(UIViewController *)viewController hasAncestorOrSelf:(nullable UIViewController *)ancestor {
@@ -206,9 +239,18 @@
206
239
  }
207
240
 
208
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 {
209
246
  UIViewController *modalHost = [self modalHostViewControllerForViewController:vc];
210
247
  if ([self waitForDismissalIfNeededForViewController:modalHost retry:^{
211
- [self handleCloseWithViewController:vc extras:extras completion:completion];
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];
212
254
  }]) {
213
255
  return;
214
256
  }
@@ -246,12 +288,22 @@
246
288
  }
247
289
 
248
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 {
249
295
  UIViewController *modalHost = [self modalHostViewControllerForViewController:vc];
250
296
  if ([self waitForDismissalIfNeededForViewController:modalHost retry:^{
251
- [self handleDismissWithViewController:vc extras:extras completion:completion];
297
+ [self handleDismissWithViewController:vc extras:extras retryCount:0 completion:completion];
252
298
  }]) {
253
299
  return;
254
300
  }
301
+ if ([self waitForTransitionIfNeededForViewController:modalHost retryCount:retryCount retry:^(NSUInteger nextRetryCount) {
302
+ [self handleDismissWithViewController:vc extras:extras retryCount:nextRetryCount completion:completion];
303
+ }]) {
304
+ return;
305
+ }
306
+
255
307
  BOOL isModal = modalHost.modalPresentationStyle == UIModalPresentationOverFullScreen;
256
308
  BOOL animated = !isModal;
257
309
  if (!isModal && [vc isKindOfClass:[HBDViewController class]]) {
@@ -286,16 +338,37 @@
286
338
  return;
287
339
  }
288
340
 
289
- UIViewController *dismissReceiver = [target isEqualToString:@"presented"] ? presented : modalHost;
290
- UIViewController *revealed = [target isEqualToString:@"presented"] ? modalHost : presenting;
291
- BOOL receiverIsModal = dismissReceiver.modalPresentationStyle == UIModalPresentationOverFullScreen;
292
- BOOL dismissAnimated = [target isEqualToString:@"presented"] ? !receiverIsModal : animated;
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;
346
+ }
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;
293
352
 
294
- if (![target isEqualToString:@"presented"] && !hasActivePresented) {
295
- [self applyPendingResultIfPresentToViewController:vc extras:extras];
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];
296
358
  }
297
359
 
360
+ __weak UIViewController *weakDismissedTarget = dismissedTarget;
298
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."));
370
+ return;
371
+ }
299
372
  if (revealed != nil) {
300
373
  HBDViewController *hbdvc = [[HBDReactBridgeManager get] primaryViewControllerWithViewController:revealed];
301
374
  if (hbdvc != nil) {
@@ -79,6 +79,10 @@ static BOOL HBDIsManagedViewController(UIViewController * _Nullable vc) {
79
79
  completion();
80
80
  }
81
81
 
82
+ if (presented.presentingViewController != nil) {
83
+ return;
84
+ }
85
+
82
86
  BOOL consumed = presented.hbd_presentingSceneId.length > 0 &&
83
87
  [UIViewController hbd_dispatchResult:presenting presented:presented sceneId:presented.hbd_presentingSceneId];
84
88
  if (!consumed) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hybrid-navigation",
3
3
  "description": "React Native Navigation that supports seamless navigation between Native and React.",
4
- "version": "5.1.0",
4
+ "version": "5.1.1",
5
5
  "main": "./dist/index",
6
6
  "module": "./dist/index",
7
7
  "types": "./dist/index.d.ts",
@@ -501,7 +501,13 @@ export default class PresentationCoordinator {
501
501
  }
502
502
  }
503
503
 
504
- const result = await next(sceneId, action, entry.nativeParams);
504
+ let result: DispatchResult;
505
+ try {
506
+ result = await next(sceneId, action, entry.nativeParams);
507
+ } catch (error) {
508
+ registration?.onRestore?.('invalid_action');
509
+ throw error;
510
+ }
505
511
  if (result.ok) {
506
512
  this.presentingOwnerByChild.delete(sceneId);
507
513
  return result;