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

[Question] Reload Tab in TabCoordinatable? #89

Closed
emartinson opened this issue Aug 10, 2022 · 2 comments
Closed

[Question] Reload Tab in TabCoordinatable? #89

emartinson opened this issue Aug 10, 2022 · 2 comments

Comments

@emartinson
Copy link

emartinson commented Aug 10, 2022

Hi! Regarding your Example App, I changed MainCoordinator to be my TabBarCoordinator (which is mostly looks like AuthenticatedCoordinator in Example App):

final class MainCoordinator: TabCoordinatable {
    var child = TabChild(startingItems: [
            \MainCoordinator.home,
            \MainCoordinator.chart,
            \MainCoordinator.profile
        ])

    var user: User?

    @Route(tabItem: makeHomeTab) var home = makeHome
    @Route(tabItem: makeChartTab) var chart = makeChart
    @Route(tabItem: makeProfileTab) var profile = makeProfile

    init() {
        self.user = nil // or read from AuthService
    }

    @ViewBuilder func sharedView(_ view: AnyView) -> some View {
        view.onReceive(AuthenticationService.shared.$status, perform: { status in
            switch status {
            case .unauthenticated:
                self.user = nil
            case .authenticated(let user):
                self.user = user
                // profile = makeProfile // <--- Error here: Cannot assign value of type '() -> NavigationViewCoordinator<ProfileCoordinator>' to type 'Content<MainCoordinator, NavigationViewCoordinator<ProfileCoordinator>>'
            }
        })
    }

What I want to know - how can I reload profile tab? I want to display user avatar and name on tab item if user is authenticated.

@LePips
Copy link
Collaborator

LePips commented Aug 10, 2022

This is somewhat similar to my request #33.

What you should do now is that the view set to the tab item checks whether the user is authenticated or not and in the body shows the correct view.

@emartinson
Copy link
Author

Yeah, this seems to be the only way and it's working! Thank you!

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

2 participants