Pure SwiftUI state-driven library to present view sequences and hierarchies.

Overview

PathPresenter

GitHub release (latest by date) GitHub top language Codacy Badge

swiftUIOnboarding.mp4

Pure SwiftUI routing with transitions, animations, and .sheet() support.

In SwiftUI, View is a function of the state. Routing is not an exception. Reasoning and under the hood explanation can be found on my blog:

http://alexdremov.me/swiftui-navigation-is-a-mess-heres-what-you-can-do/

Why

  • .sheet() usages are usually messy, deviate from app architecture, and require additional business-logic
  • Creating view sequences in SwiftUI is not elegant and even not messy
  • MVVM is gorgeous, but what about one level above? Routing between MVVM modules is cluttered.

Advantages

  • Purely state-driven. No ObservableObjects, no EnvironmentObjects, no Singletons.
  • Pure SwiftUI.
  • SwiftUI transitions and animations.
  • Structured .sheet() support. No need to remaster the whole codebase to present the view with .sheet(). It just works.

Example

Example from the video: PathPresenterExample

The view hierarchy is managed through the PathPresenter.Path() structure. You can push new views into it using .append methods and delete views from the top using .removeLatest.

Internally, the view's layout is managed by ZStack, so all views history is visible.

Possible presentation ways:

enum PathType {
  /**
   * Just show a view. No animation, no transition.
   * Show view above all other views
   */
  case plain
  
  /**
   * Show view with in and out transitions.
   * Transition animation also can be specified.
   */
  case animated(transition: AnyTransition, animation: Animation)
  
  /**
   * Show view in .sheet()
   * - Note: If you want to present several views in sheet,
   * you can create a second RoutingView and use it in sheet!
   */
  case sheet(onDismiss: Action)
}

Complete example:


struct RootViewGitHub: View {
    @State var path = PathPresenter.Path()

    var body: some View {
        PathPresenter.RoutingView(path: $path) {
            // Root view. Always presented
            VStack {
                Button("Push") {
                    path.append(
                        VStack {
                            Text("Hello from plain push")
                            backButton
                        }.frame(width: 300, height: 300)
                         .background(.white)
                         .border(.red),
                        type: .plain
                    )
                }
                Button("Sheet") {
                    path.append(
                        VStack {
                            Text("Hello from sheet")
                            backButton
                        }.frame(width: 300, height: 300)
                         .background(.white)
                         .border(.red),
                        type: .sheet(onDismiss: {print("dismissed")})
                    )
                }
                Button("Left animation") {
                    path.append(
                        VStack {
                            Text("Hello from left animation")
                            backButton
                        }.frame(width: 300, height: 300)
                         .background(.white)
                         .border(.red),
                        type: .animated(transition: .move(edge: .leading),
                                        animation: .easeIn)
                    )
                }
            }
            .frame(width: 300, height: 300)
        }
    }
    
    var backButton: some View {
        Button("Back") {
            if !path.isEmpty {
                path.removeLast()
            }
        }
    }
}

Transitions and animation example

Documentation

Code is mostly commented and simply structured. Check it out!

TODO

  • Path-based routing. Define view hierarchy with URL-like structures for better views switching architecture
You might also like...
SwiftUI animated image view that works on iOS and layout just as SwiftUI.Image

SwiftUI.AnimatedImage SwiftUI animated image view that works on iOS and layout just as SwiftUI.Image Screen.Recording.2021-07-31.at.02.18.33.mov Insta

Inspired by Fabric - Answers animation. Allows to
Inspired by Fabric - Answers animation. Allows to "build" given view with pieces. Allows to "destroy" given view into pieces

ADPuzzleAnimation Whats inside Custom animation for UIView inspired by Fabric - Answers animation. Easy to use To create your first animation you need

A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!
A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!

ver 2.0 NB! Breaking changes in 2.0 - due to a lot of requests EasyAnimation does NOT automatically install itself when imported. You need to enable i

This library for animating text. Developed with SwiftUI. This library supports iOS/macOS.

AnimateText This library for animating text. Developed with SwiftUI. This library supports iOS/macOS. Screenshot AnimateText.mp4 Example https://fabul

