Skip to content

Drop Drawee from Android background image loading - #60411

Open
Abbondanzo wants to merge 3 commits into
react:mainfrom
Abbondanzo:export-D135152979
Open

Abbondanzo wants to merge 3 commits into
react:mainfrom
Abbondanzo:export-D135152979

Conversation

@Abbondanzo

Copy link
Copy Markdown
Contributor

Summary:
The url() background image loader used Drawee only to reach the image pipeline and to defer releasing a bitmap. It now gets the same pipeline from ImagePipelineFactory, and releases the bitmap on the next main-thread turn, which is what the Drawee releaser does on the UI thread. Background images now depend on the image pipeline alone.

Changelog: [Internal]

Differential Revision: D135152979

)

Summary:
- Adds support for loading images with `url` syntax. e.g. `backgroundImage: url("https://example.com/1.png")`.
- `background-repeat: round` now uses at least one tile, as CSS requires. This also changes gradients whose tile is more than twice the size of the box.
- This PR only includes android code changes. To fully test the PR, merge react#58246 (JS/parser) and react#58248 (iOS) into this one.

> Recreated from react#54994, which was auto-closed when my fork was deleted. GitHub does not allow reopening a PR whose head repository is gone. Rebased onto current `main`.

### How:
Uses Fresco's image pipeline to fetch the image in `BackgroundImageURLLoader`. Keeps Fresco's `CloseableReference` open and draws the shared bitmap in the `BackgroundImageDrawable` canvas using `drawBitmap`, like Fresco's drawee. Background images with the same url share one bitmap. The reference is released when the url changes or the view is dropped.

## Changelog:

[ANDROID] [ADDED] - `url` support with `backgroundImage`

Pull Request resolved: react#58247

Test Plan:
- Merge react#58246, this PR and react#58248, then test the examples added in the JS PR.
- Added unit tests: `./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.uimanager.drawable.*' --tests 'com.facebook.react.uimanager.style.BackgroundImageLayerTest'`

### Screenshots

Each `url()` example in RN Tester, opened by deep link, on the Android emulator, with all three PRs merged:

| URL Image | URL Image from local file | Local file at its natural size (3x asset, 33x33) |
| --- | --- | --- |
| <img src="https://raw.githubusercontent.com/intergalacticspacehighway/react-native/c7893b2cc494b383efc609a82f71b1ceda0e6411/android-1.png" width="100" /> | <img src="https://raw.githubusercontent.com/intergalacticspacehighway/react-native/c7893b2cc494b383efc609a82f71b1ceda0e6411/android-2.png" width="100" /> | <img src="https://raw.githubusercontent.com/intergalacticspacehighway/react-native/c7893b2cc494b383efc609a82f71b1ceda0e6411/android-3.png" width="100" /> |

### Follow-ups

- Decode images at the size they are drawn, instead of full size.
- `cover` and `contain` support for `backgroundSize`.

Reviewed By: andrewdacenko

Differential Revision: D131256210

Pulled By: Abbondanzo
Summary:
Building an image request validates its uri and throws for one the pipeline can't load, such as a `res:` uri without a resource id. That ran in the `backgroundImage` prop setter on the UI thread, so a bad style value crashed the app. The loader now logs a warning and skips that layer, like any other failed load.

Also replaces `conic-gradient` as the unknown layer type in a parsing test with a made-up type, since conic gradients are supported now.

Changelog: [Internal]

Differential Revision: D135152981
Summary:
The `url()` background image loader used Drawee only to reach the image pipeline and to defer releasing a bitmap. It now gets the same pipeline from `ImagePipelineFactory`, and releases the bitmap on the next main-thread turn, which is what the Drawee releaser does on the UI thread. Background images now depend on the image pipeline alone.

Changelog: [Internal]

Differential Revision: D135152979
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 30, 2026
@meta-codesync

meta-codesync Bot commented Nov 30, 2026

Copy link
Copy Markdown

@Abbondanzo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D135152979.

@github-actions

Copy link
Copy Markdown

Visual regression

No visual differences at 4e744d227c51.

ios: no capture

Abbondanzo added a commit to Abbondanzo/react-native that referenced this pull request Dec 2, 2026
Summary:

The `url()` background image loader used Drawee only to reach the image pipeline and to defer releasing a bitmap. It now gets the same pipeline from `ImagePipelineFactory`, and releases the bitmap on the next main-thread turn, which is what the Drawee releaser does on the UI thread. Background images now depend on the image pipeline alone.

Changelog: [Internal]

Differential Revision: D135152979

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants