apptekstudios / ASCollectionView

A SwiftUI collection view with support for custom layouts, preloading, and more.
MIT License
1.36k stars 160 forks source link

Cannot Hide Navigation Bar #151

Closed Rspoon3 closed 3 years ago

Rspoon3 commented 4 years ago

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

apptekstudios commented 4 years ago

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!

Rspoon3 commented 4 years ago

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

apptekstudios commented 4 years ago

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.

Rspoon3 commented 4 years ago

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.

mengdun commented 4 years ago

have the same issue as well

apptekstudios commented 4 years ago

@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?

mengdun commented 4 years ago

@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
Rspoon3 commented 4 years ago

@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
Fox-On-The-Run-NPE commented 4 years ago

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?

AngkiZ commented 4 years ago

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)  
  }
sergdort commented 3 years ago

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