Skip to content

Commit

Permalink
Revise ModalPresenter
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Oct 24, 2016
1 parent f50b3f5 commit 63ff773
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Demo/ToViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ToViewController: UIViewController {

class Presenter: ModalPresenter {

func parentController(_ viewController: ToViewController) -> UIViewController? {
func parentController(viewController: ToViewController) -> UIViewController? {
return nil
}

Expand Down
18 changes: 9 additions & 9 deletions Presenter/ModalPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,37 @@ import UIKit

public protocol ModalPresenter: PresenterType {

func parentController(_ viewController: ViewController) -> UIViewController?
func willPresent(_ viewController: ViewController)
func didPresent(_ viewController: ViewController)
func parentController(viewController: ViewController) -> UIViewController?
func willPresent(presentedViewController: ViewController, presentingViewController: UIViewController)
func didPresent(presentedViewController: ViewController, presentingViewController: UIViewController)
}

extension ModalPresenter {

public func willPresent(_ viewController: ViewController) {
public func willPresent(presentedViewController: ViewController, presentingViewController: UIViewController) {

}

public func didPresent(_ viewController: ViewController) {
public func didPresent(presentedViewController: ViewController, presentingViewController: UIViewController) {

}

@discardableResult
public func present(on presentingViewController: UIViewController, animated: Bool, willPresentTweak: (ModalTransaction<ViewController>) -> Void = { _ in }) -> ModalTransaction<ViewController> {

let controller = createViewController()
willPresent(controller)
willPresent(presentedViewController: controller, presentingViewController: presentingViewController)

let transaction = ModalTransaction(viewController: controller)
willPresentTweak(transaction)

controller.presentOperation = .modal

let presentController = parentController(controller) ?? controller
let presentController = parentController(viewController: controller) ?? controller

presentingViewController.present(presentController, animated: animated, completion: {

self.didPresent(controller)
self.didPresent(presentedViewController: controller, presentingViewController: presentingViewController)
})

return transaction
Expand All @@ -74,7 +74,7 @@ public struct AnyModalPresenter<V: ModalPresenter>: ModalPresenter {
parentControllerClosure = source.parentController
}

public func parentController(_ viewController: ViewController) -> UIViewController? {
public func parentController(viewController: ViewController) -> UIViewController? {
return parentControllerClosure(viewController)
}

Expand Down

0 comments on commit 63ff773

Please sign in to comment.