|
| 1 | +// Copyright © 2021 Saleem Abdulrasool < [email protected]> |
| 2 | +// SPDX-License-Identifier: BSD-3-Clause |
| 3 | + |
| 4 | +/// The keys you use to identify the view controllers involved in a transition. |
| 5 | +public struct TransitionContextViewControllerKey: Equatable, Hashable, RawRepresentable { |
| 6 | + public typealias RawValue = String |
| 7 | + |
| 8 | + public let rawValue: RawValue |
| 9 | + |
| 10 | + public init(rawValue: RawValue) { |
| 11 | + self.rawValue = rawValue |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +extension TransitionContextViewControllerKey { |
| 16 | + /// A key that identifies the view controller that is visible at the beginning |
| 17 | + /// of the transition, or at the end of a canceled transition. |
| 18 | + public static var from: TransitionContextViewControllerKey { |
| 19 | + TransitionContextViewControllerKey(rawValue: "UITransitionContextFromViewController") |
| 20 | + } |
| 21 | + |
| 22 | + /// A key that identifies the view controller that is visible at the end of a |
| 23 | + /// completed transition. |
| 24 | + public static var to: TransitionContextViewControllerKey { |
| 25 | + TransitionContextViewControllerKey(rawValue: "UITransitionContextToViewController") |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +/// The keys you use to identify the views involved in a transition. |
| 30 | +public struct TransitionContextViewKey: Equatable, Hashable, RawRepresentable { |
| 31 | + public typealias RawValue = String |
| 32 | + |
| 33 | + public let rawValue: RawValue |
| 34 | + |
| 35 | + public init(rawValue: RawValue) { |
| 36 | + self.rawValue = rawValue |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +extension TransitionContextViewKey { |
| 41 | + /// A key that identifies the view shown at the beginning of the transition, |
| 42 | + /// or at the end of a canceled transition. |
| 43 | + public static var from: TransitionContextViewKey { |
| 44 | + TransitionContextViewKey(rawValue: "UITransitionContextFromView") |
| 45 | + } |
| 46 | + |
| 47 | + /// A key that identifies the view shown at the end of a completed transition. |
| 48 | + public static var to: TransitionContextViewKey { |
| 49 | + TransitionContextViewKey(rawValue: "UITransitionContextToView") |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +/// A set of methods that provide contextual information for transition |
| 54 | +/// animations between view controllers. |
| 55 | +public protocol ViewControllerContextTransitioning { |
| 56 | + // MARK - Accessing the Transition Objects |
| 57 | + |
| 58 | + /// The view that acts as the superview for the views involved in the |
| 59 | + /// transition. |
| 60 | + var containerView: View { get } |
| 61 | + |
| 62 | + /// Returns a view controller involved in the transition. |
| 63 | + func viewController(forKey key: TransitionContextViewControllerKey) |
| 64 | + -> ViewController? |
| 65 | + |
| 66 | + /// Returns the specified view involved in the transition. |
| 67 | + func view(forKey key: TransitionContextViewKey) -> View? |
| 68 | + |
| 69 | + // MARK - Getting the Transition Frame Rectangles |
| 70 | + |
| 71 | + /// Returns the starting frame rectangle for the specified view controller's |
| 72 | + /// view. |
| 73 | + func initialFrame(for viewController: ViewController) -> Rect |
| 74 | + |
| 75 | + /// Returns the ending frame rectangle for the specified view controller's |
| 76 | + /// view. |
| 77 | + func finalFrame(for viewController: ViewController) -> Rect |
| 78 | + |
| 79 | + // MARK - Getting the Transition Behaviors |
| 80 | + |
| 81 | + /// A boolean value indicating whether the transition should be animated. |
| 82 | + var isAnimated: Bool { get } |
| 83 | + |
| 84 | + /// A boolean value indicating whether the transition is currently |
| 85 | + /// interactive. |
| 86 | + var isInteractive: Bool { get } |
| 87 | + |
| 88 | + /// Returns the presentation style for the view controller transition. |
| 89 | + var presentationStyle: ModalPresentationStyle { get } |
| 90 | + |
| 91 | + // MARK - Reporting the Transition Progress |
| 92 | + |
| 93 | + /// Notifies the system that the transition animation is done. |
| 94 | + func completeTransition(_ didComplete: Bool) |
| 95 | + |
| 96 | + /// Updates the completion percentage of the transition. |
| 97 | + func updateInteractiveTransition(_ percentComplete: Double) |
| 98 | + |
| 99 | + /// Tells the system to pause the animations. |
| 100 | + func pauseInteractiveTransition() |
| 101 | + |
| 102 | + /// Notifies the system that user interactions signaled the completion of the |
| 103 | + /// transition. |
| 104 | + func finishInteractiveTransition() |
| 105 | + |
| 106 | + /// Notifies the system that user interactions canceled the transition. |
| 107 | + func cancelInteractiveTransition() |
| 108 | + |
| 109 | + /// Returns a boolean value indicating whether the transition was canceled. |
| 110 | + var transitionWasCancelled: Bool { get } |
| 111 | + |
| 112 | + // MARK - Getting the Rotation Factor |
| 113 | + |
| 114 | + /// Returns a transform indicating the amount of rotation being applied during |
| 115 | + /// the transition. |
| 116 | + var targetTransform: AffineTransform { get } |
| 117 | +} |
0 commit comments