55// Audited for 6.5.4
66// Status: Complete
77
8- // MARK: - ViewTraitCollection + canTransition
8+ // MARK: - View + transition
9+
10+ @available ( OpenSwiftUI_v1_0, * )
11+ extension View {
12+
13+ /// Associates a transition with the view.
14+ ///
15+ /// When this view appears or disappears, the transition will be applied to
16+ /// it, allowing for animating it in and out.
17+ ///
18+ /// The following code will conditionally show MyView, and when it appears
19+ /// or disappears, will use a slide transition to show it.
20+ ///
21+ /// if isActive {
22+ /// MyView()
23+ /// .transition(.slide)
24+ /// }
25+ /// Button("Toggle") {
26+ /// withAnimation {
27+ /// isActive.toggle()
28+ /// }
29+ /// }
30+ @inlinable
31+ @_disfavoredOverload
32+ nonisolated public func transition( _ t: AnyTransition ) -> some View {
33+ return _trait ( TransitionTraitKey . self, t)
34+ }
35+
36+ /// Associates a transition with the view.
37+ ///
38+ /// When this view appears or disappears, the transition will be applied to
39+ /// it, allowing for animating it in and out.
40+ ///
41+ /// The following code will conditionally show MyView, and when it appears
42+ /// or disappears, will use a custom RotatingFadeTransition transition to
43+ /// show it.
44+ ///
45+ /// if isActive {
46+ /// MyView()
47+ /// .transition(RotatingFadeTransition())
48+ /// }
49+ /// Button("Toggle") {
50+ /// withAnimation {
51+ /// isActive.toggle()
52+ /// }
53+ /// }
54+ @available ( OpenSwiftUI_v5_0, * )
55+ @_alwaysEmitIntoClient
56+ nonisolated public func transition< T> ( _ transition: T ) -> some View where T: Transition {
57+ self . transition ( AnyTransition ( transition) )
58+ }
59+ }
60+
61+ // MARK: - TransitionTraitKey
62+
63+ @available ( OpenSwiftUI_v1_0, * )
64+ @usableFromInline
65+ struct TransitionTraitKey : _ViewTraitKey {
66+ @inlinable
67+ static var defaultValue : AnyTransition { . opacity }
68+ }
69+
70+ @available ( * , unavailable)
71+ extension TransitionTraitKey : Sendable { }
72+
73+ // MARK: - CanTransitionTraitKey
974
1075@available ( OpenSwiftUI_v1_0, * )
1176@usableFromInline
@@ -17,6 +82,8 @@ struct CanTransitionTraitKey: _ViewTraitKey {
1782@available ( * , unavailable)
1883extension CanTransitionTraitKey : Sendable { }
1984
85+ // MARK: - ViewTraitCollection + canTransition
86+
2087extension ViewTraitCollection {
2188 package var canTransition : Bool {
2289 get { self [ CanTransitionTraitKey . self] }
@@ -26,10 +93,6 @@ extension ViewTraitCollection {
2693
2794// MARK: - ViewTraitCollection + transition
2895
29- struct TransitionTraitKey : _ViewTraitKey {
30- static var defaultValue : AnyTransition { . opacity }
31- }
32-
3396extension ViewTraitCollection {
3497 package var transition : AnyTransition {
3598 self [ TransitionTraitKey . self]
0 commit comments