TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2016 |
SPMSupports SPM | ✗ |
Screen transition with safe and clean code.
With Presenter, you can…
This library is recommended to be used together with Instantiatable.
MyViewController.Presenter(userID: "muukii").push(self.navigationController)
MyViewController.Presenter(userID: "muukii").present(self)
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
}
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) {
}
}
}
Presenter is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Presenter"
muukii, [email protected]
Presenter is available under the MIT license. See the LICENSE file for more info.