Skip to content

Commit 43dcdaf

Browse files
Morgan Prettyfacebook-github-bot-4
authored andcommitted
ActionSheetIOS support for presentation from modal view controller
Summary: Currently the RCTActionSheetManager attempts to present itself from the 'rootViewController' of the key window, presenting a modal from a view controller which is already presenting a modal is not allowed on iOS and this fails with the following error appearing in the XCode debugger (but not the chrome debugger): ``` Warning: Attempt to present <UIAlertController: 0x7fca85b14f40> on <UINavigationController: 0x7fca84812000> whose view is not in the window hierarchy! ``` This change recursively looks through modally presented view controllers until it finds the top one and then uses that to present the action sheet. Closes facebook#5263 Reviewed By: svcscm Differential Revision: D2823201 Pulled By: nicklockwood fb-gh-sync-id: aad1ad88115563f633fd9aaea8e27d1d155a6c27
1 parent 6623e48 commit 43dcdaf

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Libraries/ActionSheetIOS/RCTActionSheetManager.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ - (CGRect)sourceRectInView:(UIView *)sourceView
6666
NSInteger cancelButtonIndex = options[@"cancelButtonIndex"] ? [RCTConvert NSInteger:options[@"cancelButtonIndex"]] : -1;
6767

6868
UIViewController *controller = RCTKeyWindow().rootViewController;
69+
while (controller.presentedViewController) {
70+
controller = controller.presentedViewController;
71+
}
72+
6973
if (controller == nil) {
7074
RCTLogError(@"Tried to display action sheet but there is no application window. options: %@", options);
7175
return;

0 commit comments

Comments
 (0)