Skip to content

fix(🤖): clip HorizontalScrollView in makeImageFromView snapshots#3862

Open
hirvesh wants to merge 2 commits into
Shopify:mainfrom
hirvesh:fix/android-clip-horizontal-scrollview-screenshot
Open

fix(🤖): clip HorizontalScrollView in makeImageFromView snapshots#3862
hirvesh wants to merge 2 commits into
Shopify:mainfrom
hirvesh:fix/android-clip-horizontal-scrollview-screenshot

Conversation

@hirvesh
Copy link
Copy Markdown

@hirvesh hirvesh commented May 26, 2026

Context

makeImageFromView on Android composites the view tree in ViewScreenshotService. While descending, it clips scroll containers to their viewport so off-screen content isn't drawn:

if (view instanceof ScrollView) {
    ...
    canvas.clipRect(clipLeft, clipTop, clipRight, clipBottom);
}

Problem

HorizontalScrollView does not extend ScrollView — both extend FrameLayout. So a horizontal scroll container never matches this check and is never clipped. When it contains a child larger than its viewport — e.g. a wide Skia <Canvas>, which renders into a TextureView and is blitted at full surface size in drawTextureView — the child bleeds past the viewport all the way to the output bitmap edge in the captured image.

Repro: a horizontally-scrollable Skia <Canvas> whose content is wider than the screen, captured via makeImageFromView. The captured image shows the canvas overrunning its container's right edge. iOS is unaffected (it captures through the live layer tree's clip).

Fix

Check HorizontalScrollView in the same branch. getScrollX/getScrollY/getWidth/getHeight are all View methods, so the existing clip-rect math is unchanged (the now-unnecessary ScrollView cast is dropped).

if (view instanceof ScrollView || view instanceof HorizontalScrollView) {
    int clipLeft = view.getScrollX();
    ...
}

Verified against the overflow repro on a physical Pixel 9a (new architecture): the captured Skia canvas is now correctly clipped to the horizontal ScrollView viewport, matching iOS.

ViewScreenshotService clips scroll containers to their viewport while
compositing the view tree, but only checks `instanceof ScrollView`.
HorizontalScrollView does not extend ScrollView (both extend FrameLayout),
so a horizontal scroll container was never clipped: an oversized child such
as a wide Skia <Canvas> (a TextureView) inside one bled past its viewport to
the output bitmap edge in the captured image.

Clip HorizontalScrollView as well; getScrollX/Y/getWidth/getHeight are
View methods so the existing clip math works unchanged (the ScrollView
cast is dropped). iOS is unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants