Skip to content

fix: GraniteImage layout on reused cells#299

Merged
jingjing2222 merged 3 commits into
mainfrom
fix-android-image
May 20, 2026
Merged

fix: GraniteImage layout on reused cells#299
jingjing2222 merged 3 commits into
mainfrom
fix-android-image

Conversation

@jingjing2222
Copy link
Copy Markdown
Collaborator

Cause

Some images were not visible on virtualized list screens

The exact flow was:

  1. FlashList/RN reuses a cell.
  2. The outer GraniteImage already has a 498x498 layout area.
  3. The source prop changes and GraniteImage.loadImageIfReady() runs.
  4. The previous internal ImageView is removed with removeView().
  5. A new internal ImageView is added with addView().
  6. Coil successfully sets the bitmap on the new ImageView.
  7. However, after the new ImageView is added, measure/layout does not run again, so it remains 0x0.
  8. As a result, only the parent/wrapper background is visible instead of the image.

In other words, during virtual list cell reuse, the outer GraniteImage managed by RN/Fabric had the correct size, but the newly replaced native child ImageView inside GraniteImage did not receive layout.

The diagnostic logs confirmed that Coil loading succeeded, but the internal ImageView still had a 0x0 size.

event=coil_success ... size=0x0 measured=0x0 ... drawable=BitmapDrawable ... bitmap=600x600

Fix

After adding the provider-created internal ImageView, this change immediately measures and lays it out to the current parent GraniteImage bounds when the parent already has a size.

addView(imageView)
containerView = imageView
layoutContainerViewIfPossible(imageView)

This ensures that when only the internal child View is replaced while the outer View is already laid out, the new ImageView does not stay at 0x0 and can draw using the parent bounds.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

🦋 Changeset detected

Latest commit: b52108f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 28 packages
Name Type
@granite-js/image Patch
@granite-js/native Patch
@granite-js/blur-view Patch
@granite-js/jest Patch
@granite-js/react-native Patch
@granite-js/style-utils Patch
babel-preset-granite Patch
create-granite-app Patch
@granite-js/brownfield-module Patch
@granite-js/cli Patch
@granite-js/cookies Patch
@granite-js/screen Patch
@granite-js/lottie Patch
@granite-js/mpack Patch
@granite-js/naver-map Patch
@granite-js/plugin-core Patch
@granite-js/plugin-env Patch
@granite-js/plugin-hermes Patch
@granite-js/plugin-micro-frontend Patch
@granite-js/plugin-router Patch
@granite-js/plugin-rozenite Patch
@granite-js/plugin-sentry Patch
@granite-js/utils Patch
@granite-js/video Patch
@granite-js/vitest Patch
@granite-js/deployment-manager Patch
@granite-js/forge-cli Patch
@granite-js/pulumi-aws Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented May 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
granite-docs Ready Ready Preview, Comment May 20, 2026 1:46am

Request Review

@jingjing2222 jingjing2222 marked this pull request as draft May 19, 2026 13:17
@jingjing2222 jingjing2222 marked this pull request as ready for review May 19, 2026 16:27
@jingjing2222 jingjing2222 merged commit 0eb0277 into main May 20, 2026
7 checks passed
@jingjing2222 jingjing2222 deleted the fix-android-image branch May 20, 2026 02:45
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.

2 participants