Skip to content

Commit

Permalink
Remove checks for childViewController.count, change assertModalHierar…
Browse files Browse the repository at this point in the history
…chy to isModalWithHeader, move statusBarSize var
  • Loading branch information
tboba committed Oct 17, 2023
1 parent e779764 commit add6ee3
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1038,14 +1038,9 @@ - (void)viewDidLayoutSubviews
}
}

- (BOOL)assertModalHierarchy
- (BOOL)isModalWithHeader
{
if (self.childViewControllers.count > 1) {
RCTLogError(
@"Modal has been rendered with more than one navigation controller, which is not allowed. Ensure that modal has none or only one RNSNavigationController mounted as a child view controller.");
}

return self.childViewControllers.count == 1 &&
return self.screenView.isModal && self.childViewControllers.count == 1 &&
[self.childViewControllers[0] isKindOfClass:UINavigationController.class];
}

Expand Down Expand Up @@ -1093,7 +1088,7 @@ - (UINavigationController *)getVisibleNavigationControllerIsModal:(BOOL)isModal
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) {
if (self.isModalWithHeader) {
navctr = self.childViewControllers[0];
} else {
// If the modal does not meet requirements (there's no RNSNavigationController which means that probably it
Expand All @@ -1109,17 +1104,18 @@ - (UINavigationController *)getVisibleNavigationControllerIsModal:(BOOL)isModal
- (CGFloat)calculateHeaderHeightIsModal:(BOOL)isModal
{
UINavigationController *navctr = [self getVisibleNavigationControllerIsModal:isModal];
CGSize statusBarSize = [self getStatusBarHeightIsModal:isModal];

// If navigation controller doesn't exists (or it is hidden) we want to handle two possible cases.
// If there's no navigation controller for the modal, we simply don't want to return header height, as modal possibly
// does not have header and we don't want to count status bar. If there's no navigation controller for the view we
// just want to return status bar height (if it's hidden, it will simply return 0).
if (navctr == nil || navctr.isNavigationBarHidden) {
if (isModal)
if (isModal) {
return 0;
else
} else {
CGSize statusBarSize = [self getStatusBarHeightIsModal:isModal];
return MIN(statusBarSize.width, statusBarSize.height);
}
}

CGFloat navbarHeight = navctr.navigationBar.frame.size.height;
Expand Down

0 comments on commit add6ee3

Please sign in to comment.