Skip to content

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

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

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

Conversation

@hirvesh

@hirvesh hirvesh commented May 26, 2026

Copy link
Copy Markdown

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.
@wcandillon

Copy link
Copy Markdown
Contributor

That looks great! Can you sign the CLA?

@hirvesh

hirvesh commented Jun 24, 2026

Copy link
Copy Markdown
Author

I have signed the CLA! :) @wcandillon

@wcandillon

Copy link
Copy Markdown
Contributor

@hirvesh Thank You :) We are working on some improvements to makeImageFromView snapshots, being the scenes

@wcandillon

Copy link
Copy Markdown
Contributor

@hirvesh it doesn't look like the CLA has been signed

@hirvesh

hirvesh commented Jun 24, 2026

Copy link
Copy Markdown
Author

I have signed on both contributor accounts, but it keeps saying I haven't 🤔
CleanShot 2026-06-24 at 12 36 47@2x

@wcandillon

Copy link
Copy Markdown
Contributor

@hirvesh I see hirvesh as username?

@hirvesh

hirvesh commented Jun 24, 2026

Copy link
Copy Markdown
Author

@wcandillon - Did for both usernames, still failing the CLA check

CleanShot 2026-06-24 at 18 09 35@2x

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