forked from davdroman/swiftui-navigation-transitions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fade.swift
48 lines (42 loc) · 866 Bytes
/
Fade.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import AtomicTransition
extension AnyNavigationTransition {
/// A transition that fades the pushed view in, fades the popped view out, or cross-fades both views.
public static func fade(_ style: Fade.Style) -> Self {
.init(Fade(style))
}
}
/// A transition that fades the pushed view in, fades the popped view out, or cross-fades both views.
public struct Fade: NavigationTransition {
public enum Style {
case `in`
case out
case cross
}
private let style: Style
public init(_ style: Style) {
self.style = style
}
public var body: some NavigationTransition {
switch style {
case .in:
MirrorPush {
OnInsertion {
ZPosition(1)
Opacity()
}
}
case .out:
MirrorPush {
OnRemoval {
ZPosition(1)
Opacity()
}
}
case .cross:
MirrorPush {
Opacity()
}
}
}
}
extension Fade: Hashable {}