36.8 Combining Transitions
SwiftUI transitions are combined using an instance of AnyTransition together with the combined(with:) method. To combine, for example, movement with opacity, a transition could be configured as follows:
.transition(AnyTransition.opacity.combined(with: .move(edge: .top)))
When the above example is implemented, the Text view will include a fading effect while moving.
To remove clutter from layout bodies and to promote re-usability, transitions can be implemented as extensions to the AnyTransition class. The above combined transition, for example, can be implemented as follows:
extension AnyTransition {
static var fadeAndMove: AnyTransition {
AnyTransition.opacity.combined(with: .move(edge: .top))
}
}
When implemented as an extension, the transition can simply be passed as an argument to the transition() modifier, for example:
.transition...