Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/zero-swift-macos-shape-backgrounds.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 5 additions & 2 deletions swift/Sources/ZeroVirtual/RowsScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions swift/Sources/ZeroVirtual/VirtualList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion swift/TestHost/App/Screens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading