[Optional] Environment-based Routing #50
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@tillkruss you're getting this for free 馃帀馃啌馃帀, if you want it.
I was messing about in SwiftUI today, on my free time. Stumbled upon something I liked a decided to stress test it on your project.
As briefly mentioned before, SwiftUI
@Environment
is also a way of doing dependency injection (I use it in some of my recent codebases). The code above allows us to automatically inject multiple Routers into the environment with very little boilerplate. So every view gets to have its own Router type but its still possible to deeplink programmatically to pretty much any screen.Notes:
path
as opposed to some global router'smoviesPath
orsettingsPath
or even deeper structures. The code is more modular.switchToNewInstance
is a little overengineered to show that the views can even be decoupled to some extent. We could have just used TabRouter and SettingsView.Router directly in MoviesView.Its a draft PR for now because I still have to uncomment some Preview code and clean up. Take it or leave it. If Im doing the cleanup, I'll start tracking time, but it'll be a few minutes.