A library of custom iOS View Controller Animations and Interactions.
A library of custom iOS View Controller Animations and Interactions.

RZTransitions is a library to help make iOS7 custom View Controller transitions slick and simple. Installation CocoaPods (Recommended) Add the followi

A drawer view implemented by SwiftUI
A drawer view implemented by SwiftUI

DrawerView-SwiftUI A drawer view implemented by SwiftUI. This is not just simply a demo, instead, it can be directly used in project as a module as it

Shimmer: A super-light modifier that adds a shimmering effect to any SwiftUI View
Shimmer: A super-light modifier that adds a shimmering effect to any SwiftUI View

SwiftUI-Shimmer ✨ Shimmer is a super-light modifier that adds a shimmering effec

A lightweight loading animation that can be applied to any SwiftUI view with 1 line of code.

SimpleAFLoader A lightweight loading animation that can be applied to any SwiftUI view with 1 line of code. All animations are built using the SwiftUI

Simple and light weight facebook login library for UIKit & SwiftUI
Simple and light weight facebook login library for UIKit & SwiftUI

MjFbLogin Simple and light weight facebook login library which provides support for UIKit & SwiftUI Example To run the example project, clone the repo

Comments
  • [ Question ] How to use path variable in child view

    [ Question ] How to use path variable in child view

    I am following the given example but it is still unclear that how can I use the same path variable in child view. The main path variable should be accessible to all its child view and must be binded.

    I have LoginView and ForgetPasswordView. I have declared path as below in LoginView

    @State var path = PathPresenter.Path()

    and embedded login layout inside PathPresenter like this

    PathPresenter.RoutingView(path: $path){ 
         VStack{
              //Login layout
         }
     }
    

    and then I am appending ForgetPasswordView in this path

    path.append(ForgetPasswordView(),
                           type: .animated(transition: .move(edge: .leading), animation: .easeIn))
    

    but now the back button is inside the ForgetPasswordView so I am wondering how can I use the same path variable to go back or to append any new View?

    question 
    opened by iRiziya 13
Releases(1.1.1)
Owner
Aleksandr Dremov
MIPT Computer Science `24
Aleksandr Dremov
A Drag-and-Drop library in pure SwiftUI.

SwiftUI Drag-and-Drop Drag-and-drop is an intuitive gesture and can improve the UX of an app. Chess Emoji Art Card Game To Do List Documentation Docum

Joel T. Huber 11 Nov 28, 2022
SwiftUI directed Server Driven UI

Server Driven UI (SDUI) Intentions Make a Server Driven UI module for SwiftUI applications that has a direct use. That way the application maintainer

Felipe Hilst 8 Nov 27, 2022
Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers

Ease is an event driven animation system that combines the observer pattern with custom spring animations as observers. It's magic. Features Animate a

Robert-Hein Hooijmans 1.3k Nov 17, 2022
Swift interpolation for gesture-driven animations

Interpolate Interpolate is a powerful Swift interpolation framework for creating interactive gesture-driven animations. Usage The ?? idea of Interpola

Roy Marmelstein 1.8k Dec 20, 2022
Designed for gesture-driven animations. Fast, simple, & extensible!

Yet Another Animation Library Designed for gesture-driven animations. Fast, simple, & extensible! It is written in pure swift 3.1 with protocol orient

Luke Zhao 509 Dec 21, 2022
Simple UIButton subclass with additional state change animations (e.g. backgroundColor) and missing features

SimpleButton UIButton subclass with animated, state-aware attributes. Easy to subclass and configure! Full API docs Usage Just create your own SimpleB

Andreas Tinoco Lobo 169 Sep 14, 2022
Build complex, conducted animations declaratively without manually managing state.

Maestro Build complex, conducted animations declaratively without manually managing state. Code struct AnimatedPieChart: View { private enum Trim

Ryan Wachowski 5 Nov 20, 2022
SwiftUI-Text-Animation-Library - Text animation library for SwiftUI

⚠️ This repository is under construction. SwiftUI Text Animation Library Make yo

null 28 Jan 8, 2023
Library for creating swipe actions for any SwiftUI View

SwipeActions Library for creating swipe actions for any SwiftUI View, similar to

Alexander Kraev 24 Dec 26, 2022