diff --git a/.changeset/zero-swift-macos-shape-backgrounds.md b/.changeset/zero-swift-macos-shape-backgrounds.md new file mode 100644 index 0000000000..2589767b93 --- /dev/null +++ b/.changeset/zero-swift-macos-shape-backgrounds.md @@ -0,0 +1,5 @@ +--- +'zero-swift': patch +--- + +`VirtualList`'s docs now warn that on macOS 27 a background or an overlay drawn from a bare `ShapeStyle` in a row, the header or the footer, such as `.background(.quaternary)`, has SwiftUI lay that view and the window's root view out again on every frame the list scrolls. Drawn in a shape, as in `.background(.quaternary, in: Rectangle())`, it looks the same without that work. A debug build's blank-space tint (`-ZeroVirtualTintBlankSpace YES`) now draws each row's backdrop in a shape, so the tint no longer adds that work to every row on each frame. diff --git a/swift/Sources/ZeroVirtual/RowsScrollView.swift b/swift/Sources/ZeroVirtual/RowsScrollView.swift index 45967b319a..920e3f9b0e 100644 --- a/swift/Sources/ZeroVirtual/RowsScrollView.swift +++ b/swift/Sources/ZeroVirtual/RowsScrollView.swift @@ -488,8 +488,11 @@ .environment(\.backgroundProminence, state.emphasized ? .increased : .standard)) if RowsLayout.tintsBlankSpace { // Drawn with the row's content: a row whose content isn't drawn - // yet shows the tint. - content = AnyView(content.background(state.selected ? .clear : Self.backdrop)) + // yet shows the tint. In a shape: a bare style laid every row out + // again on each frame the list scrolled, on macOS 27 (see + // `VirtualList`). + content = AnyView( + content.background(state.selected ? .clear : Self.backdrop, in: Rectangle())) } let shown = layout.selectable diff --git a/swift/Sources/ZeroVirtual/VirtualList.swift b/swift/Sources/ZeroVirtual/VirtualList.swift index c3b0a27e8b..c062c8ebb1 100644 --- a/swift/Sources/ZeroVirtual/VirtualList.swift +++ b/swift/Sources/ZeroVirtual/VirtualList.swift @@ -38,6 +38,15 @@ /// own hosting view, which inherits /// the list's environment: a row's `@ZeroQuery` reads the list's client /// (`.zero(_:)`), and its `@Environment` values are the list's. + /// + /// Draw a background or an overlay in a row, the header or the footer in + /// a shape, as in `.background(.quaternary, in: Rectangle())`, not + /// `.background(.quaternary)`. From a bare `ShapeStyle` (a `Color`, a + /// material, `.quaternary`), SwiftUI on macOS 27 follows the view's place + /// in the window, so on every frame the list scrolls it lays that view + /// out again, and the window's root view with it, rows kept off screen + /// included. In a shape it looks the same, as does + /// `.background { Color.gray }`. public struct VirtualList< Context: Sendable, Row: ZeroRow, Key: Hashable, StartRow: Equatable & Sendable, ListContext: Equatable & Sendable, RowContent: View diff --git a/swift/TestHost/App/Screens.swift b/swift/TestHost/App/Screens.swift index 8be7e9bbec..27c1631616 100644 --- a/swift/TestHost/App/Screens.swift +++ b/swift/TestHost/App/Screens.swift @@ -230,7 +230,9 @@ struct Accessory: View { .font(.headline) .frame(maxWidth: .infinity, alignment: .leading) .padding(12) - .background(.quaternary) + // In a shape: a bare style lays the header and the window's root + // out again on every frame the list scrolls, on macOS 27. + .background(.quaternary, in: Rectangle()) .contentShape(.accessibility, Rectangle()) .accessibilityElement(children: .ignore) .accessibilityLabel(text)