Skip to content
Snippets Groups Projects
FadePresenter.swift 994 B
Newer Older
Bruno Muniz's avatar
Bruno Muniz committed
import UIKit

public final class FadePresenter: NSObject, Presenting {
    private var transition: FadeTransition?

    public func present(_ target: UIViewController, from parent: UIViewController) {
        target.modalPresentationStyle = .overFullScreen
        target.transitioningDelegate = self

        parent.present(target, animated: true)
    }
}

extension FadePresenter: UIViewControllerTransitioningDelegate {
    public func animationController(forPresented presented: UIViewController,
                                    presenting: UIViewController,
                                    source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        transition = FadeTransition(didDismiss: { [weak self] in self?.transition = nil })
        return transition
    }

    public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        transition?.direction = .dismiss
        return transition
    }
}