Background colors applied using SwiftUI's `background(_:alignment:)` modifier don't behave as expected
Describe the bug
Trying to set a background color for an ASCollectionView nested inside of a NavigationView causes two problems:
- The background does not extend under the navigation bar.
- Large navigation titles do not collapse when scrolling the collection view.
To Reproduce
Inside the demo app, modify the line in MainView.swift that instantiates PhotoGridScreen to look like this:
NavigationLink(destination: PhotoGridScreen().background(Color.green))
Expected behaviour The green background color should extend under the navigation bar, and the large navigation title should collapse when scrolling the collection view.
Screenshots
Xcode Version:
Xcode 11.6, but I'm pretty certain it'll happen on any version of Xcode that can build ASCollectionView.
Simulator, Device, Both? The problem occurs on both the simulator and device.
This is related to https://github.com/apptekstudios/ASCollectionView/issues/112. That issue seemed to have closed without a resolution, though.
Thanks for the PR. I'll look into merging this into the upcoming version :)
It seems that the SwiftUI .background modifier is causing the issue. I managed to reproduce a similar issue when using a plain UIScrollView wrapped in SwiftUI. I'm curious whether using .edgesIgnoringSafeArea(.all) made any difference?
Thanks a lot for merging it.
I changed the PhotoGridScreen initialization line in MainView.swift to the following:
NavigationLink(destination: PhotoGridScreen().background(Color.green).edgesIgnoringSafeArea(.all))
Unfortunately, this approach doesn't seem to be workable, either. It creates a few new problems. First, the navigation bar becomes completely translucent. Second, the collection view's insets get screwed up, too, which leads to the content being scrolled up past the top of the screen on initial appearance. I'll include a screenshot below, but, overall, it seems like using the native UICollectionView.backgroundColor property is still the best approach to take.
