Make sure the Tab Rail's background matches the split view's detail background. (#6003)

This commit is contained in:
Doug
2026-08-11 11:07:24 +01:00
committed by GitHub
parent d57c376b21
commit 2228da3eb9
6 changed files with 59 additions and 12 deletions
@@ -0,0 +1,35 @@
//
// Copyright 2026 Element Creations Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import SwiftUI
/// The reported background drawn by a view.
public enum CompoundBackground: Equatable {
/// A specific background colour.
case color(Color)
/// The default canvas background.
case `default`
public var colorValue: Color {
switch self {
case .color(let color): color
case .default: .compound.bgCanvasDefault
}
}
}
/// A background reported up the hierarchy by a view that opts in, so that surrounding chrome (e.g. the
/// tab rail that sits alongside iOS 26's inset sidebar) can match that view's canvas.
public struct CompoundBackgroundPreferenceKey: PreferenceKey {
public static let defaultValue: CompoundBackground? = nil
public static func reduce(value: inout CompoundBackground?, nextValue: () -> CompoundBackground?) {
if let nextValue = nextValue() {
value = nextValue
}
}
}
@@ -24,11 +24,13 @@ public extension View {
environment(\.defaultMinListRowHeight, 48)
.scrollContentBackground(.hidden)
.background(Color.compound.bgSubtleSecondaryLevel0.ignoresSafeArea())
.preference(key: CompoundBackgroundPreferenceKey.self, value: .color(.compound.bgSubtleSecondaryLevel0))
case .plain:
listStyle(.plain)
.environment(\.defaultMinListRowHeight, 48)
.scrollContentBackground(.hidden)
.background(Color.compound.bgCanvasDefault.ignoresSafeArea())
.preference(key: CompoundBackgroundPreferenceKey.self, value: .default)
}
}