Skip to content

Paint a virtual list's background on iOS like a list's - #175

Open
wojt-janowski wants to merge 1 commit into
NativePHP:mainfrom
wojt-janowski:fix/virtual-list-background
Open

wojt-janowski wants to merge 1 commit into
NativePHP:mainfrom
wojt-janowski:fix/virtual-list-background

Conversation

@wojt-janowski

Copy link
Copy Markdown
Contributor

Problem

On iOS, native:virtual-list ignores its background. A virtual list with class="w-full flex-1 bg-theme-background" paints the iOS system background: pure black in dark mode and white in light mode, under a themed screen. native:list on the same theme paints the theme's colour.

During a fast scroll, the slots that haven't loaded yet show a solid systemGray6 sheet.

Cause

NativeUIVirtualListRenderer.swift renders a .plain List without ListBackgroundModifier, which NativeUIListRenderer.swift applies. That modifier hides the system scroll background and paints the node's bg-* colour, and it handles gradients and transparent too. The virtual list's rows also kept SwiftUI's opaque system row fill, and its placeholders were a hard-coded Color(.systemGray6).

Fix

  • ListBackgroundModifier is no longer private. The virtual list applies the same modifier, so a colour, a gradient or transparent behave the same on native:list and native:virtual-list.
  • Rows have .listRowBackground(Color.clear), as plain native:list rows do.
  • Placeholders are Color.clear, like native:list's own placeholder rows. The list's background shows through while rows load, so a fast scroll stays on the screen's colour instead of flashing a fill.
  • virtual-list accepts transparent (attribute and fluent method), like list, so it can sit directly on a gradient or background layer. There's a collector test for it.

Android is unchanged. LazyColumn draws no background of its own, so the node's bg-* already shows, and VirtualListRenderer.kt's placeholders use the theme's surfaceVariant, not a system colour.

Evidence

The Firstlight showcase (Recipes → Contacts, 5,000 rows) was pointed at this branch with bg-theme-background added to its native:virtual-list. It ran on an iPhone 17 Pro simulator (iOS 26.5). "Fast scroll" is a capture taken mid-fling, three quick flicks past the loaded window.

Dark mode. Before: black list, and a grey sheet while scrolling. After: navy #0F172A throughout.

iOS dark mode before and after

Light mode. Before: white list, and a #F2F2F7 sheet while scrolling. After: theme background #F8FAFC throughout.

iOS light mode before and after

The colours above are pixel samples from the list area of each screenshot.

Checks: Pest (404 passed; the new test fails without the PHP change), pint --test, and swiftc -parse on both changed Swift files.

Not verified: Android, which has no code change; gradient and transparent virtual lists on device (they take the same modifier path as native:list); iOS 27.

Made with Amp: https://ampcode.com/threads/T-01a1717b-73af-7263-867e-a12595969c54 and https://ampcode.com/threads/T-01a17444-1016-755c-a4c4-8bfd1563e21c

A virtual list with a bg-* class drew the iOS system background instead:
pure black in dark mode, white in light mode, under a themed screen. Its
List never got ListBackgroundModifier, which native:list uses to hide the
system scroll background and paint the node's colour. Rows outside the
window also drew a hard-coded systemGray6 block, so a fast scroll
flashed a grey sheet.

The virtual list now uses the same ListBackgroundModifier as native:list,
so a colour, a gradient or transparent behave the same on both. Rows and
placeholders are clear, as in a plain native:list, so the list's
background shows through while rows load. virtual-list also accepts
transparent, like list.

Android is unchanged: LazyColumn draws no background of its own, and its
placeholders already use the theme's surface-variant.

Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-01a17444-1016-755c-a4c4-8bfd1563e21c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant