Fixed display of alerts on top of modal window
Reviewed By: javache Differential Revision: D2616170 fb-gh-sync-id: f72f728008099fff6fc966d7a2ce4c0d27a4fefd
This commit is contained in:
parent
0da2004e88
commit
11df4cb08c
|
@ -66,7 +66,7 @@ RCT_EXPORT_METHOD(showActionSheetWithOptions:(NSDictionary *)options
|
|||
NSInteger destructiveButtonIndex = options[@"destructiveButtonIndex"] ? [RCTConvert NSInteger:options[@"destructiveButtonIndex"]] : -1;
|
||||
NSInteger cancelButtonIndex = options[@"cancelButtonIndex"] ? [RCTConvert NSInteger:options[@"cancelButtonIndex"]] : -1;
|
||||
|
||||
UIViewController *controller = RCTSharedApplication().delegate.window.rootViewController;
|
||||
UIViewController *controller = RCTKeyWindow().rootViewController;
|
||||
if (controller == nil) {
|
||||
RCTLogError(@"Tried to display action sheet but there is no application window. options: %@", options);
|
||||
return;
|
||||
|
@ -166,7 +166,7 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options
|
|||
}
|
||||
|
||||
UIActivityViewController *shareController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
|
||||
UIViewController *controller = RCTSharedApplication().delegate.window.rootViewController;
|
||||
UIViewController *controller = RCTKeyWindow().rootViewController;
|
||||
|
||||
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
|
||||
|
||||
|
@ -212,8 +212,6 @@ RCT_EXPORT_METHOD(showShareActionSheetWithOptions:(NSDictionary *)options
|
|||
} else {
|
||||
RCTLogWarn(@"No callback registered for action sheet: %@", actionSheet.title);
|
||||
}
|
||||
|
||||
[RCTSharedApplication().delegate.window makeKeyWindow];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -60,8 +60,7 @@ RCT_EXPORT_METHOD(openCameraDialog:(NSDictionary *)config
|
|||
return;
|
||||
}
|
||||
|
||||
UIWindow *keyWindow = RCTSharedApplication().keyWindow;
|
||||
UIViewController *rootViewController = keyWindow.rootViewController;
|
||||
UIViewController *rootViewController = RCTKeyWindow().rootViewController;
|
||||
|
||||
UIImagePickerController *imagePicker = [UIImagePickerController new];
|
||||
imagePicker.delegate = self;
|
||||
|
@ -87,8 +86,7 @@ RCT_EXPORT_METHOD(openSelectDialog:(NSDictionary *)config
|
|||
return;
|
||||
}
|
||||
|
||||
UIWindow *keyWindow = RCTSharedApplication().keyWindow;
|
||||
UIViewController *rootViewController = keyWindow.rootViewController;
|
||||
UIViewController *rootViewController = RCTKeyWindow().rootViewController;
|
||||
|
||||
UIImagePickerController *imagePicker = [UIImagePickerController new];
|
||||
imagePicker.delegate = self;
|
||||
|
@ -121,8 +119,7 @@ didFinishPickingMediaWithInfo:(NSDictionary *)info
|
|||
[_pickerCallbacks removeObjectAtIndex:index];
|
||||
[_pickerCancelCallbacks removeObjectAtIndex:index];
|
||||
|
||||
UIWindow *keyWindow = RCTSharedApplication().keyWindow;
|
||||
UIViewController *rootViewController = keyWindow.rootViewController;
|
||||
UIViewController *rootViewController = RCTKeyWindow().rootViewController;
|
||||
[rootViewController dismissViewControllerAnimated:YES completion:nil];
|
||||
|
||||
callback(@[[info[UIImagePickerControllerReferenceURL] absoluteString]]);
|
||||
|
@ -137,8 +134,7 @@ didFinishPickingMediaWithInfo:(NSDictionary *)info
|
|||
[_pickerCallbacks removeObjectAtIndex:index];
|
||||
[_pickerCancelCallbacks removeObjectAtIndex:index];
|
||||
|
||||
UIWindow *keyWindow = RCTSharedApplication().keyWindow;
|
||||
UIViewController *rootViewController = keyWindow.rootViewController;
|
||||
UIViewController *rootViewController = RCTKeyWindow().rootViewController;
|
||||
[rootViewController dismissViewControllerAnimated:YES completion:nil];
|
||||
|
||||
callback(@[]);
|
||||
|
|
|
@ -58,6 +58,10 @@ RCT_EXTERN BOOL RCTRunningInAppExtension(void);
|
|||
// Returns the shared UIApplication instance, or nil if running in an App Extension
|
||||
RCT_EXTERN UIApplication *RCTSharedApplication(void);
|
||||
|
||||
// Returns the current main window, useful if you need to access the root view
|
||||
// or view controller, e.g. to present a modal view controller or alert.
|
||||
RCT_EXTERN UIWindow *RCTKeyWindow(void);
|
||||
|
||||
// Return a UIAlertView initialized with the given values
|
||||
// or nil if running in an app extension
|
||||
RCT_EXTERN UIAlertView *RCTAlertView(NSString *title,
|
||||
|
|
|
@ -342,16 +342,25 @@ BOOL RCTRunningInAppExtension(void)
|
|||
return [[[[NSBundle mainBundle] bundlePath] pathExtension] isEqualToString:@"appex"];
|
||||
}
|
||||
|
||||
id RCTSharedApplication(void)
|
||||
UIApplication *RCTSharedApplication(void)
|
||||
{
|
||||
if (RCTRunningInAppExtension()) {
|
||||
return nil;
|
||||
}
|
||||
return [[UIApplication class] performSelector:@selector(sharedApplication)];
|
||||
}
|
||||
|
||||
UIWindow *RCTKeyWindow(void)
|
||||
{
|
||||
if (RCTRunningInAppExtension()) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
return [[UIApplication class] performSelector:@selector(sharedApplication)];
|
||||
// TODO: replace with a more robust solution
|
||||
return RCTSharedApplication().keyWindow;
|
||||
}
|
||||
|
||||
id RCTAlertView(NSString *title,
|
||||
UIAlertView *RCTAlertView(NSString *title,
|
||||
NSString *message,
|
||||
id delegate,
|
||||
NSString *cancelButtonTitle,
|
||||
|
|
|
@ -89,7 +89,7 @@ RCT_EXPORT_METHOD(alertWithArgs:(NSDictionary *)args
|
|||
return;
|
||||
}
|
||||
|
||||
UIViewController *presentingController = RCTSharedApplication().delegate.window.rootViewController;
|
||||
UIViewController *presentingController = RCTKeyWindow().rootViewController;
|
||||
if (presentingController == nil) {
|
||||
RCTLogError(@"Tried to display alert view but there is no application window. args: %@", args);
|
||||
return;
|
||||
|
|
|
@ -454,7 +454,7 @@ RCT_EXPORT_METHOD(show)
|
|||
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1;
|
||||
|
||||
actionSheet.actionSheetStyle = UIBarStyleBlack;
|
||||
[actionSheet showInView:RCTSharedApplication().keyWindow.rootViewController.view];
|
||||
[actionSheet showInView:RCTKeyWindow().rootViewController.view];
|
||||
_actionSheet = actionSheet;
|
||||
_presentedItems = items;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue