From 43dcdaffe2caa8a6a8a38932a3e97ccb172bbc13 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Tue, 12 Jan 2016 03:13:21 -0800 Subject: [PATCH] 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 on 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 https://github.com/facebook/react-native/pull/5263 Reviewed By: svcscm Differential Revision: D2823201 Pulled By: nicklockwood fb-gh-sync-id: aad1ad88115563f633fd9aaea8e27d1d155a6c27 --- Libraries/ActionSheetIOS/RCTActionSheetManager.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Libraries/ActionSheetIOS/RCTActionSheetManager.m b/Libraries/ActionSheetIOS/RCTActionSheetManager.m index 6d568a0a4..ab1a8c8d0 100644 --- a/Libraries/ActionSheetIOS/RCTActionSheetManager.m +++ b/Libraries/ActionSheetIOS/RCTActionSheetManager.m @@ -66,6 +66,10 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions:(NSDictionary *)options NSInteger cancelButtonIndex = options[@"cancelButtonIndex"] ? [RCTConvert NSInteger:options[@"cancelButtonIndex"]] : -1; UIViewController *controller = RCTKeyWindow().rootViewController; + while (controller.presentedViewController) { + controller = controller.presentedViewController; + } + if (controller == nil) { RCTLogError(@"Tried to display action sheet but there is no application window. options: %@", options); return;