Skip to content

fix(snapshots): Derive screen orientation from the preview dimensions - #1458

Merged
runningcode merged 4 commits into
mainfrom
no/snapshots-preview-orientation
Sep 24, 2026
Merged

runningcode merged 4 commits into
mainfrom
no/snapshots-preview-orientation

Conversation

@runningcode

@runningcode runningcode commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Wide previews came out sideways. @Preview(widthDp = 300, heightDp = 200) produced a snapshot 200 wide and 300 tall.

Why: Every snapshot was told the screen is in portrait (tall) unless the device said otherwise. The renderer (layoutlib) then flips the width and height so the screen matches that orientation. A wide preview was therefore turned tall.

Fix: Pick the orientation from the final size: wider than tall means landscape, otherwise portrait.

One catch: a device like spec:width=411dp,height=891dp,orientation=landscape is still given in portrait numbers and relies on the orientation to be turned. Those numbers are now rotated first, so landscape devices stay landscape. The same rotation now also sizes the content area when showSystemUi = true, which previously stayed tall on landscape devices.

What changes: Only previews that end up wider than tall. For example, 300x200 now renders 825x550 px instead of 550x825. A landscape device with only widthDp set now uses the landscape height. Everything else keeps its size. Existing baselines for the affected previews need to be re-recorded.

Verified the orientation fix with SAGP + Paparazzi 2.0.0-alpha05 against previews covering sized, width-only, unsized, showSystemUi, and landscape/wide device specs. The showSystemUi content-size fix is covered only by a unit test on the generated code so far.

Found while investigating #1456. Independent of #1457.

🤖 Generated with Claude Code

runningcode and others added 2 commits September 23, 2026 13:49
The generated test took the screen orientation from the parsed device,
which is portrait by default. Layoutlib swaps the screen dimensions to
match the orientation, so a preview wider than it is tall, like
@Preview(widthDp = 300, heightDp = 200), rendered at 200x300.

Derive the orientation from the final screen size instead. A device
spec with orientation=landscape keeps its portrait dimensions, so rotate
them first to keep landscape devices rendering in landscape.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@runningcode
runningcode force-pushed the no/snapshots-preview-orientation branch from edc25b8 to 04d840c Compare September 23, 2026 11:49

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 04d840c. Configure here.

…tion

With showSystemUi, the content box was sized from the raw device
dimensions. A spec with orientation=landscape keeps its portrait
dimensions, so the box stayed portrait while the screen rendered in
landscape.

Share the rotation logic with the screen dimensions so both agree.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@runningcode runningcode added the sanity-check PR needs a lightweight review for obvious issues label Sep 24, 2026

@markushi markushi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@runningcode
runningcode merged commit c2e39e4 into main Sep 24, 2026
27 checks passed
@runningcode
runningcode deleted the no/snapshots-preview-orientation branch September 24, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sanity-check PR needs a lightweight review for obvious issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants