diff --git a/ios/RNSScreen.mm b/ios/RNSScreen.mm index e6129badd6..eaa2ef95dc 100644 --- a/ios/RNSScreen.mm +++ b/ios/RNSScreen.mm @@ -563,6 +563,12 @@ - (RNSScreenStackHeaderConfig *_Nullable)findHeaderConfig return nil; } +- (BOOL)hasModalOpened +{ + return self.controller.childViewControllers.count > 0 && + [self.controller.childViewControllers[0] isKindOfClass:UINavigationController.class]; +} + - (BOOL)isModal { return self.stackPresentation != RNSScreenStackPresentationPush; @@ -1046,16 +1052,15 @@ - (BOOL)hasNestedStack - (CGFloat)getNavigationBarHeightIsModal:(BOOL)isModal { - CGFloat navbarHeight = self.navigationController.navigationBar.frame.size.height; + UINavigationController *navctr = self.navigationController; - // In case where screen is a modal, we want to calculate just its childViewController's height - if (isModal && self.childViewControllers.count > 0 && - [self.childViewControllers[0] isKindOfClass:UINavigationController.class]) { - UINavigationController *childNavCtr = self.childViewControllers[0]; - navbarHeight = childNavCtr.navigationBar.frame.size.height; + // In case where screen is a modal, we want to calculate childViewController's + // navigation bar height instead of the navigation controller from RNSScreen. + if (isModal && self.screenView.hasModalOpened) { + navctr = self.childViewControllers[0]; } - return navbarHeight; + return navctr.navigationBar.frame.size.height; } - (CGFloat)getNavigationBarInsetIsModal:(BOOL)isModal @@ -1064,8 +1069,15 @@ - (CGFloat)getNavigationBarInsetIsModal:(BOOL)isModal // On TVOS there's no inset of navigation bar. return 0; #endif // TARGET_OS_TV + UINavigationController *navctr = self.navigationController; + + // In case where screen is a modal, we want to calculate childViewController's + // navigation bar inset instead of the navigation controller from RNSScreen. + if (isModal && self.screenView.hasModalOpened) { + navctr = self.childViewControllers[0]; + } - return self.navigationController.navigationBar.frame.origin.y; + return navctr.navigationBar.frame.origin.y; } - (CGFloat)calculateHeaderHeightIsModal:(BOOL)isModal