fix(android): build renderInto's destination Rect from edges, not size - #164
Open
dazakdev wants to merge 1 commit into
Open
fix(android): build renderInto's destination Rect from edges, not size#164dazakdev wants to merge 1 commit into
dazakdev wants to merge 1 commit into
Conversation
android.graphics.Rect takes (left, top, right, bottom), so passing `width`
and `height` into the right/bottom slots drew the image at (width - x) by
(height - y), and drew nothing at all once x >= width. The spec documents
these arguments as a size ("scaled to the given width and height") and iOS
implements them that way with CGRect(x:y:width:height:), so Android was the
outlier.
Adds the renderInto coverage that would have caught it: image-transforms had
no test for it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
dazakdev
marked this pull request as ready for review
August 10, 2026 10:30
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.
What
HybridImage.renderInto()builds its destination rectangle asRect(x, y, width, height).android.graphics.Recttakes(left, top, right, bottom), sowidth/heightland in the edge slots: the drawn size becomes(width β x) Γ (height β y), and oncex >= widththe rect inverts and nothing is drawn at all. Onlyx = y = 0is unaffected, which is why existing usage looks fine.These arguments are a size, not edges:
Image.nitro.tsdocuments them as one β "at the givenxandyposition, scaled to the givenwidthandheight"NativeImage.swiftusesCGRect(x:y:width:height:)crop(startX, startY, endX, endY)Drawing a 200x200 sprite into a 400x400 image at
(100, 100): documented 200x200, Android drew 100x100. At(300, 300), nothing was drawn.Fix
No API change, iOS untouched.
Test
image-transforms.harness.tscoveredresize,crop,rotateandmirrorHorizontallybut had norenderIntocase, which is why this went unnoticed. Added one: a red sprite drawn at(20, 20)sized60x60, three sampled pixels. The pixel reader is local to the test β the equivalent helper inimage-raw-pixel-data.harness.tsis file-local and not exported.On
mainit fails on the far corner (expected false to be trueβ the pixel at (75, 75) is still background); with the fix applied it passes. Verified by stashing the Kotlin change, rebuilding the app and re-running, so the test is known to exercise the changed code path.Run locally on an arm64 API 35 emulator rather than CI's x86_64. No iOS code is touched, so the iOS harness is left to CI.
Note for consumers
This is a behaviour fix. Code that compensated for it on Android by passing
(x + width, y + height)must drop the compensation.Standalone repro, without cloning the monorepo: https://github.com/dazakdev/nitro-image-renderinto-repro
Right now it looks like this:
π€ Generated with Claude Code