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

When i push to new screen, tabbar disappears. #78

Open
Cavidan998 opened this issue Nov 17, 2024 · 19 comments
Open

When i push to new screen, tabbar disappears. #78

Cavidan998 opened this issue Nov 17, 2024 · 19 comments

Comments

@Cavidan998
Copy link

Tabbar is only shown in first screen, i dont hide tabbar, but when push tabbar stay on old screen, does not cross to new screen. Anyone face that problem?

@SwiftfulThinking
Copy link
Owner

In SwiftUI, you determine this behavior by putting the NavigationStack inside or outside of the TabView. This is the same behavior for using native NavigationStack or RouterView...

// Each tab has a NavigationStack and does not hide tabbar
TabView {
     RouterView { router in
          Text("Screen1")
     }
}
// The entire tabbar has one NavigationStack that does hide tabbar
RouterView { router in
     TabView {
          Text("Screen1")
     }
}

@Cavidan998
Copy link
Author

Thanks for quick response , i will check this

@Cavidan998
Copy link
Author

I think after IOS 18, this problem appeared. I tested your code, it does not work. But this case worked before IOS 18, did you test your code in any project

@Cavidan998
Copy link
Author

Problem is on showScreen(.push) it does not work correctly

@SwiftfulThinking
Copy link
Owner

Can you provide sample code example that does not work?

@Cavidan998
Copy link
Author

there are a lot of codes. I found problem, problem is when i put

RouterView { router in
TabsView(viewModel: TabsViewModel())
}

problem occur.

But when i use

TabsView(viewModel: TabsViewModel())

it works.

I dont understand, why?

@Cavidan998
Copy link
Author

After 16 hours of testing all cases. i found how to solve.

RouterView(addNavigationView: false) { router in
}

this solved problem.

@SwiftfulThinking
Copy link
Owner

That's explained in the ReadMe if you want some background...

That means you probably still have NavigationStack in your code. If you delete your NavigationStack and use only RouterView, you won't need to set addNavigationView: false.

@Cavidan998
Copy link
Author

But i only use RouterView.

@SwiftfulThinking
Copy link
Owner

Check your whole codebase for NavigationStack? If you link the repo I can look.

@Cavidan998
Copy link
Author

i search for NavigationStack, but nothing is found. Repo is private and belong to company. But i never use NavigationStack , i only use your library. I think problem is nested RouterView . Becuase in TabView i have 4 view with RouterView. And when i put TabsView(viewModel: TabsViewModel()) inside RouterView. Problem appeared. I think problem is nested RouterView

@SwiftfulThinking
Copy link
Owner

You should only have 1 RouterView per view hierarchy, there would be no need to add a 2nd. If you did, then I guess you can set addNavigationView: false but it shouldn't be necessary to add.

@SwiftfulThinking
Copy link
Owner

Without addNavigationView: false, adding a RouterView is the same as adding a NavigationStack

@Cavidan998
Copy link
Author

But i have add button in tab, and i show AddNewPost view, from TabsView(viewModel: TabsViewModel())'s router. And I have other four tabs in tabview. when is set this addNavigationView to false , add dont work. when dont set , tabbar cant disappear. i start to search new solution for this. Do you have an idea for that?

@SwiftfulThinking
Copy link
Owner

Sorry, I can't tell what the problem is without seeing the code. I've built many MVVM apps using this so there must be something unique to your setup. I would start by only having 1 RouterView per view hierarchy.

@Cavidan998
Copy link
Author

I use fullscreencover for add button in tabview. Thanks for help)

@Cavidan998
Copy link
Author

@SwiftfulThinking Hi again, when i user showModal it did not overlay tabbar, the modal start after tabbar , example: fullScreenCover overlay tabbar. How to achieve this in showModal?

@qsd-faris
Copy link

qsd-faris commented Mar 5, 2025

I have the same issue, tabbar is disappearing when pushing with:
router.showScreen(.push) { _ in...
from any of these 3 main tabbar views:

@Environment(\.router) var router

var body: some Scene {
        WindowGroup {
            RouterView { _ in
                ZStack {
                    TabView {
                        BookListView()
                            .tabItem {
                                Label(AppStrings.books, systemImage: "book.circle")
                            }
                                        
                        FavoritesView()
                            .tabItem {
                                Label(AppStrings.favorites, systemImage: "heart.circle")
                            }
                        
                        SettingsView()
                            .tabItem {
                                Label(AppStrings.settings, systemImage: "gear.circle")
                            }
                    }
                }
            }
        }
    }

@SwiftfulThinking
Copy link
Owner

SwiftfulThinking commented Mar 5, 2025

@qsd-faris That is not an issue, it is how the NavigationStack works by design. As I said above, you can implement a separate NavigationStack on each tab if you prefer. It would look closer to this:

TabView {
      RouterView { _ in
          BookListView()
     }       
     RouterView { _ in
          FavoritesView()
     }
     RouterView { _ in
          SettingsView()
     }
}

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

3 participants