Suppress window-level safe-area on outer snapshot VC stack#8
Closed
dfed wants to merge 1 commit into
Closed
Conversation
The existing pin on ExpandingViewController.view (PR #5) prevents layout-margin-driven safe-area propagation in the SwiftUI host, but UIKit child VCs wrapped by UIViewControllerRepresentable bridging still receive window-level safeAreaInsets through the parent-VC chain. On the apple-side consumer, this surfaces as ~8px run-to-run vertical translation on UIKit-based previews (PlanetEditorFlowViewController, PhotoUploadViewController/Viewfinder) because safe-area propagation lands at different points relative to the settle loop's intrinsic-size measurement. Negating window.safeAreaInsets via additionalSafeAreaInsets at the outermost windowRootVC zeros the effective safe-area for every descendant before measurement, closing this race class for UIKit-based previews.
Author
|
Closing — apple-side adoption (portolans/apple#6042) showed this approach is too aggressive. Zeroing window.safeAreaInsets via additionalSafeAreaInsets affects every view that reads safe-area for .padding/.ignoresSafeArea, producing 210 baseline regens and an outright test failure. The original PR-#5 layoutMargin pin was correctly scoped; window-level safe-area suppression isn't. Will re-diagnose the underlying issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The existing safe-area pin on
ExpandingViewController.view(PR #5) prevents layout-margin-driven safe-area propagation inside the SwiftUI host. But UIKit-based view controllers placed inside a SwiftUI#Previeware wrapped by SwiftUI'sUIViewControllerRepresentablebridge, which propagates window-levelsafeAreaInsetsdown the parent-VC chain — independent of the host'sdirectionalLayoutMargins.On the apple-side consumer this surfaces as ~8px run-to-run vertical translation in UIKit-based previews. Two known cases:
PlanetEditorFlowViewController(delta on intrinsicContentSize: 2064 vs 2072 — exactly 8px, with every row from 322 onward shifted down 8px in the taller render)PhotoUploadViewController/Viewfinder(~150px run-to-run translation in earlier drift investigations)The 8px figure aligns with
HeaderLayoutUtility.rects(for:)readingview.safeAreaInsets.top + Metrics.edgeInsets.top(edgeInsets.top = 8). WhethersafeAreaInsetslands before or after the settle loop's intrinsic-content-size measurement determines whether the back button (and downstream content) draws 8px lower.What
Sources/SnapshotPreviewsCore/View+Snapshot.swift:setupRootVC(windowRootVC->containerVC->subVC) now uses a customSafeAreaSuppressingViewControllerfor the outer two VCs. ItsviewSafeAreaInsetsDidChangeoverride setsadditionalSafeAreaInsetsto the negation of the window'ssafeAreaInsets. UIKit clamps the resolved value to >= 0, so the effective inset for that VC and all descendants becomes exactly zero.insetsLayoutMarginsFromSafeArea = false/directionalLayoutMargins = .zeropin already applied tosubVC(theExpandingViewController).Together this closes both the layout-margin path (already covered for the host) and the parent-VC
safeAreaInsetspath (newly covered) for UIKit-based previews.Test plan
The fork-side change is byte-deterministic by construction: zeroing safe-area before measurement removes a source of nondeterministic translation. Verification happens on the apple-side adoption PR — a one-time regen of
PlanetEditorFlowViewController/Default/snapshot.pngand possiblyPhotoUploadViewController/Viewfinder/*is the expected positive signal that the fix landed; subsequent CI runs should not regen those files.Note
Medium Risk
Changes how safe-area insets are propagated for all snapshot previews by altering the root view-controller stack, which can shift layout in rendered images. Risk is limited to snapshot rendering behavior and should surface quickly via snapshot diffs.
Overview
Reduces flaky layout shifts in SwiftUI
#Previewsnapshots by suppressing window-derivedsafeAreaInsetsin the outer view-controller stack created bysetupRootVC.The root and container controllers are replaced with a new
SafeAreaSuppressingViewControllerthat negateswindow.safeAreaInsetsviaadditionalSafeAreaInsets, and both outer views now also pininsetsLayoutMarginsFromSafeArea = falseanddirectionalLayoutMargins = .zero.Reviewed by Cursor Bugbot for commit dd7e26e. Bugbot is set up for automated code reviews on this repo. Configure here.