@@ -155,6 +155,7 @@ - (void)initCommonProps
155155 // the header will render in collapsed state which is perhaps a bug
156156 // in UIKit but ¯\_(ツ)_/¯
157157 [_controller setViewControllers: @[ [UIViewController new ] ]];
158+ NSLog (@" RNSScreenStackView alloc at %p with NavVC at %p " , self, _controller);
158159}
159160
160161#pragma mark - helper methods
@@ -399,7 +400,17 @@ - (void)setModalViewControllers:(NSArray<UIViewController *> *)controllers
399400 afterTransitions ();
400401 return ;
401402 } else {
403+ NSLog (@" visibleViewController %p " , self->_controller.visibleViewController);
402404 UIViewController *previous = changeRootController;
405+ UIViewController *visibleViewController = self->_controller .visibleViewController ;
406+ if ([visibleViewController isKindOfClass: RNSScreen.class ]) {
407+ RNSScreen *screen = (RNSScreen *)visibleViewController;
408+ if (screen.screenView .isModal && screen.presentingViewController != weakSelf) {
409+ // We have already presented a modal from different (nested) stack
410+ // So the first view controller to be used as presenting view controller should be the last current modal.
411+ previous = screen;
412+ }
413+ }
403414 for (NSUInteger i = changeRootIndex; i < controllers.count ; i++) {
404415 UIViewController *next = controllers[i];
405416 BOOL lastModal = (i == controllers.count - 1 );
@@ -424,6 +435,7 @@ - (void)setModalViewControllers:(NSArray<UIViewController *> *)controllers
424435 return ;
425436 }
426437
438+ NSLog (@" %p is presenting %p modally" , previous, next);
427439 [previous presentViewController: next
428440 animated: shouldAnimate
429441 completion: ^{
0 commit comments