Skip to content

Commit

Permalink
fix(ios): allow Browser popover presentation if supported (#2784)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Apr 16, 2020
1 parent 4b8820d commit 4b40494
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions ios/Capacitor/Capacitor/CAPPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@
-(NSString *) getString:(CAPPluginCall *)call field:(NSString *)field defaultValue:(NSString *)defaultValue;
-(id)getConfigValue:(NSString *) key;
-(void)setCenteredPopover:(UIViewController *) vc;
-(BOOL)supportsPopover;

@end
8 changes: 8 additions & 0 deletions ios/Capacitor/Capacitor/CAPPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,13 @@ -(void)setCenteredPopover:(UIViewController *) vc {
vc.popoverPresentationController.permittedArrowDirections = 0;
}

-(BOOL)supportsPopover {
if (@available(iOS 13, *)) {
return YES;
} else {
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
}
}

@end

2 changes: 1 addition & 1 deletion ios/Capacitor/Capacitor/Plugins/Browser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CAPBrowserPlugin : CAPPlugin, SFSafariViewControllerDelegate {
self.vc = SFSafariViewController.init(url: url!)
self.vc!.delegate = self
let presentationStyle = call.getString("presentationStyle")
if presentationStyle != nil && presentationStyle == "popover" && UIDevice.current.userInterfaceIdiom == .pad {
if presentationStyle != nil && presentationStyle == "popover" && self.supportsPopover() {
self.vc!.modalPresentationStyle = .popover
self.setCenteredPopover(self.vc)
} else {
Expand Down

0 comments on commit 4b40494

Please sign in to comment.