Skip to content

Commit adfa65a

Browse files
authored
Animation and Haptics: define ViewControllerContextTransitioning
Add the definition for the `ViewControllerContextTransitioning` protocol which is needed the rest of the type hierarchy required for the `ViewController` type.
1 parent fc2b8d6 commit adfa65a

File tree

3 files changed

+118
-49
lines changed

3 files changed

+118
-49
lines changed

Sources/SwiftWin32/Animation and Haptics/View Controller Transitions/ViewControllerTransitionCoordinatorContext.swift

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,6 @@
33

44
import struct Foundation.TimeInterval
55

6-
/// The keys you use to identify the view controllers involved in a transition.
7-
public struct TransitionContextViewControllerKey: Equatable, Hashable, RawRepresentable {
8-
public typealias RawValue = String
9-
10-
public let rawValue: RawValue
11-
12-
public init(rawValue: RawValue) {
13-
self.rawValue = rawValue
14-
}
15-
}
16-
17-
/// The keys you use to identify the views involved in a transition.
18-
public struct TransitionContextViewKey: Equatable, Hashable, RawRepresentable {
19-
public typealias RawValue = String
20-
21-
public let rawValue: RawValue
22-
23-
public init(rawValue: RawValue) {
24-
self.rawValue = rawValue
25-
}
26-
}
27-
28-
extension TransitionContextViewControllerKey {
29-
/// A key that identifies the view controller that is visible at the beginning
30-
/// of the transition, or at the end of a canceled transition.
31-
public static var from: TransitionContextViewControllerKey {
32-
TransitionContextViewControllerKey(rawValue: "UITransitionContextFromViewController")
33-
}
34-
35-
/// A key that identifies the view controller that is visible at the end of a
36-
/// completed transition.
37-
public static var to: TransitionContextViewControllerKey {
38-
TransitionContextViewControllerKey(rawValue: "UITransitionContextToViewController")
39-
}
40-
}
41-
42-
extension TransitionContextViewKey {
43-
/// A key that identifies the view shown at the beginning of the transition,
44-
/// or at the end of a canceled transition.
45-
public static var from: TransitionContextViewKey {
46-
TransitionContextViewKey(rawValue: "UITransitionContextFromView")
47-
}
48-
49-
/// A key that identifies the view shown at the end of a completed transition.
50-
public static var to: TransitionContextViewKey {
51-
TransitionContextViewKey(rawValue: "UITransitionContextToView")
52-
}
53-
}
54-
556
/// Modal presentation styles available when presenting view controllers.
567
public enum ModalPresentationStyle: Int {
578
/// The default presentation style chosen by the system.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
}

Sources/SwiftWin32/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ target_sources(SwiftWin32 PRIVATE
2626
target_sources(SwiftWin32 PRIVATE
2727
"App Extensions/InputViewController.swift")
2828
target_sources(SwiftWin32 PRIVATE
29+
"Animation and Haptics/ViewControllerContextTransitioning.swift"
2930
"Animation and Haptics/View Controller Transitions/ViewControllerTransitionCoordinator.swift"
3031
"Animation and Haptics/View Controller Transitions/ViewControllerTransitionCoordinatorContext.swift")
3132
target_sources(SwiftWin32 PRIVATE

0 commit comments

Comments
 (0)