Skip to content
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

How do I know which route I am in? #130

Open
anthony1810 opened this issue Dec 19, 2023 · 0 comments
Open

How do I know which route I am in? #130

anthony1810 opened this issue Dec 19, 2023 · 0 comments

Comments

@anthony1810
Copy link

Let say I have a coordinator like this:

import Foundation
import RMStoreKit
import Stinsen
import SwiftUI

final class AccountCoordinator: NavigationCoordinatable {
    let stack = NavigationStack(initial: \AccountCoordinator.start)
    @Root var start = makeStart

    @Route(.fullScreen) var sports = makeSportScreen
    @Route(.push) var joinCodeTeam = makeJoinTeamScreen
    @Route(.push) var teamJoinCodeSettings = makeTeamJoinCodeSettingsScreen
    @Route(.fullScreen) var subscription = makeSubscriptionModal

    let mainViewModel: MainViewModel

    init(mainViewModel: MainViewModel) {
        self.mainViewModel = mainViewModel
    }

    @ViewBuilder
    func makeStart() -> some View {
        AccountsView()
            .environmentObject(mainViewModel)
    }

    func makeSportScreen() -> NavigationViewCoordinator<CreateTeamCoordinator> {
        NavigationViewCoordinator(
            CreateTeamCoordinator(sportsViewModel: ViewModelBuilder.build(), mainViewModel: mainViewModel)
        )
    }

    func makeJoinTeamScreen() -> some View {
        JoinTeamView()
            .environmentObject(mainViewModel)
    }

    @ViewBuilder
    func makeTeamJoinCodeSettingsScreen() -> some View {
        if let selectedTeam = mainViewModel.selectedTeam {
            TeamJoinCodeView(viewModel: TeamJoinCodeViewModel(team: selectedTeam))
                .environmentObject(mainViewModel)
        }
    }

    @ViewBuilder
    func makeSubscriptionModal() -> some View {
        RMSubscriptionModal()
    }
}

How do I detect which route I am current at so I can adjust my logic accordingly?

if (accountRouters?.isRoot(\.sports)).orFalse() {
// do something
} else {
// do something else
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant