-
Notifications
You must be signed in to change notification settings - Fork 40
/
Slide.swift
65 lines (58 loc) · 1.47 KB
/
Slide.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import AtomicTransition
import SwiftUI
extension AnyNavigationTransition {
/// A transition that moves both views in and out along the specified axis.
///
/// This transition:
/// - Pushes views right-to-left and pops views left-to-right when `axis` is `horizontal`.
/// - Pushes views bottom-to-top and pops views top-to-bottom when `axis` is `vertical`.
public static func slide(axis: Axis) -> Self {
.init(Slide(axis: axis))
}
}
extension AnyNavigationTransition {
/// Equivalent to `slide(axis: .horizontal)`.
@inlinable
public static var slide: Self {
.slide(axis: .horizontal)
}
}
/// A transition that moves both views in and out along the specified axis.
///
/// This transition:
/// - Pushes views right-to-left and pops views left-to-right when `axis` is `horizontal`.
/// - Pushes views bottom-to-top and pops views top-to-bottom when `axis` is `vertical`.
public struct Slide: NavigationTransitionProtocol {
private let axis: Axis
public init(axis: Axis) {
self.axis = axis
}
/// Equivalent to `Move(axis: .horizontal)`.
@inlinable
public init() {
self.init(axis: .horizontal)
}
public var body: some NavigationTransitionProtocol {
switch axis {
case .horizontal:
MirrorPush {
OnInsertion {
Move(edge: .trailing)
}
OnRemoval {
Move(edge: .leading)
}
}
case .vertical:
MirrorPush {
OnInsertion {
Move(edge: .bottom)
}
OnRemoval {
Move(edge: .top)
}
}
}
}
}
extension Slide: Hashable {}