Skip to content

A header's drawn bar items are drawn again when the scheme changes on iOS - #2

Draft
janicduplessis wants to merge 1 commit into
mainfrom
@janic/bar-face-scheme
Draft

janicduplessis wants to merge 1 commit into
mainfrom
@janic/bar-face-scheme

Conversation

@janicduplessis

@janicduplessis janicduplessis commented Nov 14, 2026 •

Copy link
Copy Markdown

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 ChipFace or BadgeFace paints for one scheme. dark is part of the face's source. The bar is projected again only from prepareRoutes, 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 as color="light-dark(#000, #fff)" is drawn black on the dark glass until the next projection (a relaunch or a navigation). Apps whose views read prefers-color-scheme happen to get a batch, which hides the bug.

Solution

ExactView already hears every scheme change (reportScheme). It now also calls NavigationHost.schemeChanged(), which runs prepareRoutes on each of allNavigations on the next main-queue turn. That is the same entry point scrollBackendChanged and replayHatches use. The face's source includes the scheme, so only routes whose faces changed are projected again, and kept items are changed in place.

  • One turn later. When the change is heard, the header's node views still report the old scheme (drawsDark reads their traitCollection). 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.
  • Live stacks only. A stack whose routes are not all in controllers (one still showing a route after end(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 (in NavigationBarSchemeIOSTests.swift, which keeps NavigationBarIOSTests.swift under 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's overrideUserInterfaceStyle and reads the bar item's pixels.

bun host/apple/build.mjs --test --ios --only NavigationBarIOSTests on an iPhone 18 Pro simulator (iOS 27.0):

  • Without a fix: the new test fails, and the other 46 pass.
  • With this fix: all 47 pass.

bun scripts/caps.mjs is within every cap.

… 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.
@janicduplessis
janicduplessis changed the base branch from main to @janic/sync-upstream November 15, 2026 02:26
@janicduplessis

Copy link
Copy Markdown
Author

I rebased this onto @janic/sync-upstream (#10), which merges expo/exact main at a107143. It conflicted in ExactViewIOS.swift and NavigationBarIOS.swift, so it would have stopped merging into main once the sync lands. The base is now @janic/sync-upstream, so the diff shows only this PR. Retarget it to main after #10 merges.

The change itself is the same. reportScheme now also calls fitAheadOfLayout() upstream, and schemeChanged() is added beside it. schemeChanged() sits before upstream's makeNavigation(first:). The three commits are squashed into one.

bun host/apple/build.mjs --test --ios --only NavigationBarIOSTests on an iPhone 18 Pro simulator (iOS 27.0) passes testADrawnBarItemIsDrawnAgainWhenTheSchemeChanges. Its one failure is testAHeadingsAuthoredTypographyIsTheBarsTitleFont, which also fails on the sync branch without this PR. bun scripts/caps.mjs is now within every cap.

@janicduplessis
janicduplessis changed the base branch from @janic/sync-upstream to main November 15, 2026 03:40
ccheever added a commit to expo/exact that referenced this pull request Nov 15, 2026
… 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>
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