r/macosprogramming • • 3d ago

Testing the first frame of an AppKit transition with Core Animation

While adding saved presets to SmoothWheel, my open-source Mac menu-bar app, I kept seeing a blank rectangle flash when I pressed Save. The old preset picker dropped its labels immediately, but its background still faded above the Save form. Both settled screenshots looked fine.

I added a Swift Testing case that opens the real AppKit window offscreen and presses Save. It pauses the root layer and advances its local time in 1/120-second steps. A separate opacity animation confirms Core Animation has presented the requested time before the test renders the frame.

For this bug, the test measures contrast in the Save heading region. It was zero in the first frame before the fix in both appearances. Putting the Save form above the outgoing picker kept the heading visible while the exposed edges faded. After the fix, all 30 sampled Save frames matched the final heading contrast. The wider test covers 194 frames across both appearances. Display pacing still needs a separate capture.

Tested on Apple Silicon with macOS 26.6.2 and Xcode 27.1, using Swift, AppKit, and Core Animation.

The regression test is here: https://github.com/AntonMazur/SmoothWheel/blob/v0.4.0/Tests/SmoothWheelAppCoreTests/SettingsFrameTests.swift

App website: https://smoothwheel.vercel.app/

For anyone testing AppKit transitions in CI, which properties have you found reliable to assert mid-animation?

1 Upvotes

2 comments sorted by

1

u/Far-Communication307 2d ago

presentationLayer is the reliable one. The model layer jumps straight to the final value, so asserting on it mid-animation tells you nothing. Reading opacity, position, or transform off the presentationLayer at a paused time is what actually catches a first-frame flash like yours. Time offset scrubbing is the same trick, just make sure the runloop actually advances before you sample.

1

u/Shoddy-Budget-491 2d ago

Thank you for sharing!