Skip to content

Capture screenshots from the correct window and gate on system memory - #217

Merged
mbarta merged 1 commit into
mainfrom
screenshot-window-and-memory-check
Sep 21, 2026
Merged

mbarta merged 1 commit into
mainfrom
screenshot-window-and-memory-check

Conversation

@mbarta

@mbarta mbarta commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Combines and extends #209 and #216.

Problem

Two independent reasons a destination ends up without a screenshot backdrop during navigation:

Fix

  • HotwireWebFragmentDelegate.screenshotView() resolves the window — the dialog's own window for a DialogFragment, the Activity's otherwise — and passes it to the holder. The capture is skipped when the view is no longer attached, which is the case for the second detach during a dialog cancel.
  • The memory check uses ActivityManager.MemoryInfo: skip when lowMemory is set or when the bitmap would push availMem under threshold. Bitmap.createBitmap is wrapped to catch a failed native allocation.
  • A skipped capture now logs viewScreenshotSkipped with the values at hand instead of returning silently.

Testing

  • HotwireViewScreenshotHolderTest covers the memory gate: headroom, lowMemory, crossing the threshold, and reaching it exactly.
  • Verified in the demo app on an emulator: bottom sheet dismiss keeps its own content while sliding out (previously showed the numbers list behind it); full-screen modal push and pop still capture from the Activity window; swipe-down dismiss produces no capture and no skip log.

Screenshots of a DialogFragment destination were copied from the Activity
window, which captured the screen behind the dialog. Resolve the dialog's
own window in the delegate and pass it to the screenshot holder.

The memory check compared the Java heap footprint to its maximum, which
refused every capture once the heap had grown, however much was free.
Bitmap pixels live on the native heap, so the Java heap never reflected
the cost anyway. Gate on ActivityManager.MemoryInfo instead, catch a
failed native allocation, and log skipped captures.

Skip the capture when the view is no longer attached, which is the case
for the second detach during a dialog cancel.
@mbarta
mbarta requested a review from jayohms September 16, 2026 10:00
@mbarta mbarta self-assigned this Sep 16, 2026
@mbarta
mbarta merged commit df29a60 into main Sep 21, 2026
1 check passed
@mbarta
mbarta deleted the screenshot-window-and-memory-check branch September 21, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant