Code Monkey home page Code Monkey logo

swiftuinavigation's Introduction

๐Ÿงญ Navigation in SwiftUI

swift v5.1 platform iOS deployment target iOS 13

Unidirectional data flow driven navigation for SwiftUI applications

๐Ÿ“ Description

This project explores ways to implement navigation in a SwiftUI application, using unidirectional data flow architecture.

๐ŸŽฏ Goals:

  • Navigate between views in a similar way that UIKit allows
    • NavigationStackView provides behavior similar to UINavigationController
    • NavigationBackGesture provides "swipe from edge to go back" behavior known from UINavigationController
  • Implementation compatible with unidirectional data flow architecture
    • NavigationItem provides an interface for a state of a view user can navigate to
    • [NavigationItem] array is a single source of truth for NavigationStackView
    • NavigationStackView can not mutate the state itself
    • State changes are visualized by NavigationStackView
  • Easily customizable appearance
    • All included views provide a basic implementation that mimics UINavigationController look and feel, but can be replaced with any custom view if needed
    • Because no UINavigationController is used under the hood, there are no limitations or issues with appearance customizations in contrast to NavigationView provided by SwiftUI

๐Ÿงฉ Components

Component Description
NavigationItem Protocol of a state model that represents an item on navigation stack
NavigationItemView View that represents navigation item
NavigationItemViewFactory Function that creates a view for given navigation item
NavigationStackView View that represents stack of navigation items, as UINavigationController does
NavigationBarView View that represents navigation bar
NavigationBackButton Back button view that can be displayed on navigation bar
NavigationBackGesture View modifier that attaches a "swipe from edge to go back" gesture to the navigation item view

โžก๏ธ Demo app

Simple application with a navigation stack that mimics UINavigationController behavior. From initial, root screen user can go to the first step screen. The step screen allows to navigate to the next step (until step number three, which is the last one) or to go back to the root screen.

navigation flow

State of the navigation stack is modeled as an array of navigation items, hold by a store object. Whenever the array changes, view is updated to display top-most navigation item from the stack. User interface is fully customizable, supports "swipe from edge to go back" gesture and both left-to-right and right-to-left layout directions. The implementation provides some default visual style and animations, but those can be easily customized as well. Everything is written in pure SwiftUI, without using UIViewControllerRepresentable to wrap UINavigationController.

Component Description
Store Simplified implementation of store object that holds app's state
RootState State model representation of root screen view
StepState State model representation of step screen view
View Description
AppView Main view of the app containing navigation stack
RootView Root screen view, initial screen of the app
StepView Step screen view

๐Ÿ›  Setup

Requirements:

Open SwiftUINavigation.xcodeproj in Xcode and run the app.

๐Ÿ“„ License

Copyright ยฉ 2020 EL Passion

License: GNU GPLv3

swiftuinavigation's People

Contributors

darrarski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mdeora izouxv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.