Add the convenient API support to use SwiftUI transition with ease-in-out duration

This commit is contained in:
DreamPiggy 2020-05-29 19:54:27 +08:00
parent 28e68492ec
commit 111a2f6b8a
1 changed files with 45 additions and 0 deletions

View File

@ -18,6 +18,15 @@ extension AnyTransition {
return AnyTransition.asymmetric(insertion: insertion, removal: removal)
}
/// Fade-in transition with duration
/// - Parameter duration: transition duration, use ease-in-out
/// - Returns: A transition with duration
public static func fade(duration: Double) -> AnyTransition {
let insertion = AnyTransition.opacity.animation(.easeInOut(duration: duration))
let removal = AnyTransition.identity
return AnyTransition.asymmetric(insertion: insertion, removal: removal)
}
/// Flip from left transition
public static var flipFromLeft: AnyTransition {
let insertion = AnyTransition.move(edge: .leading)
@ -25,6 +34,15 @@ extension AnyTransition {
return AnyTransition.asymmetric(insertion: insertion, removal: removal)
}
/// Flip from left transition with duration
/// - Parameter duration: transition duration, use ease-in-out
/// - Returns: A transition with duration
public static func flipFromLeft(duration: Double) -> AnyTransition {
let insertion = AnyTransition.move(edge: .leading).animation(.easeInOut(duration: duration))
let removal = AnyTransition.identity
return AnyTransition.asymmetric(insertion: insertion, removal: removal)
}
/// Flip from right transition
public static var flipFromRight: AnyTransition {
let insertion = AnyTransition.move(edge: .trailing)
@ -32,6 +50,15 @@ extension AnyTransition {
return AnyTransition.asymmetric(insertion: insertion, removal: removal)
}
/// Flip from right transition with duration
/// - Parameter duration: transition duration, use ease-in-out
/// - Returns: A transition with duration
public static func flipFromRight(duration: Double) -> AnyTransition {
let insertion = AnyTransition.move(edge: .trailing).animation(.easeInOut(duration: duration))
let removal = AnyTransition.identity
return AnyTransition.asymmetric(insertion: insertion, removal: removal)
}
/// Flip from top transition
public static var flipFromTop: AnyTransition {
let insertion = AnyTransition.move(edge: .top)
@ -39,10 +66,28 @@ extension AnyTransition {
return AnyTransition.asymmetric(insertion: insertion, removal: removal)
}
/// Flip from top transition with duration
/// - Parameter duration: transition duration, use ease-in-out
/// - Returns: A transition with duration
public static func flipFromTop(duration: Double) -> AnyTransition {
let insertion = AnyTransition.move(edge: .top).animation(.easeInOut(duration: duration))
let removal = AnyTransition.identity
return AnyTransition.asymmetric(insertion: insertion, removal: removal)
}
/// Flip from bottom transition
public static var flipFromBottom: AnyTransition {
let insertion = AnyTransition.move(edge: .bottom)
let removal = AnyTransition.identity
return AnyTransition.asymmetric(insertion: insertion, removal: removal)
}
/// Flip from bottom transition with duration
/// - Parameter duration: transition duration, use ease-in-out
/// - Returns: A transition with duration
public static func flipFromBottom(duration: Double) -> AnyTransition {
let insertion = AnyTransition.move(edge: .bottom).animation(.easeInOut(duration: duration))
let removal = AnyTransition.identity
return AnyTransition.asymmetric(insertion: insertion, removal: removal)
}
}