Repository navigation
fix(snapshots): Derive screen orientation from the preview dimensions - #1458
Merged
Merged
Conversation
runningcode
requested review from
0xadam-brown,
adinauer,
markushi and
romtsn
as code owners
September 23, 2026 08:11
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
force-pushed
the
no/snapshots-preview-orientation
branch
from
September 23, 2026 11:49
edc25b8 to
04d840c
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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>
markushi
approved these changes
Sep 24, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This was referenced Sep 24, 2026
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.

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=landscapeis 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 whenshowSystemUi = 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
widthDpset 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. TheshowSystemUicontent-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