1 //  Copyright (c) 2018, Applidium. All rights reserved
2 //  OverlayTransitioningDelegate.swift
3 //  OverlayContainer
4 //
5 //  Created by Gaétan Zanella on 14/11/2018.
6 //
7 
8 import UIKit
9 
10 /// A protocol that provides contextual information on the current overlay translation.
11 ///
12 /// Do not adopt this protocol in your own classes, use the one provided in `OverlayTranslationTargetNotchPolicy`.
13 public protocol OverlayContainerContextTargetNotchPolicy: OverlayContainerTransitionContext {
14     /// The manipulated child view controller.
15     var overlayViewController: UIViewController { get }
16 }
17 
18 /// A protocol that provides contextual information on the current overlay translation.
19 ///
20 /// Do not adopt this protocol in your own classes, use the one provided in `OverlayAnimatedTransitioning`.
21 public protocol OverlayContainerContextTransitioning: OverlayContainerTransitionContext {
22     /// The manipulated child view controller.
23     var overlayViewController: UIViewController { get }
24     /// The expected notch index once the animations ended.
25     var targetNotchIndex: Int { get }
26     /// The expected translation height once the animation ended.
27     var targetNotchHeight: CGFloat { get }
28 }
29 
30 /// A protocol that manages the container behavior once the user finishes dragging.
31 ///
32 /// Adopt this protocol to provide your own translation behavior.
33 public protocol OverlayTransitioningDelegate: AnyObject {
34     /// Returns the target notch policy for the specified child view controller.
overlayTargetNotchPolicynull35     func overlayTargetNotchPolicy(for overlayViewController: UIViewController) -> OverlayTranslationTargetNotchPolicy?
36     /// Returns the animation controller for the specified child view controller.
37     func animationController(for overlayViewController: UIViewController) -> OverlayAnimatedTransitioning?
38 }
39 
40 /// A protocol that provides the expected notch index once the user finishes dragging.
41 ///
42 /// Adopt this protocol to provide your own policy. You can also use the provided
43 /// implementations like `RushingForwardTargetNotchPolicy`.
44 public protocol OverlayTranslationTargetNotchPolicy {
45     /// Returns the expected notch index based on the specified context.
46     func targetNotchIndex(using context: OverlayContainerContextTargetNotchPolicy) -> Int
47 }
48 
49 /// A protocol that provides the animation controllers once the user finishes dragging.
50 ///
51 /// Adopt this protocol to perform your own translation animations. You can also use the provided
52 /// implementations like `SpringOverlayTranslationAnimationController`.
53 public protocol OverlayAnimatedTransitioning {
54     /// Returns the animator that will animate the end of the translation.
interruptibleAnimatornull55     func interruptibleAnimator(using context: OverlayContainerContextTransitioning) -> UIViewImplicitlyAnimating
56 }
57 
58 public extension OverlayTransitioningDelegate {
59 
60     func overlayTargetNotchPolicy(for overlayViewController: UIViewController) -> OverlayTranslationTargetNotchPolicy? {
61         nil
62     }
63 
64     func animationController(for overlayViewController: UIViewController) -> OverlayAnimatedTransitioning? {
65         nil
66     }
67 }
68