Skip to content

Commit

Permalink
Add additional checks for calculating header height
Browse files Browse the repository at this point in the history
  • Loading branch information
tboba committed Oct 13, 2023
1 parent 9c0a332 commit e910699
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1058,40 +1058,42 @@ - (BOOL)hasNestedStack
return NO;
}

- (CGFloat)getNavigationBarHeightIsModal:(BOOL)isModal
- (UINavigationController *)getVisibleNavigationControllerIsModal:(BOOL)isModal
{
UINavigationController *navctr = self.navigationController;

// 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.assertModalHierarchy) {
navctr = self.childViewControllers[0];
if (isModal) {
// In case where screen is a modal, we want to calculate childViewController's
// navigation bar height instead of the navigation controller from RNSScreen.
if (self.assertModalHierarchy) {
navctr = self.childViewControllers[0];
} else {
// If the modal does not meet requirements (there's no RNSNavigationController which means that probably it
// doesn't have header or there are more than one RNSNavigationController which is invalid) we don't want to
// return anything.
return nil;
}
}

return navctr.navigationBar.frame.size.height;
return navctr;
}

- (CGFloat)getNavigationBarInsetIsModal:(BOOL)isModal
- (CGFloat)calculateHeaderHeightIsModal:(BOOL)isModal
{
#if TARGET_OS_TV
// On TVOS there's no inset of navigation bar.
return 0;
#endif // TARGET_OS_TV
UINavigationController *navctr = self.navigationController;
UINavigationController *navctr = [self getVisibleNavigationControllerIsModal:isModal];

// 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.assertModalHierarchy) {
navctr = self.childViewControllers[0];
if (navctr == nil || navctr.navigationBarHidden) {
return 0;
}

return navctr.navigationBar.frame.origin.y;
}
CGFloat navbarHeight = navctr.navigationBar.frame.size.height;
#if !TARGET_OS_TV
CGFloat navbarInset = navctr.navigationBar.frame.origin.y;
#else
// On TVOS there's no inset of navigation bar.
CGFloat navbarInset = 0;
#endif // !TARGET_OS_TV

- (CGFloat)calculateHeaderHeightIsModal:(BOOL)isModal
{
CGFloat navbarHeight = [self getNavigationBarHeightIsModal:isModal];
CGFloat navbarInset = [self getNavigationBarInsetIsModal:isModal];
return navbarHeight + navbarInset;
}

Expand Down

0 comments on commit e910699

Please sign in to comment.