Skip to content

Commit

Permalink
Fix issue with not counting navigation bar inset in transparent modals
Browse files Browse the repository at this point in the history
  • Loading branch information
tboba committed Oct 11, 2023
1 parent 40df2fd commit 3d4bd36
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3d4bd36

Please sign in to comment.