From 7c463a1e4a8319e2e6bacd7d0db9c5feec2cf0b3 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Wed, 4 Oct 2023 13:53:24 +0200 Subject: [PATCH] Add partial fix allowing for presenting outer-modal from the inner one --- ios/RNSScreen.mm | 1 + ios/RNSScreenStack.mm | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/ios/RNSScreen.mm b/ios/RNSScreen.mm index 99db2b5097..06e81e5c7d 100644 --- a/ios/RNSScreen.mm +++ b/ios/RNSScreen.mm @@ -89,6 +89,7 @@ - (void)initCommonProps #if !TARGET_OS_TV _sheetExpandsWhenScrolledToEdge = YES; #endif // !TARGET_OS_TV + NSLog(@"RNSScreenView alloc at %p with VC at %p", self, _controller); } - (UIViewController *)reactViewController diff --git a/ios/RNSScreenStack.mm b/ios/RNSScreenStack.mm index 61fe072086..e64a7934e0 100644 --- a/ios/RNSScreenStack.mm +++ b/ios/RNSScreenStack.mm @@ -155,6 +155,7 @@ - (void)initCommonProps // the header will render in collapsed state which is perhaps a bug // in UIKit but ¯\_(ツ)_/¯ [_controller setViewControllers:@[ [UIViewController new] ]]; + NSLog(@"RNSScreenStackView alloc at %p with NavVC at %p", self, _controller); } #pragma mark - helper methods @@ -399,7 +400,17 @@ - (void)setModalViewControllers:(NSArray *)controllers afterTransitions(); return; } else { + NSLog(@"visibleViewController %p", self->_controller.visibleViewController); UIViewController *previous = changeRootController; + UIViewController *visibleViewController = self->_controller.visibleViewController; + if ([visibleViewController isKindOfClass:RNSScreen.class]) { + RNSScreen *screen = (RNSScreen *)visibleViewController; + if (screen.screenView.isModal && screen.presentingViewController != weakSelf) { + // We have already presented a modal from different (nested) stack + // So the first view controller to be used as presenting view controller should be the last current modal. + previous = screen; + } + } for (NSUInteger i = changeRootIndex; i < controllers.count; i++) { UIViewController *next = controllers[i]; BOOL lastModal = (i == controllers.count - 1); @@ -424,6 +435,7 @@ - (void)setModalViewControllers:(NSArray *)controllers return; } + NSLog(@"%p is presenting %p modally", previous, next); [previous presentViewController:next animated:shouldAnimate completion:^{