Skip to content

Result Builders #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions Demo/Demo/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import NavigationTransitions

final class AppState: ObservableObject {
enum Transition: CaseIterable, CustomStringConvertible, Hashable {
case `default`
case slide
case crossFade
case slideAndFade
Expand All @@ -11,29 +12,33 @@ final class AppState: ObservableObject {

var description: String {
switch self {
case .default:
return "Default"
case .slide:
return "Slide"
case .crossFade:
return "Fade"
case .slideAndFade:
return "Slide + Fade"
case .moveVertically:
return "Move Vertically"
return "Slide Vertically"
case .swing:
return "Swing"
}
}

func callAsFunction() -> NavigationTransition {
func callAsFunction() -> AnyNavigationTransition {
switch self {
case .default:
return .default
case .slide:
return .slide
case .crossFade:
return .fade(.cross)
case .slideAndFade:
return .slide.combined(with: .fade(.in))
case .moveVertically:
return .move(axis: .vertical)
return .slide(axis: .vertical)
case .swing:
return .swing
}
Expand Down Expand Up @@ -89,7 +94,7 @@ final class AppState: ObservableObject {
var curve: Curve
var duration: Duration

func callAsFunction() -> NavigationTransition.Animation {
func callAsFunction() -> AnyNavigationTransition.Animation {
switch curve {
case .linear:
return .linear(duration: duration())
Expand Down Expand Up @@ -117,7 +122,7 @@ final class AppState: ObservableObject {
}
}

func callAsFunction() -> NavigationTransition.Interactivity {
func callAsFunction() -> AnyNavigationTransition.Interactivity {
switch self {
case .disabled:
return .disabled
Expand All @@ -130,7 +135,7 @@ final class AppState: ObservableObject {
}

@Published var transition: Transition = .slide
@Published var animation: Animation = .init(curve: .easeInOut, duration: .medium)
@Published var animation: Animation = .init(curve: .easeInOut, duration: .fast)
@Published var interactivity: Interactivity = .edgePan

@Published var isPresentingSettings: Bool = false
Expand Down
46 changes: 33 additions & 13 deletions Demo/Demo/Swing.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
import NavigationTransition
import SwiftUI

extension NavigationTransition {
extension AnyNavigationTransition {
static var swing: Self {
.init(Swing())
}
}

struct Swing: NavigationTransition {
var body: some NavigationTransition {
let angle = Angle(degrees: 70)
let offset: CGFloat = 150
let scale: CGFloat = 0.5

return .move(axis: .horizontal).combined(
with: .asymmetric(
push: .asymmetric(
insertion: [.rotate(-angle), .offset(x: offset), .opacity, .scale(scale)].combined(),
removal: [.rotate(angle), .offset(x: -offset)].combined()
),
pop: .asymmetric(
insertion: [.rotate(angle), .offset(x: -offset), .opacity, .scale(scale), .bringToFront].combined(),
removal: [.rotate(-angle), .offset(x: offset)].combined()
)
)
)
Slide(axis: .horizontal)
OnPush {
OnInsertion {
Rotate(-angle)
Offset(x: offset)
Opacity()
Scale(scale)
}
OnRemoval {
Rotate(angle)
Offset(x: -offset)
}
}
OnPop {
OnInsertion {
Rotate(angle)
Offset(x: -offset)
Opacity()
Scale(scale)
BringToFront()
}
OnRemoval {
Rotate(-angle)
Offset(x: offset)
}
}
}
}

Expand Down
Loading