Skip to content

🧭 SwiftUI navigation done right

Notifications You must be signed in to change notification settings

camboIT/NavigationKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

60 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧭 NavigationKit

NavigationKit is a lightweight library which makes SwiftUI navigation super easy to use.

πŸ’» Installation

πŸ“¦ Swift Package Manager

Using Swift Package Manager, add it as a Swift Package in Xcode 11.0 or later, select File > Swift Packages > Add Package Dependency... and add the repository URL:

https://github.com/rebeloper/NavigationKit.git

✊ Manual Installation

Download and include the NavigationKit folder and files in your codebase.

πŸ“² Requirements

  • iOS 13+
  • Swift 5

🎬 Video Tutorial

SwiftUI Navigation - How to Navigate in SwiftUI Apps on YouTube

πŸ‘‰ Import

Import NavigationKit into your View

import NavigationKit

🧳 Features

Here's the list of navigation actions that you can do with NavigationKit:

  • present
  • present with allowsSwipeToDismiss
  • present with onDismiss callback
  • present with NavigationView
  • present with NavigationView and onDismiss callback
  • push
  • push as root
  • dismiss to root
  • dismiss

Presents

Text("Present Second View").presents(SecondView())

Presents with allowsSwipeToDismiss

Text("Present Second View (not swipeablbe)").presents(SecondView(), allowsSwipeToDismiss: false)

Presents with onDismiss callback

Text("Present Second View with onDismiss callback").presents(SecondView(), onDismiss: {
    print("Did dismiss SecondView")
})

Presents with NavigationView

Text("Present Second View in NavigationView").presentsNavigationView(
    SecondView().navigationBarTitleDisplayMode(.inline).disableSwipeToDismiss()
)

Note: disableSwipeToDismiss() does the same as if you would have set allowsSwipeToDismiss to false in the init

Presents with NavigationView and onDismiss callback

Text("Present Second View in NavigationView with onDismiss callback").presentsNavigationView(
    SecondView().navigationBarTitleDisplayMode(.inline).allowsSwipeToDismiss(false)
) {
    print("Did dismiss SecondView")
}

Note: allowsSwipeToDismiss(false) does the same as if you would have set allowsSwipeToDismiss to false in the init

Pushes

NavigationView {
    Text("Push Second View").pushes(SecondView())
}

Pushes as root

NavigationView {
    Text("Push Second View").pushesAsRoot(SecondView())
}.rootable()

Dismisses to root

Text("Dismiss to Root").dismissesToRoot()

Dismisses

Text("Dismiss").dismisses()

As Button

Turn any view into a Button.

Text("Push Third View").pushes(ThirdView()).asButton()

Note: asButton() must be added right after the .pushes(_:) modifier.

TabBarView

Convenience View to construct tab bar views with already backed in NavigationView, Navigation() and rootable().

TabBarView(rootView: {
    Tab1RootView()
}, tabItemView: {
    VStack {
        Image(systemName: "1.circle.fill")
        Text("First Tab")
    }
}, tabTag: 0)

✍️ Contact

rebeloper.com / YouTube / Shop / Mentoring

πŸ“ƒ License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

🧭 SwiftUI navigation done right

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%