diff --git a/ios/RNSScreenStack.mm b/ios/RNSScreenStack.mm index 8cc10f7881..db0e31fd11 100644 --- a/ios/RNSScreenStack.mm +++ b/ios/RNSScreenStack.mm @@ -686,9 +686,7 @@ - (void)dismissOnReload #ifdef RCT_NEW_ARCH_ENABLED #else dispatch_async(dispatch_get_main_queue(), ^{ - [self dismissAllPresentedViewControllersFrom:self->_controller completion:^{ - [self invalidate]; - }]; + [self invalidate]; }); #endif // RCT_NEW_ARCH_ENABLED } @@ -1195,16 +1193,18 @@ - (void)prepareForRecycle - (void)invalidate { _invalidated = YES; - [_presentedModals removeAllObjects]; - [_controller willMoveToParentViewController:nil]; - [_controller removeFromParentViewController]; + [self dismissAllPresentedViewControllersFrom:_controller completion:^{ + // Ensure presented modals are removed and the controller is detached from its parent + [self->_presentedModals removeAllObjects]; + [self->_controller willMoveToParentViewController:nil]; + [self->_controller removeFromParentViewController]; + }]; } - (void)dismissAllPresentedViewControllersFrom:(UIViewController *)viewController completion:(void (^)(void))completion { if (viewController.presentedViewController) { [viewController.presentedViewController dismissViewControllerAnimated:NO completion:^{ [self dismissAllPresentedViewControllersFrom:viewController completion:completion]; - [self invalidate]; }]; } else { completion();