Skip to content

Commit

Permalink
Change hasModalOpened to assertModalHierarchy, add assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
tboba committed Oct 12, 2023
1 parent 4f45e5f commit 9c0a332
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,6 @@ - (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 @@ -1037,6 +1031,20 @@ - (void)viewDidLayoutSubviews
}
}

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

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

// Checks whether this screen has any child view controllers of type RNSNavigationController.
// Useful for checking if this screen has nested stack or is displayed at the top.
- (BOOL)hasNestedStack
Expand All @@ -1056,7 +1064,7 @@ - (CGFloat)getNavigationBarHeightIsModal:(BOOL)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 (isModal && self.screenView.hasModalOpened) {
if (isModal && self.assertModalHierarchy) {
navctr = self.childViewControllers[0];
}

Expand All @@ -1073,7 +1081,7 @@ - (CGFloat)getNavigationBarInsetIsModal:(BOOL)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.screenView.hasModalOpened) {
if (isModal && self.assertModalHierarchy) {
navctr = self.childViewControllers[0];
}

Expand Down

0 comments on commit 9c0a332

Please sign in to comment.