NavigationKit is a lightweight library which makes SwiftUI
navigation super easy to use.
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
Download and include the NavigationKit
folder and files in your codebase.
- iOS 13+
- Swift 5
SwiftUI Navigation - How to Navigate in SwiftUI Apps on YouTube
Import NavigationKit
into your View
import NavigationKit
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
Text("Present Second View").presents(SecondView())
Text("Present Second View (not swipeablbe)").presents(SecondView(), allowsSwipeToDismiss: false)
Text("Present Second View with onDismiss callback").presents(SecondView(), onDismiss: {
print("Did dismiss SecondView")
})
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
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
NavigationView {
Text("Push Second View").pushes(SecondView())
}
NavigationView {
Text("Push Second View").pushesAsRoot(SecondView())
}.rootable()
Text("Dismiss to Root").dismissesToRoot()
Text("Dismiss").dismisses()
Turn any view into a Button
.
Text("Push Third View").pushes(ThirdView()).asButton()
Note: asButton()
must be added right after the .pushes(_:)
modifier.
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)
rebeloper.com / YouTube / Shop / Mentoring
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.