AnyTransition.combined()
// 1. AnyTransition([.scale, .opacity, ...])
// 2. .combined(.scale, .opacity, ...)
// 3. AnyTransition(.scale, .opacity, ...)
extension AnyTransition {
// โญ๏ธ 1. combining transitions
// AnyTransition([.scale, .opacity, ...]) ........ (1)
public init(_ transitions: [AnyTransition]) {
let intialValue = AnyTransition.identity
// โญ๏ธ ไฝฟ็จ `reduce(_:_)`
self = transitions.reduce(intialValue) { (result, transition) in
result.combined(with: transition)
}
}
// โญ๏ธ 2. when AnyTransition can be inferred, use๏ผ
// .combined(.move, .scale, ...)
public static func combined(_ transitions: AnyTransition...) -> AnyTransition {
.init(transitions)
}
}
extension AnyTransition: ExpressibleByArrayLiteral {
// โญ๏ธ 3. convenience init
// AnyTransition(.move, .scale, .opacity, ...)
public init(arrayLiteral elements: AnyTransition...) {
self.init(elements) // ไฝฟ็จ (1)
}
}
View โฉ Graphics and Rendering โฉ
Last updated