apptekstudios / ASCollectionView

A SwiftUI collection view with support for custom layouts, preloading, and more.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot Hide Navigation Bar

Rspoon3 opened this issue · comments

commented

Describe the bug
If you try to hide the navigation bar on a view with ASCollectionView, the navigation bar always shows to some degree.

To Reproduce
Steps to reproduce the behavior:
On the TagsScreen of the demo project add the following to the outermost VStack:

.navigationBarTitle("")
.navigationBarHidden(true)
.navigationBarBackButtonHidden(true)

Expected behaviour
The navigation bar should be completely hidden, and there should be not available space for it.

Screenshots
I colored the outer most VStack red to show that its not taking but the full height.
Screen Shot 2020-06-01 at 5 26 42 PM

Simulator, Device, Both?
Tested on Xcode 11.5 simulator

Hi Ricky,

Thanks for opening the issue. This looks like some default SwiftUI behaviour unrelated to ASCollectionView. Try setting a non-empty navigation title and you'll see where this space is coming from 👍

SwiftUI defaults to using the 'large title' style, which is visible even when the nav-bar is hidden. To fix this simply use .navigationBarTitle("", displayMode: .inline)

Hope that helps!

commented

Thanks for being super responsive👊🏽

I've tried your suggestion and unfortunately that doesn't fix it. You were right that the extra space is due to the large title being the default behavior, however by changing it to be inline, the navigation view is still there, just smaller.

I'm also not sure that it is entirely SwiftUI behavior because if you comment out the ASCollectionView it works as expected. I have included additional screenshots below.

With the collection view
Screen Shot 2020-06-02 at 9 31 14 AM

Screen Shot 2020-06-02 at 9 31 50 AM

Without the collection view
Screen Shot 2020-06-02 at 9 32 42 AM

Screen Shot 2020-06-02 at 9 32 35 AM

I'm not sure why this would be happening! Perhaps you have nested multiple NavigationViews? It's a long shot, but try setting .navigationBarHidden(true) outside your NavigationView { ... } as well.

commented

Setting it outside of the navigation view (by itself and as well as inside) have no effect. There is also only one Navigation View, so its not a nesting problem.

I'm wondering if it has to do with the fact that AS_CollectionViewController is a view controller and the navigation menu needs to be hidden in that as well.

have the same issue as well

@Rspoon3 @mengdun Strangely I can't get this to happen locally, which is making debugging hard. Is this happening only in when presented in a sheet modal? Or all of the time?

@apptekstudios for me it happens all the time, tried to hide the navigation bar in the example app (the AdjustableGridScreen view), it doesn't work, it works to hide navigationbar title or back button, but not hiding the entire nav bar, thanks

Screen Shot 2020-06-08 at 2 04 44 PM

commented

@apptekstudios Yes, I ams presenting it in a sheet. In addition to my earlier screenshot, this is the only other code.

Screen Shot 2020-06-08 at 7 55 35 PM

I too am seeing this behavior with hidden navigation being un-hidden on data load. See that there is fix in place (YES!). Will this fix be in 1.7.2 release?

Adding .navigationBarTitle("", displayMode: .inline).navigationBarHidden(true).navigationBarBackButtonHidden(true) to the item layout can solve this problem.
eg:

ASCollectionView(data: dataExample, dataID: \.self) {  item, _ in 
         Color.blue  
                .overlay(Text("\(item)"))  
                .navigationBarTitle("", displayMode: .inline)  
                .navigationBarHidden(true)  
                .navigationBarBackButtonHidden(true)  
  }

So it seems like it's a SwiftUI issue as it for some reason tries to access parent's view controller's navigation controller.
Which happens on ACCollectionView cell will appear, (when it adds internal cell hosting view controller as a child)
Screenshot 2021-06-03 at 14 48 12