Repository navigation
feat(iOS) - url function support in backgroundImage - #58248
intergalacticspacehighway wants to merge 1 commit into
Conversation
d123490 to
f4d9407
Compare
fe224a5 to
83c2b1d
Compare
Visual regressionNo visual differences at ios: no capture |
|
|
||
| CALayer *imageLayer = [CALayer layer]; | ||
| imageLayer.contents = (__bridge id)image.CGImage; | ||
| imageLayer.bounds = swapsAxes ? CGRectMake(0, 0, size.height, size.width) : CGRectMake(0, 0, size.width, size.height); |
There was a problem hiding this comment.
The layer never sets contentsScale, so on a Retina display the decoded image rasterizes at 1x. Could you set itemLayer.contentsScale = image.scale (and the same on the inner imageLayer)?
There was a problem hiding this comment.
I think we can avoid setting it, since these layers only display an already-decoded bitmap stretched to their bounds, so contentsScale has no effect. Also, image.scale is always 1 here, so it would be a no-op.
|
|
||
| - (void)setImageManager:(std::shared_ptr<ImageManager>)imageManager | ||
| { | ||
| _imageManager = std::move(imageManager); |
There was a problem hiding this comment.
Recycled views keep the manager they were created with--if setImageManager: ever re-fires, pooled views would hold a stale ImageManager, putting two queues on one RCTImageLoader. Worth setting the manager on every dequeue, not just newly created views?
There was a problem hiding this comment.
Good point. Today it is set only once, before any view exists, but I moved it to every dequeue so recycled views always get the current manager. Fixed in 65a1222.
## 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 #58246 (JS/parser) and #58248 (iOS) into this one.
> Recreated from #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`
## Test Plan:
- Merge #58246, this PR and #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`.
Differential Revision: D131256210
Pull Request resolved: #58247
Adds support for loading images with url() syntax on iOS, for example
`backgroundImage: url("https://example.com/1.png")`.
RCTViewComponentView loads the url() images when it receives props,
through the same ImageManager pipeline as the Image component.
RCTBackgroundImageURLLoader keeps one request per unique url, and
cancels a request when its url is removed or the view is recycled or
deallocated. background-repeat: round now uses at least one tile, as
CSS requires.
65a1222 to
4b60a75
Compare
Summary:
Note
iOS CI fails until #58246 (JS/parser) is merged. This PR uses the
URLBackgroundImagetype that #58246 adds.urlsyntax. e.g.backgroundImage: url("https://example.com/1.png").background-repeat: roundnow uses at least one tile, as CSS requires. This also changes gradients whose tile is more than twice the size of the box.urlfunction support inbackgroundImage#58246 (JS/parser) and feat(android) -urlfunction support inbackgroundImage#58247 (Android).How:
RCTViewComponentViewloads theurl()images when it receives props, through the sameImageManagerpipeline as the Image component.RCTBackgroundImageURLLoaderkeeps one request per unique url. It cancels a request when its url is removed, or when the view is recycled or deallocated.RCTSurfacePresenterputs one sharedImageManagerin the context container, unless the app already added one.<Image>now uses thisImageManagertoo.RCTMountingManagerpasses theImageManagertoRCTComponentViewRegistry, which gives it to each newRCTViewComponentView.Changelog:
[IOS] [ADDED] -
urlsupport withbackgroundImageTest Plan:
urlfunction support inbackgroundImage#58246, feat(android) -urlfunction support inbackgroundImage#58247 and this PR, then test the examples added in the JS PR.RNTesterUnitTests/RCTBackgroundImageUtilsTests.mm.Screenshots
Each
url()example in RN Tester, opened by deep link, on the iOS simulator, with all three PRs merged:Follow-ups
coverandcontainsupport forbackgroundSize.