An alternative SwiftUI NavigationView.
import JetNavigation
struct RootView: View {
var body: some View {
JetNavigationView {
ExampleView()
}
}
}
JetNavigationLink
allows you to navigate between views and is a universal means of interacting with navigation. When creating a JetNavigationLink
, you can specify a navigation option (forward/backward/identity/opacity), a view to navigate to, or an action (backward or root view). When you specify a view to navigate to, it is possible to specify a tag and subsequently navigate to it. Each of these options allows you to use either a label or a button style.
destination
- the view to navigatetag
- unique tag of the view that is being navigated totoTag
- the view tag to navigateoption
- transition option (animation)action
- go back either to the root viewstyle
- button stylelabel
- button design for the transitionnameButton
- the name of the button (when using a style)
destination
+label
destination
+tag
+label
destination
+option
+label
destination
+tag
+option
+label
buttonName
+style
+option
+destination
buttonName
+style
+destination
buttonName
+style
+option
+action
buttonName
+style
+action
buttonName
+style
+option
+toTag
buttonName
+style
+tag
action
+option
+label
toTag
+option
+label
toTag
+label
option
+label
struct RedView: View {
var body: some View {
ZStack {
Color.red
//Use destination and label
JetNavigationLink(destination: { BlueView() }) {
HStack{
Text("Go to blue")
.foregroundColor(.white)
.padding()
}.background(Color.yellow)
}
}
}
}
struct BlueView: View {
var body: some View {
ZStack {
Color.blue
//Use option forward and action
JetNavigationLink(action: .back, option: .forward) {
Text("Back")
.foregroundColor(.white)
}
}
}
}
Allows you to control navigation outside of the JetNavigationView
class ExternalController: JetNavigationExternalController, ObservableObject {
var jetNavigationController: AnyObject?
}
struct RootView: View {
@StateObject
var externalController:
ExternalController = .init()
var body: some View {
VStack{
JetNavigationView(externalController: externalController) {
FirstExample()
}
//External button for control
Button {
self.externalController.home()
} label: {
Text("Go to home")
}
}
}
}