TransitionPresenterManager.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // Created by Jake Lin on 2/29/16.
  3. // Copyright © 2016 IBAnimatable. All rights reserved.
  4. //
  5. import Foundation
  6. /**
  7. TransitionPresenter Manager: Used to cache the Presenters for Present and Dismiss transitions
  8. */
  9. public class TransitionPresenterManager {
  10. // MARK: - Singleton
  11. public static let shared = TransitionPresenterManager()
  12. private init() {}
  13. // MARK: - Private
  14. private var cache = [TransitionAnimationType: TransitionPresenter]()
  15. // MARK: Internal Interface
  16. public func retrievePresenter(transitionAnimationType: TransitionAnimationType,
  17. transitionDuration: Duration = defaultTransitionDuration,
  18. interactiveGestureType: InteractiveGestureType? = nil) -> TransitionPresenter {
  19. // Get the cached presenter
  20. let presenter = cache[transitionAnimationType]
  21. if let presenter = presenter {
  22. // Update the `transitionDuration` and `interactiveGestureType` every time to reuse the same presenter with the same type
  23. presenter.transitionDuration = transitionDuration
  24. presenter.interactiveGestureType = interactiveGestureType
  25. return presenter
  26. }
  27. // Create a new if cache doesn't exist
  28. let newPresenter = TransitionPresenter(transitionAnimationType: transitionAnimationType,
  29. transitionDuration: transitionDuration,
  30. interactiveGestureType: interactiveGestureType)
  31. cache[transitionAnimationType] = newPresenter
  32. return newPresenter
  33. }
  34. }