2 // UIViewController+Ext.swift
5 // Created by Pawel Dabrowski on 30/05/2018.
6 // Copyright © 2018 Fundacja Nowoczesna Polska. All rights reserved.
13 extension UIViewController
15 var syncManager:SyncManager{
16 return appDelegate.syncManager
20 extension UINavigationController{
21 open override var preferredStatusBarStyle : UIStatusBarStyle {
26 extension UIViewController{
29 static func createViewControllerFromStoryboard(storyboardName:String = "Login") -> UIViewController {
31 let viewController:UIViewController = UIStoryboard(name:storyboardName, bundle: nil).instantiateViewController(withIdentifier: String(describing: self)) as UIViewController
35 class func instance() -> Self
37 return instantiateFromStoryboardHelper()
40 private class func instantiateFromStoryboardHelper<T>() -> T
42 let storyboard = UIStoryboard(name: "Main", bundle: nil)
43 let controller = storyboard.instantiateViewController(withIdentifier: "\(self)") as! T
48 extension UIViewController{
50 func presentAlertViewController(title:String,message:String, okAction:UIAlertAction?)
52 let alertController = UIAlertController(title:title, message:message, preferredStyle: .alert)
54 var cancelTitle = "button_cancel".localized
56 cancelTitle = "button_ok".localized
59 let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel, handler: nil)
60 alertController.addAction(cancelAction)
64 alertController.addAction(okAction!)
66 self.present(alertController, animated: true, completion:nil)
69 func presentProblemOccuredAlert(message: String){
70 presentAlertViewController(title: "problem_occurred".localized, message: message, okAction: nil)
73 func presentToast(message: String) {
74 view.makeToast(message, duration: 3.0, position: .bottom)
77 func share(string: String, button: UIButton) {
79 let activity = UIActivityViewController(activityItems: items, applicationActivities: nil)
82 if let actv = activity.popoverPresentationController {
83 actv.sourceView = button
86 self.present(activity, animated: true, completion: nil)
89 func onBecomeFriendButtonTapped(){
90 guard Constants.donateEnabled else { return }
92 if syncManager.isLoggedIn() {
93 appDelegate.mainNavigator.presentPayPalForm()
96 appDelegate.mainNavigator.presentLogin(push: true)
101 extension UIViewController{
103 providesPresentationContextTransitionStyle = true
104 definesPresentationContext = true
105 modalPresentationStyle = .overCurrentContext
106 modalTransitionStyle = .crossDissolve
110 extension UIViewController{
112 func containerAdd(childViewController: UIViewController, toView: UIView){
114 addChildViewController(childViewController)
115 childViewController.view.frame = toView.bounds
116 toView.addSubview(childViewController.view)
117 childViewController.view.translatesAutoresizingMaskIntoConstraints = false
118 childViewController.view.topAnchor.constraint(equalTo: toView.topAnchor).isActive = true
119 childViewController.view.leftAnchor.constraint(equalTo: toView.leftAnchor).isActive = true
120 childViewController.view.rightAnchor.constraint(equalTo: toView.rightAnchor).isActive = true
121 childViewController.view.bottomAnchor.constraint(equalTo: toView.bottomAnchor).isActive = true
122 childViewController.didMove(toParentViewController: self)
125 func containerRemove(childViewController: UIViewController){
127 childViewController.willMove(toParentViewController: nil)
128 childViewController.view.removeFromSuperview()
129 childViewController.removeFromParentViewController()