mirror of
https://github.com/tappollo/react-native-safari-view.git
synced 2026-04-28 20:05:05 +08:00
If the SafariView is triggered while the keyboard is active, the following exception is thrown:
`[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.`
This is similar to https://github.com/facebook/react-native/pull/4231, which was resolved by 6dd171b8c2.
This pull request forces the SafariViewManager to run on the main thread. See https://facebook.github.io/react-native/docs/native-modules-ios.html#threading for more details.
56 lines
1.6 KiB
Objective-C
56 lines
1.6 KiB
Objective-C
#import "SafariViewManager.h"
|
|
#import "RCTUtils.h"
|
|
#import "RCTLog.h"
|
|
#import "RCTEventDispatcher.h"
|
|
|
|
@implementation SafariViewManager
|
|
@synthesize bridge = _bridge;
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
- (dispatch_queue_t)methodQueue
|
|
{
|
|
return dispatch_get_main_queue();
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(show:(NSDictionary *)args callback:(RCTResponseSenderBlock)callback)
|
|
{
|
|
|
|
// Error if no url is passed
|
|
if (!args[@"url"]) {
|
|
RCTLogError(@"[SafariView] You must specify a url.");
|
|
return;
|
|
}
|
|
|
|
// Initialize the Safari View
|
|
SFSafariViewController *safariView = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:args[@"url"]] entersReaderIfAvailable:args[@"readerMode"]];
|
|
safariView.delegate = self;
|
|
|
|
// Display the Safari View
|
|
UIViewController *ctrl = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
|
|
[ctrl presentViewController:safariView animated:YES completion:nil];
|
|
|
|
[self.bridge.eventDispatcher sendAppEventWithName:@"SafariViewOnShow" body:nil];
|
|
}
|
|
|
|
RCT_EXPORT_METHOD(isAvailable:(RCTResponseSenderBlock)callback)
|
|
{
|
|
if ([SFSafariViewController class]) {
|
|
// SafariView is available
|
|
return callback(@[[NSNull null], @true]);
|
|
} else {
|
|
return callback(@[RCTMakeError(@"[SafariView] SafariView is unavailable.", nil, nil)]);
|
|
}
|
|
}
|
|
|
|
|
|
-(void)safariViewControllerDidFinish:(nonnull SFSafariViewController *)controller
|
|
{
|
|
[controller dismissViewControllerAnimated:true completion:nil];
|
|
NSLog(@"[SafariView] SafariView dismissed.");
|
|
|
|
[self.bridge.eventDispatcher sendAppEventWithName:@"SafariViewOnDismiss" body:nil];
|
|
}
|
|
|
|
@end
|