FlowRouter GitHub Repo Search App.
A FlowRouter
exists for each Flow.
It is responsible for single flow control.
flowchart LR;
subgraph search_flow
SearchPresenter--Push Transition Screen-->SearchFlowRouter;
DetailPresenter-->SearchFlowRouter;
subgraph detail
DetailView-->DetailPresenter;
end
subgraph search
SearchView-->SearchPresenter;
end
end
subgraph readme_flow
subgraph readme
ReadmeView-->ReadmePresenter;
end
ReadmePresenter-->ReadmeFlowRouter;
end
SearchPresenter-->GithubUseCase;
DetailPresenter-->GithubUseCase;
ReadmePresenter-->GithubUseCase;
GithubUseCase-->GithubRepoGateway;
DetailView--Open Modal-->ReadmeView;
protocol FlowRouter: Hashable {
associatedtype PushRoute: Hashable
associatedtype NextScreen: View
var id: UUID { get }
var navigationPath: NavigationPath { get set }
var nextTransitionRoute: PushRoute { get }
func triggerScreenTransition(route: PushRoute)
func nextTransitionScreen() -> NextScreen
}
final class SearchFlowRouter: ObservableObject, FlowRouter {
let id = UUID()
@Published
var navigationPath: NavigationPath = .init()
private(set) var nextTransitionRoute: PushRoute = .unknown
func triggerScreenTransition(route: PushRoute) {
navigationPath.append(route)
nextTransitionRoute = route
}
func nextTransitionScreen() -> some View {
nextTransitionRoute.nextView(router: self)
}
}
extension SearchFlowRouter {
enum PushRoute: Hashable {
case unknown
case detail(repo: GithubRepo)
func nextView(router: SearchFlowRouter) -> some View {
switch self {
case .detail(let repo):
return DetailScreen(repo: repo, router: router)
case .unknown:
fatalError("no set next transition screen.")
}
}
}
}
-
You generate GitHub token. The only permission required is
public_repo
. -
Paste to authorization header in
GithubRepoGatewayImpl#searchGithubRepo()
-
Build and Run App!
- Mastering NavigationStack in SwiftUI. Navigator Pattern - Swift with Majid
- The new NavigationStack & NavigationPath for SwiftUI - dev.to Duncan Kent
This is licensed under MIT License