Latest 1.0.0
Homepage https://github.com/muukii/Presenter
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform
Carthage compatible

Screen transition with safe and clean code.

With Presenter, you can…

  • Assure that the ViewController’s requirements are met, such as a ViewModel to be injected.
  • Constrain transition types (push or present modal or both)

This library is recommended to be used together with Instantiatable.

Usage

Clean Screen Transition

MyViewController.Presenter(userID: "muukii").push(self.navigationController)
MyViewController.Presenter(userID: "muukii").present(self)

Advanced

MyViewController.Presenter(userID: "muukii").push(self.navigationController) { (transaction: PushTransaction<MyViewController> in

    // Pop    
    transaction.pop()

    // Get
    transaction.viewController
}

MyViewController.Presenter(userID: "muukii").present(self) { (transaction: ModalTransaction<MyViewController>) in

    // Pop    
    transaction.dismiss()

    // Get
    transaction.viewController
}

Create Presenter

Push

extension MyViewController {

    final class Presenter: PushPresenter {

        let userID: String

        init(userID: String) {
            self.userID = userID
        }

        func createViewController() -> MyViewController {
            let controller = MessagesViewController() // Init from Stroyboard or XIB
            controller.userID = userID
            return controller
        }  

        // Optional:

        public func willPush(viewController: MyViewController) {

        }

        public func didPush(viewController: MyViewController) {

        }
    }
}

Present

extension MyViewController {

    final class Presenter: ModalPresenter {

        let userID: String

        init(userID: String) {
            self.userID = userID
        }

        func parentController(viewController: UIViewController) -> UIViewController? {
            return UINavigationController(rootViewController: viewController)
        }

        func createViewController() -> MyViewController {
            let controller = MessagesViewController() // Init from Stroyboard or XIB
            controller.userID = userID
            return controller
        }   

        // Optional

        public func willPresent(viewController: MyViewController) {

        }

        public func didPresent(viewController: MyViewController) {

        }
    }
}

Present or Push

extension MyViewController {

    final class Presenter: PushPresenter, ModalPresenter {

        let userID: String

        init(userID: String) {
            self.userID = userID
        }

        func parentController(viewController: UIViewController) -> UIViewController? {
            // Call Present() only
            return UINavigationController(rootViewController: viewController)
        }

        func createViewController() -> MyViewController {
            let controller = MessagesViewController() // Init from Stroyboard or XIB
            controller.userID = userID
            return controller
        }    

        // Optional

        public func willPresent(viewController: MyViewController) {

        }

        public func didPresent(viewController: MyViewController) {

        }

        public func willPush(viewController: MyViewController) {

        }

        public func didPush(viewController: MyViewController) {

        }
    }
}

Requirements

Installation

Presenter is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "Presenter"

Author

muukii, [email protected]

License

Presenter is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Presenter",
    "version": "1.0.0",
    "summary": "Presenter protect ViewController",
    "description": "Presenter protect ViewController.n[Push, Present, Pop, Dismiss]",
    "homepage": "https://github.com/muukii/Presenter",
    "license": "MIT",
    "authors": {
        "muukii": "[email protected]"
    },
    "source": {
        "git": "https://github.com/muukii/Presenter.git",
        "tag": "1.0.0"
    },
    "social_media_url": "https://twitter.com/muukii0803",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Presenter/Classes/**/*"
}

Pin It on Pinterest

Share This