Skip to content

Comments

Pin screenshot dimensions to fixed dp size#48

Draft
EmilioBejasa wants to merge 12 commits intomainfrom
fix/pin-screenshot-dimensions
Draft

Pin screenshot dimensions to fixed dp size#48
EmilioBejasa wants to merge 12 commits intomainfrom
fix/pin-screenshot-dimensions

Conversation

@EmilioBejasa
Copy link
Collaborator

Summary

  • Uses ViewHelpers.setupView() to layout the content view at a fixed 360x640dp before snapping screenshots
  • Snaps android.R.id.content instead of decorView.rootView to exclude status/navigation bars
  • Both dimensions are overridable via getScreenshotWidthDp() and getScreenshotHeightDp()
  • Fixes Screenshotbot showing dimension mismatches between CI runs due to varying emulator screen sizes

Test plan

  • CI screenshot tests pass (draft PR to verify)
  • Screenshotbot shows consistent dimensions across runs

🤖 Generated with Claude Code

EmilioBejasa and others added 12 commits February 18, 2026 14:12
Use ViewHelpers to layout the content view at a fixed 360x640dp
before snapping, so screenshots are consistent regardless of
emulator screen size. Also snaps android.R.id.content instead of
the decor view root to exclude the status and navigation bars.

Both dimensions are overridable via getScreenshotWidthDp() and
getScreenshotHeightDp().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Get the first child of the content FrameLayout (the React Native
root view) to exclude status bar and navigation bar black bars
from screenshots.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Draw the full window to a Bitmap, then use the content view's
global visible rect to crop out the status bar and navigation
bar. The cropped result is rendered in an ImageView at fixed
dp dimensions before snapping.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
getGlobalVisibleRect returns full screen bounds with edge-to-edge
rendering. Use WindowInsets.Type.statusBars/navigationBars to get
exact pixel insets for cropping.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
FIT_CENTER was adding gray bars when the cropped bitmap's aspect
ratio didn't exactly match the target dp size.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Scale the system-bar-cropped bitmap to exact target pixel dimensions
before rendering in ImageView, eliminating any size mismatch that
caused letterboxing bars.

Apply the same crop-and-scale approach to ScreenshotTest.testActualApp
so all screenshots are bar-free and consistently sized.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
WindowInsets may return 0 in instrumentation test context. Use
resources.getIdentifier for status_bar_height and
navigation_bar_height which work reliably regardless of context.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
android.R.id.content is positioned between system bars, so no bitmap
manipulation or inset calculation is needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
android.R.id.content is full-screen-sized in AppCompat; system bar
heights are applied as padding to it. Its first child (the React root
view) is already sized to the usable area between bars.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This API directly returns the rect between system bars without any
guessing about inset heights or view hierarchy navigation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant