Skip to content

Commit 48792e2

Browse files
authored
Result Builders (#19)
Closes #6.
1 parent a07bf21 commit 48792e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1775
-1216
lines changed

Demo/Demo/AppState.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import NavigationTransitions
33

44
final class AppState: ObservableObject {
55
enum Transition: CaseIterable, CustomStringConvertible, Hashable {
6+
case `default`
67
case slide
78
case crossFade
89
case slideAndFade
@@ -11,29 +12,33 @@ final class AppState: ObservableObject {
1112

1213
var description: String {
1314
switch self {
15+
case .default:
16+
return "Default"
1417
case .slide:
1518
return "Slide"
1619
case .crossFade:
1720
return "Fade"
1821
case .slideAndFade:
1922
return "Slide + Fade"
2023
case .moveVertically:
21-
return "Move Vertically"
24+
return "Slide Vertically"
2225
case .swing:
2326
return "Swing"
2427
}
2528
}
2629

27-
func callAsFunction() -> NavigationTransition {
30+
func callAsFunction() -> AnyNavigationTransition {
2831
switch self {
32+
case .default:
33+
return .default
2934
case .slide:
3035
return .slide
3136
case .crossFade:
3237
return .fade(.cross)
3338
case .slideAndFade:
3439
return .slide.combined(with: .fade(.in))
3540
case .moveVertically:
36-
return .move(axis: .vertical)
41+
return .slide(axis: .vertical)
3742
case .swing:
3843
return .swing
3944
}
@@ -89,7 +94,7 @@ final class AppState: ObservableObject {
8994
var curve: Curve
9095
var duration: Duration
9196

92-
func callAsFunction() -> NavigationTransition.Animation {
97+
func callAsFunction() -> AnyNavigationTransition.Animation {
9398
switch curve {
9499
case .linear:
95100
return .linear(duration: duration())
@@ -117,7 +122,7 @@ final class AppState: ObservableObject {
117122
}
118123
}
119124

120-
func callAsFunction() -> NavigationTransition.Interactivity {
125+
func callAsFunction() -> AnyNavigationTransition.Interactivity {
121126
switch self {
122127
case .disabled:
123128
return .disabled
@@ -130,7 +135,7 @@ final class AppState: ObservableObject {
130135
}
131136

132137
@Published var transition: Transition = .slide
133-
@Published var animation: Animation = .init(curve: .easeInOut, duration: .medium)
138+
@Published var animation: Animation = .init(curve: .easeInOut, duration: .fast)
134139
@Published var interactivity: Interactivity = .edgePan
135140

136141
@Published var isPresentingSettings: Bool = false

Demo/Demo/Swing.swift

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,44 @@
11
import NavigationTransition
22
import SwiftUI
33

4-
extension NavigationTransition {
4+
extension AnyNavigationTransition {
55
static var swing: Self {
6+
.init(Swing())
7+
}
8+
}
9+
10+
struct Swing: NavigationTransition {
11+
var body: some NavigationTransition {
612
let angle = Angle(degrees: 70)
713
let offset: CGFloat = 150
814
let scale: CGFloat = 0.5
915

10-
return .move(axis: .horizontal).combined(
11-
with: .asymmetric(
12-
push: .asymmetric(
13-
insertion: [.rotate(-angle), .offset(x: offset), .opacity, .scale(scale)].combined(),
14-
removal: [.rotate(angle), .offset(x: -offset)].combined()
15-
),
16-
pop: .asymmetric(
17-
insertion: [.rotate(angle), .offset(x: -offset), .opacity, .scale(scale), .bringToFront].combined(),
18-
removal: [.rotate(-angle), .offset(x: offset)].combined()
19-
)
20-
)
21-
)
16+
Slide(axis: .horizontal)
17+
OnPush {
18+
OnInsertion {
19+
Rotate(-angle)
20+
Offset(x: offset)
21+
Opacity()
22+
Scale(scale)
23+
}
24+
OnRemoval {
25+
Rotate(angle)
26+
Offset(x: -offset)
27+
}
28+
}
29+
OnPop {
30+
OnInsertion {
31+
Rotate(angle)
32+
Offset(x: -offset)
33+
Opacity()
34+
Scale(scale)
35+
BringToFront()
36+
}
37+
OnRemoval {
38+
Rotate(-angle)
39+
Offset(x: offset)
40+
}
41+
}
2242
}
2343
}
2444

0 commit comments

Comments
 (0)