Skip to content
Draft
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
2 changes: 1 addition & 1 deletion host/apple/Sources/ExactKit/IOS/ExactViewIOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public final class ExactView: UIView {
/// Paint motion resolves `light-dark()` by this view's appearance (LLP 1062).
/// A system appearance change reaches the view as a trait change too:
/// `prefers-color-scheme` is told again (LLP 1069.000 D1).
private func reportScheme() { fitAheadOfLayout(); session.scheme(dark: traitCollection.userInterfaceStyle == .dark); session.tellPreferences(); session.natives.scopesChanged() }
private func reportScheme() { fitAheadOfLayout(); session.scheme(dark: traitCollection.userInterfaceStyle == .dark); session.tellPreferences(); session.natives.scopesChanged(); session.presenter.navigation.schemeChanged() }
/// An app or window tint changed: `AccentColor` is reported again (LLP 1095 D9).
public override func tintColorDidChange() { super.tintColorDidChange(); fitAheadOfLayout(); session.reportColors() }

Expand Down
16 changes: 16 additions & 0 deletions host/apple/Sources/ExactKit/IOS/NavigationBarIOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,22 @@ extension NavigationHost {
}
}

/// A bar item's face and badge are images drawn for one scheme
/// (`ChipFace.dark`, `BadgeFace`): a new scheme projects each stack's
/// bars again, a turn later, once the header's views have the new traits
/// too. A stack still showing an ended route (a sheet animating away) is
/// left alone.
func schemeChanged() {
DispatchQueue.main.async { [weak self] in
guard let self else { return }
for nav in allNavigations {
let routes = nav.stackRoutes.compactMap { $0 as? RouteController }
guard !routes.isEmpty, routes.allSatisfy({ self.controllers[$0.node.id] === $0 }) else { continue }
prepareRoutes(routes, in: nav)
}
}
}

func makeNavigation(first: NodeView?) -> UINavigationController {
let nav = UINavigationController(navigationBarClass: RouteNavigationBar.self, toolbarClass: nil)
let stack = registerStack(nav)
Expand Down
31 changes: 31 additions & 0 deletions host/apple/tests/ExactKitTests/NavigationBarSchemeIOSTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#if os(iOS)
import UIKit
import XCTest
@testable import ExactKit

extension NavigationBarIOSTests {
/// A drawn face is an image for one scheme: the scheme changing while
/// it shows draws it again in the other ink, though the app sends no batch.
func testADrawnBarItemIsDrawnAgainWhenTheSchemeChanges() throws {
let session = try fixture("scheme-face", module: false, plan: "BAR_FACE_SCHEME")
let nav = try XCTUnwrap(session.presenter.navigation.primaryNavigation)
let navigationItem = try XCTUnwrap(nav.topViewController?.navigationItem)
let title = { ((navigationItem.leftBarButtonItems ?? []) + (navigationItem.rightBarButtonItems ?? [])).first { $0.accessibilityIdentifier == "title-home" } }
// The brightest red among the face's opaque pixels: near 0 in black ink, near 255 in white.
let ink = { () -> UInt8? in
guard let image = title()?.image?.cgImage else { return nil }
var bytes = [UInt8](repeating: 0, count: image.width * image.height * 4)
guard let context = CGContext(data: &bytes, width: image.width, height: image.height, bitsPerComponent: 8, bytesPerRow: image.width * 4,
space: CGColorSpace(name: CGColorSpace.sRGB)!, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) else { return nil }
context.draw(image, in: CGRect(x: 0, y: 0, width: image.width, height: image.height))
return stride(from: 0, to: bytes.count, by: 4).filter { bytes[$0 + 3] > 200 }.map { bytes[$0] }.max()
}
let window = try XCTUnwrap(self.window)
window.overrideUserInterfaceStyle = .light
until("the title is drawn in the light ink") { ink().map { $0 < 60 } == true }
window.overrideUserInterfaceStyle = .dark
defer { window.overrideUserInterfaceStyle = .unspecified }
until("the title is drawn again in the dark ink") { ink().map { $0 > 200 } == true }
}
}
#endif
15 changes: 15 additions & 0 deletions host/apple/tests/fixtures/bar-face-scheme.contract
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// A route whose header's title is a pressable in an authored font with a
// light and a dark ink (NavigationBarIOSTests): its bar item is a drawn face,
// and nothing in the app depends on the scheme, so switching it sends no batch.
component BarFaceScheme
state taps = 0
action tap
taps = taps + 1
view
main navigationKey="home" width="100%" height="100%"
column navigationKey="home" position="absolute" inset=0 display="flex" flex-direction="column"
header display="flex" align-items="center" padding=12 flex-shrink=0
view role="button" press=tap aria-label="Title" testId="title-home"
text "Title" font-size=20 color="light-dark(#000000, #ffffff)"
text "" role="heading" aria-level=2 flex=1
column flex=1
2 changes: 2 additions & 0 deletions host/apple/xctest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export function compileFixtures(root, run, env, dir, prefix, appId) {
contract([resolve(root, 'host/apple/tests/fixtures/untitled-bar.contract'), '-o', env[`${prefix}_UNTITLED_BAR_PLAN`] = resolve(dir, 'untitled-bar.plan')]);
// NavigationBarIOSTests': a header whose controls share and add a control.
contract([resolve(root, 'host/apple/tests/fixtures/bar-share.contract'), '-o', env[`${prefix}_BAR_SHARE_PLAN`] = resolve(dir, 'bar-share.plan')]);
// NavigationBarIOSTests': a header title drawn as a face, in an ink per scheme.
contract([resolve(root, 'host/apple/tests/fixtures/bar-face-scheme.contract'), '-o', env[`${prefix}_BAR_FACE_SCHEME_PLAN`] = resolve(dir, 'bar-face-scheme.plan')]);
contract([resolve(root, 'host/apple/tests/fixtures/dialog-sheet-reads.contract'), '-o', env[`${prefix}_DIALOG_SHEET_READS_PLAN`] = resolve(dir, 'dialog-sheet-reads.plan')]);
contract([resolve(root, 'host/apple/tests/fixtures/route-backdrop.contract'), '-o', env[`${prefix}_ROUTE_BACKDROP_PLAN`] = resolve(dir, 'route-backdrop.plan')]);
contract([resolve(root, 'host/apple/tests/fixtures/trailing-time.contract'), '-o', env[`${prefix}_TRAILING_TIME_PLAN`] = resolve(dir, 'trailing-time.plan')]);
Expand Down
Loading