-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Would be great to have a HelloWorld app #19
Comments
That is a great idea. I'll see about getting an example app that focuses just on the navigation library. In the meantime, I just pushed a quick update to the todo app with the changes for SwiftDuxNavigation 2.0. https://github.com/StevenLambion/SwiftUI-Todo-Example/tree/swiftdux-navigation I'll try out the code ASAP, but taking a quick glance I don't see a Route view in the code. This view is used to declare a new "route" state within the SwiftDux store that manages the routing. You'll typically want it at the root of SwiftUI Scene such as a WindowGroup. Try removing the WaypointView from the ContentView and instead add a Route to the WindowGroup. One other thing I want to point out is that the WaypointView is meant for use in custom navigational views. You don't need to use it for content views. This means that the OneView and TwoView shouldn't have a WaypointView themselves, instead, you might want to add a NavigationView to the ContentView. Then to add the OneView and TwoView as "stack items". The stackItem function below will internally wrap the OneView and TwoView inside a WaypointView for you. I wrote this code on the fly, so it may have some errors, but hopefully helps as a reference. To make it recursive, you can add further stack items to the OneView and TwoView in the same way. // RouteTestApp.swift
struct RouteTestApp: App {
var body: some Scene {
WindowGroup {
Route(name: "main") { // Add the Route here.
ContentView()
.provideStore(configureStore())
}
}
}
}
// ContentView.swift
struct ContentView: View {
@Environment(\.actionDispatcher) private var dispatch
@Environment(\.waypoint) private var waypoint
var body: some View {
NavigationView {
List {
Text("Hello, world!")
.padding()
Button(action: {
dispatch(NavigationAction.navigate(to: URL(string: "/one")!))
}) { Text("Button to one") }
Button(action: {
dispatch(NavigationAction.navigate(to: URL(string: "/two")!))
}) { Text("Button to two") }
RouteLink(path: "/one") { Text("ONE") }
RouteLink(path: "/two") { Text("TWO") }
}
// These will create the Waypoint for you and will push their views onto the NavigationView.
.stackItem(.name("one")) { OneView() }
.stackItem(.name("two")) { TwoView() }
}
}
}
struct OneView: View {
@Environment(\.actionDispatcher) private var dispatch
@Environment(\.waypoint) private var waypoint
var body: some View {
Text("One!")
.padding()
}
}
struct TwoView: View {
@Environment(\.actionDispatcher) private var dispatch
@Environment(\.waypoint) private var waypoint
var body: some View {
Text("Two!")
.padding()
}
} |
Awesome, thanks so much, I got the So if i have two main sections ( Anyway, that's a lot of questions, and i apologize for my slow uptake. I'll look forward to the hello-world version :). I'm really excited about this library, because just like (I added some probably embarrassing updates to https://github.com/hoopes/RouteTest/blob/main/RouteTest/ContentView.swift showing off my lack of knowledge...) |
The
Todo
app seems nice, but to a beginner like me, there's a lot of ceremony.I have a incredibly simple test app here, with really only the ContentView.swift really being relevant. Can you see something obvious I'm doing wrong? Somehow conflating/confusing the
route
vswaypoint
concepts?Please feel free to take what's there as a HelloWorld app (or make it even simpler, if you can/want). In any case, thanks for the library!
The text was updated successfully, but these errors were encountered: