Closed daprice closed 11 months ago
The Page View With Navigation Stack example demonstrates the issue if you remove the background from the ContentView and add a non-default background to the RootView:
The issue:
With this PR:
Thanks for the PR @daprice!
Whilst setting the background on the page's content view with ignoreSafeArea will achieve the same effect as your example, I can imagine there are also scenarios where you do just want the page to be transparent.
A few thoughts:
To workaround this I suggest we mirror something akin to List's scrollContentBackground
modifier which allows the behaviour to be toggled on/off.
I've gone ahead and added a new modifier on the main branch:
.pageContentBackground(.hidden)
This allows the parent background to punch through when needed whilst also preserving the default behaviour. It also has the benefit of allowing custom styles to adapt too.
I'll close this PR, but please let me know if you think I've missed anything.
With
.pageViewStyle(.scroll)
I couldn’t set a background for the overall view in SwiftUI, only for each individual page’s content. Viewing the UI hierarchy in Xcode showed theContentHostingController
being stuck with the default white background. This PR sets the hosting controller’s view background color to.clear
if the style is.scroll
, allowing any background set in SwiftUI to show through.I did this by adding a
customBackgroundColor
property toPlatformPageViewConfiguration
, then passing the configuration all the way to theContainerViewController
so it can be referenced when creating the hosting controller. I’m not sure this is the best approach architecturally, but this way allows eachPageViewStyle
to define its own background color if needed (I found that setting a clear background broke the.book
style and was only needed for.scroll
), and doesn’t break API compatibility as far as I can tell.