MacOS application built using SwiftUI. I am replicating a transparent background for NavigationSplitView by setting a background image for the detail and sidebar views.
//NavigationSplitView
NavigationSplitView {
VStack {
//Sidebar views
}.background(
SidebarBackgroundView()
)
.navigationSplitViewColumnWidth(ideal: 200)
} detail: {
//Detail Views
}
.toolbar {
ToolbarItem(placement: ToolbarItemPlacement.navigation) {
StatusManagerView()
}
}
.ignoresSafeArea()
.background(
SidebarBackgroundView()
)
//Background image / view
struct SidebarBackgroundView : View {
var body : some View {
GeometryReader { geo in
Image(backgroundImageName).resizable() // Make the image resizable
.aspectRatio(contentMode: .fill)
.blur(radius: 4.0, opaque: true)
.edgesIgnoringSafeArea(.all)
.frame(width: geo.size.width, height: geo.size.height, alignment: .topLeading)
}
}
}
This works fine, but I am running into an issue where when i go into fullscreen mode, the image no longer appears under the toolbar.
At this point, Im at a loss of how to approach. Ive looked to see if i can reforce the background to be redrawn, looked if there are properties ive missed, explicitly set background on toolbar.
Anyone have any suggestions or ideas of what might be going on here?
The main issue here is that NSToolbar adds a blur view as its background when the app goes into fullscreen. Your background is still technically under the toolbar.
So the ideal solution would be to completely remove the background of the toolbar, however it doesn't seem possible to remove it when the app is in fullscreen mode.
One solution could be to auto hide the toolbar when the app goes into fullscreen mode. The toolbar appears when the cursor is moved to the top edge of the window and hides when it moves away.
To achieve this in SwiftUI, you have to do the following:
willUseFullScreenPresentationOptions
to auto hide the toolbar on fullscreenI have posted an answer here to achieve this.
I also noticed that your sidebar and detail backgrounds don't align properly. Here's a quick fix with the full code:
GeometryReader gives us the width and height of the window, and the
.background(alignment: .topLeading)
makes sure both backgrounds are aligned to the top left.