Skip to content

Commit

Permalink
feat(ios): add presentVC and dismissVC methods to bridge (#2678)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Apr 2, 2020
1 parent 63ecd1c commit a6c91da
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
17 changes: 17 additions & 0 deletions ios/Capacitor/Capacitor/CAPBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ enum BridgeError: Error {

@objc public class CAPBridge : NSObject {

let tmpWindow = UIWindow.init(frame: UIScreen.main.bounds)
let tmpVC = TmpViewController.init()
@objc public static let statusBarTappedNotification = Notification(name: Notification.Name(rawValue: "statusBarTappedNotification"))
@objc public static let tmpVCAppeared = Notification(name: Notification.Name(rawValue: "tmpViewControllerAppeared"))
public static var CAP_SITE = "https://capacitor.ionicframework.com/"
public static var CAP_FILE_START = "/_capacitor_file_"
public static let CAP_DEFAULT_SCHEME = "capacitor"
Expand Down Expand Up @@ -63,6 +66,11 @@ enum BridgeError: Error {
registerPlugins()
setupCordovaCompatibility()
bindObservers()
self.tmpWindow.rootViewController = tmpVC
self.tmpWindow.makeKeyAndVisible()
NotificationCenter.default.addObserver(forName: CAPBridge.tmpVCAppeared.name, object: .none, queue: .none) { _ in
self.tmpWindow.isHidden = true
}
}

public func setStatusBarVisible(_ isStatusBarVisible: Bool) {
Expand Down Expand Up @@ -589,5 +597,14 @@ enum BridgeError: Error {
return localUrl!
}

@objc public func presentVC(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {
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)
}

}

4 changes: 2 additions & 2 deletions ios/Capacitor/Capacitor/Plugins/Browser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CAPBrowserPlugin : CAPPlugin, SFSafariViewControllerDelegate {
self.vc!.preferredBarTintColor = UIColor(fromHex: toolbarColor!)
}

self.bridge.viewController.present(self.vc!, animated: true, completion: {
self.bridge.presentVC(self.vc!, animated: true, completion: {
call.success()
})
}
Expand All @@ -48,7 +48,7 @@ public class CAPBrowserPlugin : CAPPlugin, SFSafariViewControllerDelegate {
call.success()
}
DispatchQueue.main.async {
self.bridge.viewController.dismiss(animated: true) {
self.bridge.dismissVC(animated: true) {
call.success()
}
}
Expand Down
8 changes: 8 additions & 0 deletions ios/Capacitor/Capacitor/TmpViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import UIKit

class TmpViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
NotificationCenter.default.post(CAPBridge.tmpVCAppeared)
}
}

0 comments on commit a6c91da

Please sign in to comment.