Repository navigation
Drop Drawee from Android background image loading - #60411
Open
Abbondanzo wants to merge 3 commits into
Open
Abbondanzo wants to merge 3 commits into
Abbondanzo wants to merge 3 commits into
Conversation
) 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
|
@Abbondanzo has exported this pull request. If you are a Meta employee, you can view the originating Diff in D135152979. |
Visual regressionNo visual differences at 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
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.
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 fromImagePipelineFactory, 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