Skip to content

Commit

Permalink
Enable Multiple Sheet Presentation in React Native (#46333)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #46333

This pull request introduces enhancements to the view controller presentation logic in React Native, allowing for multiple sheets to be presented on top of each other. The current implementation restricts the presentation to a single view at a time, which limits the flexibility needed in complex applications.
The proposed changes modify the presentation behavior to always utilize the top-most view controller for presentations. This adjustment ensures that multiple sheets can be managed more effectively, without disrupting the existing application flow.
Key changes include:
Modification of the presentation logic to reference the top-most view controller.
Utilization of a recursive method to determine the top-most controller.
The changes have been thoroughly tested with both old and new interfaces and have shown to work seamlessly across different scenarios
Changelog: [Internal] Allow multiple sheets to be presented on top of each other

Reviewed By: jessebwr

Differential Revision: D62202475

fbshipit-source-id: daa0cf95edb23ea52a26441337f9a16f5475b211
  • Loading branch information
Mohamed Alsadek authored and facebook-github-bot committed Sep 5, 2024
1 parent 62ee5c9 commit f1031be
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions packages/react-native/React/Views/RCTModalHostViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ - (void)presentModalHostView:(RCTModalHostView *)modalHostView
if (self->_presentationBlock) {
self->_presentationBlock([modalHostView reactViewController], viewController, animated, completionBlock);
} else {
[[modalHostView reactViewController] presentViewController:viewController
animated:animated
completion:completionBlock];
[[self _topMostViewControllerFrom:[modalHostView reactViewController]] presentViewController:viewController
animated:animated
completion:completionBlock];
}
});
}
Expand Down Expand Up @@ -107,6 +107,26 @@ - (void)invalidate
_hostViews = nil;
}

#pragma mark - Private

- (UIViewController *)_topMostViewControllerFrom:(UIViewController *)rootViewController
{
UIViewController *topController = rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
if ([topController isKindOfClass:[UINavigationController class]]) {
UINavigationController *navigationController = (UINavigationController *)topController;
topController = navigationController.visibleViewController;
return [self _topMostViewControllerFrom:topController];
} else if ([topController isKindOfClass:[UITabBarController class]]) {
UITabBarController *tabBarController = (UITabBarController *)topController;
topController = tabBarController.selectedViewController;
return [self _topMostViewControllerFrom:topController];
}
return topController;
}

RCT_EXPORT_VIEW_PROPERTY(animationType, NSString)
RCT_EXPORT_VIEW_PROPERTY(presentationStyle, UIModalPresentationStyle)
RCT_EXPORT_VIEW_PROPERTY(transparent, BOOL)
Expand Down

0 comments on commit f1031be

Please sign in to comment.