mirror of
https://github.com/yattee/yattee.git
synced 2026-10-23 05:02:53 +00:00
Content-sized pages like the Search empty state only got the opaque window background behind their own frame, leaving darker window material on both sides.
39 lines
1.3 KiB
Swift
39 lines
1.3 KiB
Swift
//
|
|
// OpaqueWindowBackground.swift
|
|
// Yattee
|
|
//
|
|
// Unified opaque background for main content views on macOS.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
/// Applies an opaque window background on macOS.
|
|
///
|
|
/// Without an explicit background, content sits on the translucent window
|
|
/// material, which picks up a wallpaper tint (often bluish in dark mode) and
|
|
/// clashes with views that draw `windowBackgroundColor` themselves (lists,
|
|
/// gradient fades). No-op on other platforms.
|
|
///
|
|
/// The view is expanded to fill the proposed space first, so content-sized
|
|
/// pages (empty states, placeholders, spinners) don't paint only a strip
|
|
/// behind themselves while the rest stays on the window material.
|
|
struct OpaqueWindowBackgroundModifier: ViewModifier {
|
|
func body(content: Content) -> some View {
|
|
#if os(macOS)
|
|
content
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.background(Color(nsColor: .windowBackgroundColor).ignoresSafeArea())
|
|
#else
|
|
content
|
|
#endif
|
|
}
|
|
}
|
|
|
|
extension View {
|
|
/// Gives the view an opaque window background on macOS so all main content
|
|
/// views share the same background color. No-op on iOS/tvOS.
|
|
func opaqueWindowBackground() -> some View {
|
|
modifier(OpaqueWindowBackgroundModifier())
|
|
}
|
|
}
|