Demo Application

The repository includes a comprehensive demo application that showcases the library's features and provides a playground for experimenting with different transitions and animations.

Running the Demo

To run the demo, clone the repository, open Package.swift in Xcode, select the Demo scheme, and run it on a simulator or device.

Core Components

The demo is built around a few key files that are worth exploring.

RootView.swift

This is the main view of the application. It sets up the NavigationStack and applies the .navigationTransition modifier. The transition, animation, and interactivity are all driven by an AppState object, showing how to dynamically configure transitions.

// Examples/Demo/Demo/RootView.swift

struct RootView: View {
    @EnvironmentObject var appState: AppState

    var body: some View {
        Group {
            if #available(iOS 16, tvOS 16, *) {
                NavigationStack {
                    PageOne()
                }
            } else {
                NavigationView {
                    PageOne()
                }
                .navigationViewStyle(.stack)
            }
        }
        .navigationTransition(transition.animation(animation), interactivity: interactivity)
        .sheet(isPresented: $appState.isPresentingSettings) {
            SettingsView().environmentObject(appState)
        }
    }

    var transition: AnyNavigationTransition {
        appState.transition()
    }

    var animation: AnyNavigationTransition.Animation? {
        // ... logic to get animation from appState
    }

    var interactivity: AnyNavigationTransition.Interactivity {
        appState.interactivity()
    }
}

AppState.swift

This observable object holds the state for the entire demo. It contains enums for all the configurable options: the transition type, animation curve, duration, and interactivity mode. This file is a great reference for seeing how different transitions are constructed.

// Examples/Demo/Demo/AppState.swift

final class AppState: ObservableObject {
    enum Transition: CaseIterable, CustomStringConvertible, Hashable {
        case `default`
        case crossFade
        case slide
        // ... more transitions

        func callAsFunction() -> AnyNavigationTransition {
            switch self {
            case .default:
                .default
            case .crossFade:
                .fade(.cross)
            case .slide:
                .slide
            // ... and so on
            }
        }
    }

    // Enums for Animation, Duration, Interactivity etc.

    @Published var transition: Transition = .slide
    @Published var animation: Animation = .spring
    // ... other @Published properties
}

SettingsView.swift

The settings screen allows you to change the active transition and its parameters at runtime. It's a great example of how to build a UI to control the navigation transitions in your own app.

Custom Transitions

The Examples/Demo/Demo/Custom Transitions/ directory contains the source code for the Flip, Swing, and Zoom transitions. These files serve as excellent, practical examples for learning how to build your own custom transitions from scratch.