Transition
A description of view changes to apply when a view is added to and removed from the view hierarchy.
Declaration
type Transition =
| 'blurReplace'
| 'identity'
| 'opacity'
| 'scale'
| 'slide'
| 'symbolEffect'
| { blurReplace: BlurReplaceTransitionConfiguration; }
| { move: { edge: Edge; }; }
| { offset: { x?: number; y?: number; }; }
| { offset: CGSize; }
| { push: { from: Edge; }; }
| { scale: { scale: number; anchor?: UnitPoint; }; }
| TransitionChain;@MainActor @preconcurrency protocol TransitionPass a literal, or build one with SwiftUI.Transition from import { SwiftUI } from 'swiftui-react-native'.
Type properties
'blurReplace'SwiftUI.Transition.blurReplaceA transition that animates the insertion or removal of a view by combining blurring and scaling effects.
'identity'SwiftUI.Transition.identityA transition that returns the input view, unmodified, as the output view.
'opacity'SwiftUI.Transition.opacityA transition from transparent to opaque on insertion, and from opaque to transparent on removal.
'scale'SwiftUI.Transition.scaleReturns a transition that scales the view.
'slide'SwiftUI.Transition.slideA transition that inserts by moving in from the leading edge, and removes by moving out towards the trailing edge.
'symbolEffect'SwiftUI.Transition.symbolEffectA transition that applies the default symbol effect transition to symbol images within the inserted or removed view hierarchy. Other views are unaffected by this transition.
Type methods
Overview
A transition should generally be made by applying one or more modifiers to
the content. For symmetric transitions, the isIdentity property on
phase can be used to change the properties of modifiers. For asymmetric
transitions, the phase itself can be used to change those properties.
Transitions should not use any identity-affecting changes like .id, if,
and switch on the content, since doing so would reset the state of the
view they're applied to, causing wasted work and potentially surprising
behavior when it appears and disappears.
The following code defines a transition that can be used to change the opacity and rotation when a view appears and disappears.
struct RotatingFadeTransition: Transition {
func body(content: Content, phase: TransitionPhase) -> some View {
content
.opacity(phase.isIdentity ? 1.0 : 0.0)
.rotationEffect(phase.rotation)
}
}
extension TransitionPhase {
fileprivate var rotation: Angle {
switch self {
case .willAppear: return .degrees(30)
case .identity: return .zero
case .didDisappear: return .degrees(-30)
}
}
}A type conforming to this protocol inherits @preconcurrency @MainActor
isolation from the protocol if the conformance is included in the type's
base declaration:
struct MyCustomType: Transition {
// `@preconcurrency @MainActor` isolation by default
}Isolation to the main actor is the default, but it's not required. Declare the conformance in an extension to opt out of main actor isolation:
extension MyCustomType: Transition {
// `nonisolated` by default
}- See Also:
TransitionPhase - See Also:
AnyTransition
From Apple’s SwiftUI documentation. Code samples there are Swift.
Used by
See also
More in Animation.
- AnimationThe way a view changes over time to create a smooth visual transition from one state to another.
- AnimationChainAnimation with chained calls: SwiftUI.Animation.delay(...).
- AnimationCompletionCriteriaThe criteria that determines when an animation is considered finished.
- AnimationTimelineScheduleA pausable schedule of dates updating at a frequency no more quickly than the provided interval.
- AnyTransitionA type-erased transition.
- AnyTransitionChainAnyTransition with chained calls: SwiftUI.AnyTransition.animation(...).
- BlurReplaceTransitionA transition that animates the insertion or removal of a view by combining blurring and scaling effects.
- BlurReplaceTransitionConfigurationConfiguration properties for a transition.
- ContentTransitionA kind of transition that applies to the content within a single view, rather than to the insertion or removal of a view.
- DropSessionPhaseThe phase of the current drop session.
- GlassEffectTransitionA structure that describes changes to apply when a glass effect is added or removed from the view hierarchy.
- IdentityTransitionA transition that returns the input view, unmodified, as the output view.