From 327ffc545c767c0d1430226ed204ca9d568dcccb Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Tue, 7 Apr 2020 15:54:00 +0200 Subject: [PATCH] fix(ios): don't use the tmpWindow on popover presentation (#2714) --- ios/Capacitor/Capacitor/CAPBridge.swift | 14 +++++++++++--- ios/Capacitor/Capacitor/Plugins/Browser.swift | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ios/Capacitor/Capacitor/CAPBridge.swift b/ios/Capacitor/Capacitor/CAPBridge.swift index 73b93b1c91..8ccb292152 100644 --- a/ios/Capacitor/Capacitor/CAPBridge.swift +++ b/ios/Capacitor/Capacitor/CAPBridge.swift @@ -598,12 +598,20 @@ enum BridgeError: Error { } @objc public func presentVC(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) { - self.tmpWindow.makeKeyAndVisible() - self.tmpVC.present(viewControllerToPresent, animated: flag, completion: completion) + if viewControllerToPresent.modalPresentationStyle == .popover { + self.viewController.present(viewControllerToPresent, animated: flag, completion: completion) + } else { + self.tmpWindow.makeKeyAndVisible() + self.tmpVC.present(viewControllerToPresent, animated: flag, completion: completion) + } } @objc public func dismissVC(animated flag: Bool, completion: (() -> Void)? = nil) { - self.tmpVC.dismiss(animated: flag, completion: completion) + if self.tmpWindow.isHidden { + self.viewController.dismiss(animated: flag, completion: completion) + } else { + self.tmpVC.dismiss(animated: flag, completion: completion) + } } } diff --git a/ios/Capacitor/Capacitor/Plugins/Browser.swift b/ios/Capacitor/Capacitor/Plugins/Browser.swift index a768de6d90..f7be28a675 100644 --- a/ios/Capacitor/Capacitor/Plugins/Browser.swift +++ b/ios/Capacitor/Capacitor/Plugins/Browser.swift @@ -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" { + if presentationStyle != nil && presentationStyle == "popover" && UIDevice.current.userInterfaceIdiom == .pad { self.vc!.modalPresentationStyle = .popover self.setCenteredPopover(self.vc) } else {