Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ios): add presentVC and dismissVC methods to bridge #2678

Merged
merged 2 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}