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

.navigationBarHidden(true) seems not work for iOS 15 #4

Open
Horse888 opened this issue Nov 30, 2023 · 7 comments
Open

.navigationBarHidden(true) seems not work for iOS 15 #4

Horse888 opened this issue Nov 30, 2023 · 7 comments

Comments

@Horse888
Copy link

				.navigationBarTitleDisplayMode(.inline)
				.navigationTitle("")
				.navigationBarHidden(true)

The navigationBar is there, not be hidden.

@lm
Copy link
Owner

lm commented Nov 30, 2023

Hello, please provide full reproducible SwiftUI view code or project and specify exact iOS version where the problem occurs.

@Horse888
Copy link
Author

Sorry, just find that this bug will not be related to this lib.

The code as bellow:

			NavigationStackBackport.NavigationStack(path: $lifeModel.wordNaviPath) {
				TabView(selection: $lifeModel.tabTag) {
					WordsPagingView()
.navigationBarTitleDisplayMode(.inline)
				.navigationTitle("")
				.navigationBarHidden(true)
...

This issue occurred when a TabView be embedded in a NavigationView.

Even try StackOverflow with no luck.

@Horse888 Horse888 reopened this Nov 30, 2023
@Horse888
Copy link
Author

@lm
Hi lm, here is the demo code.

import SwiftUI
import NavigationStackBackport

enum TestTab {
	case test1
	case test2
	case test3
}

struct ContentView: View {
	@State var selectedTab: TestTab = .test1

	var body: some View {
		ZStack {
			NavigationStackBackport.NavigationStack { // Can't hide the navigation bar
//			NavigationView { // Using NavigationView is ok.
				TabView(selection: $selectedTab) {
					// Tab A
					List(1...1000, id: \.self) { i in
						Text("Item A: \(i)")
					}
					.navigationBarHidden(true).navigationBarTitle("a")

					.tag(TestTab.test1)
					.tabItem { Label("Home", systemImage: "n.circle") }

					// Tab B
					List(1...1000, id: \.self) { i in
						Text("Item B: \(i)")
					}
					.navigationBarHidden(true).navigationBarTitle("b")
					.tag(TestTab.test2)
					.tabItem { Label("Stories", systemImage: "book") }

					// Tab C
					List(1...1000, id: \.self) { i in
						Text("Item C: \(i)")
					}
					.navigationBarHidden(true).navigationBarTitle("c")
					.tag(TestTab.test3)
					.tabItem { Label("Settings", systemImage: "gear") }
				}
			}
			.navigationViewStyle(StackNavigationViewStyle())
		}
	}
}

#Preview {
	ContentView()
}

When I use NavigationView instead of NavigationStackBackport.NavigationStack, the navigationBar can be hidden.

@Horse888
Copy link
Author

Demo device is an iOS 15 simulator.

@lm
Copy link
Owner

lm commented Nov 30, 2023

Usually each tab has it's own navigation stack. Could that work for you? it would probably fix issues like this.

@Horse888
Copy link
Author

Yes, usually it is.
Current my requirement: I need to hide the tabBar when push to detail page.
I add something like .toolbar(.hidden, for: .tabBar), the tabBar can be hidden, and can be shown when pop back.

BUT The only issue is the tabBar will appear immediately(with no animation) when pop back. I want it's smooth appear or keep there.

So I embed the TabView in the NavigationView.

@abcdeiko
Copy link

abcdeiko commented Feb 13, 2024

Horse888
Yes, there is a problem with hiding navigation bar on ios < 16.
To do that you need to add navigationbarhidden code as the same level as your main view inside NavigationStackView is.

This code will show navigation bar when you pop from SomePushableView to SomeView:

NavigationStack(path: someVarPath) {
            SomeView()
            .navBackport
            .navigationDestination(for: SomeNavigationItem.self) {
                SomePushableView().navigationBarHidden(true)
            }
        }

This code won't show navigation bar when you pop from SomePushableView to SomeView:

NavigationStack(path: someVarPath) {
            SomeView()
            .navBackport
            .navigationDestination(for: SomeNavigationItem.self) {
                SomePushableView().navigationBarHidden(true)
            }
            .navigationBarHidden(true)
        }

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