Repository navigation
A header's drawn bar items are drawn again when the scheme changes on iOS - #2
janicduplessis wants to merge 1 commit into
Conversation
… iOS A bar item whose face is drawn (ChipFace, BadgeFace) is an image painted for one scheme, and the bar was projected again only after a batch. ExactView, which hears every scheme change, now calls NavigationHost.schemeChanged, which runs prepareRoutes on each live stack a turn later, once the header's views report the new traits. A stack still showing an ended route is left alone.
7a24c60 to
b810afb
Compare
|
I rebased this onto The change itself is the same.
|
… changes A header button whose face is drawn (a label in an authored size or font, a status dot beside a label, a badge) is a bar item whose image is painted for one colour scheme. Bars were projected again only after a batch, so when the system appearance changed and the app sent none, the item kept the old image: a title written `light-dark(#000000, #ffffff)` stayed black on the dark bar. `ExactView.reportScheme`, which hears the colour scheme, display scale and contrast change, now projects each live stack's bars again (`appearanceChanged`); a face's source includes the scheme, so only an item whose face changed is drawn again. The change is heard in the Exact view's own trait change, before UIKit has passed the new traits down to the header's views, which the faces read. Rather than wait a main-queue turn, as Janic Duplessis's fork does (appandflow#2), it asks the window for its pending trait update (`updateTraitsIfNeeded`, whose callbacks UIKit sends synchronously) and projects at once. The pixel test is the fork's: `NavigationBarIOSTests.testADrawnBarItemIsDrawnAgainWhenTheSchemeChanges` fails without this change and passes with it. Fixes #667 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Description
On iOS, a header button whose face is drawn (a label in the author's font, a dot beside a label, a badge) becomes a bar item whose image
ChipFaceorBadgeFacepaints for one scheme.darkis part of the face'ssource. The bar is projected again only fromprepareRoutes, after a batch. If the system appearance changes while the route shows and the app sends no batch, the old image stays. A title written ascolor="light-dark(#000, #fff)"is drawn black on the dark glass until the next projection (a relaunch or a navigation). Apps whose views readprefers-color-schemehappen to get a batch, which hides the bug.Solution
ExactViewalready hears every scheme change (reportScheme). It now also callsNavigationHost.schemeChanged(), which runsprepareRouteson each ofallNavigationson the next main-queue turn. That is the same entry pointscrollBackendChangedandreplayHatchesuse. The face'ssourceincludes the scheme, so only routes whose faces changed are projected again, and kept items are changed in place.drawsDarkreads theirtraitCollection). Projecting right away would rebuild an identical source and change nothing. Logging on the simulator showed the header node still reporting light at that moment and dark a turn later.controllers(one still showing a route afterend(c), such as a sheet animating away) is skipped, so no route is hatched again after.ended. Held stacks are not navigation controllers and are not touched.Test plan
NavigationBarIOSTests.testADrawnBarItemIsDrawnAgainWhenTheSchemeChanges(inNavigationBarSchemeIOSTests.swift, which keepsNavigationBarIOSTests.swiftunder the line cap) boots a new fixture,host/apple/tests/fixtures/bar-face-scheme.contract. Its header title is a pressable in an authored font with a light/dark ink pair, and nothing in it depends on the scheme. The test flips the window'soverrideUserInterfaceStyleand reads the bar item's pixels.bun host/apple/build.mjs --test --ios --only NavigationBarIOSTestson an iPhone 18 Pro simulator (iOS 27.0):bun scripts/caps.mjsis within every cap.