Repository navigation
Use CA shadow apis for box shadow - #50636
Closed
joevilches wants to merge 1 commit into
Closed
joevilches wants to merge 1 commit into
joevilches wants to merge 1 commit into
Conversation
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D72823334 |
joevilches
force-pushed
the
export-D72823334
branch
from
April 10, 2025 23:26
f68dfeb to
9803790
Compare
Summary: Pull Request resolved: react#50636 A while ago someone on GitHub reported that box shadow on iOS was causing frame drops when animating a large, pretty blurry shadow: react#49128. This week I finally got around to fixing this! The slowness was happening since we were using CG to draw this shadow, which is very CPU intensive and, to my knowledge, does not take advantage of GPUs to do anything. Couple that with an animating, large, blurry shadow and we have frame issues. These shadows were taking very long to draw, to get the image of the shadow (which then needs to be copied into some texture 3 times as big, composited, put on the screen etc) took 12-14ms :o, thats very slow. To fix this I figured out how to get CA's shadow APIs working, which take advantage of the GPU. The enable inset shadows and spread you have to get creative with a mix of `shadowPath` and `mask` with a `CAShapeLayer`, but we got it done! Things are much faster, I am not sure how to time this but using a real device shows no frame drops :D Changelog: [iOS][Fixed] - Box shadows on iOS are faster Reviewed By: lenaic Differential Revision: D72823334
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D72823334 |
joevilches
force-pushed
the
export-D72823334
branch
from
April 10, 2025 23:33
9803790 to
305076c
Compare
Contributor
|
This pull request has been merged in 52173ab. |
Collaborator
|
This pull request was successfully merged by @joevilches in 52173ab When will my fix make it into a release? | How to file a pick request? |
uffoltzl
pushed a commit
to uffoltzl/react-native
that referenced
this pull request
Apr 18, 2025
Summary: Pull Request resolved: react#50636 A while ago someone on GitHub reported that box shadow on iOS was causing frame drops when animating a large, pretty blurry shadow: react#49128. This week I finally got around to fixing this! The slowness was happening since we were using CG to draw this shadow, which is very CPU intensive and, to my knowledge, does not take advantage of GPUs to do anything. Couple that with an animating, large, blurry shadow and we have frame issues. These shadows were taking very long to draw, to get the image of the shadow (which then needs to be copied into some texture 3 times as big, composited, put on the screen etc) took 12-14ms :o, thats very slow. To fix this I figured out how to get CA's shadow APIs working, which take advantage of the GPU. The enable inset shadows and spread you have to get creative with a mix of `shadowPath` and `mask` with a `CAShapeLayer`, but we got it done! Things are much faster, I am not sure how to time this but using a real device shows no frame drops :D Changelog: [iOS][Fixed] - Box shadows on iOS are faster Reviewed By: lenaic Differential Revision: D72823334 fbshipit-source-id: 460339c9d77e7423ce59a1a9178b6b3ad527e4b0
meta-codesync Bot
pushed a commit
that referenced
this pull request
Dec 1, 2026
…ve spread on small views ## Summary: Fixes #60302. On iOS, an outset `boxShadow` with a negative spread logs CoreGraphics `invalid numeric value (NaN)` errors when the view is smaller than twice the spread on either axis. The most common case is a view with zero size, such as the first frame of a measure-then-animate indicator. Tailwind's `shadow-sm` is enough to trigger it, because its second layer has `-1px` spread. `RCTGetOutsetBoxShadowLayer` builds the shadow rect with `CGRectInset(bounds, -spread, -spread)`. When that would make the width or height negative, `CGRectInset` returns `CGRectNull` (origin at infinity). The null rect then goes into `RCTPathCreateWithRoundedRect` for both the shadow path and the padded mask path, and `CGPathAddArc` receives NaN. This has been happening since #50636 (0.80). Before that, the shadow rect size was clamped with `fmax(…, 0)`. This change caps each axis's inset at half the layer's size, so a negative spread can shrink the rect to zero but not past it. The rect stays centred on the layer, as in 0.79. For any spread that doesn't overshrink the rect, `CGRectInset` gets exactly the same arguments as before, so zero, positive and small negative spreads are unchanged. With a zero-sized rect, `RCTPathCreateWithRoundedRect` already clamps every corner radius to 0, so no NaN reaches CoreGraphics. The inset branch in the same file already handles this case with a `CGRectIsNull` check. ## Changelog: [IOS] [FIXED] - Fix NaN passed to CoreGraphics when an outset `boxShadow` with negative spread is applied to a view smaller than the spread, e.g. a zero-sized view ## Test Plan: Added `React/Tests/Fabric/RCTBoxShadowTests.mm` (5 tests), which checks the shadow path and mask path bounds from `RCTGetBoxShadowLayer`: - a zero-sized layer with negative spread gives an empty shadow rect at the offset, and the mask still includes the padded rect - each axis is clamped on its own (100×1 layer with `-1` spread → 98×0 rect, centred) - small negative, zero and positive spread give the same rects as before To run them, I enabled the `React-RCTFabric` test spec locally (`:testspecs => ['Tests']` in `scripts/cocoapods/fabric.rb`), ran `pod install` in `packages/rn-tester` (plus `pod update hermes-engine --no-repo-update` to match the local Hermes version), then: ``` xcodebuild test -workspace RNTesterPods.xcworkspace -scheme React-RCTFabric-Unit-Tests -destination 'platform=iOS Simulator,…' ``` - Before the fix: 3 of 5 new tests fail. The shadow path bounds are `{{inf, inf}, {0, 0}}`, and the log has 16 `invalid numeric value (NaN…) to CoreGraphics API` messages, 8 per failing test, matching the issue's 2 paths × 4 corner arcs. - After the fix: `Executed 27 tests, with 0 failures`, covering all of `React/Tests/Fabric`, including the existing `RCTGradientUtilsTests` and `AppleEventBeatTests`. No CoreGraphics NaN messages. Notes: - CI does not build this test spec, the same as `RCTGradientUtilsTests` (#59774). - With the full `Tests/**/*.mm` glob, the test spec currently fails to compile on `main` for an unrelated reason: `React/Tests/Text/RCTSelectableParagraphComponentViewTests.mm` can't find `react/renderer/element/ComponentBuilder.h`. I narrowed the glob to `Tests/Fabric/*.mm` locally to run these tests. That change is not part of this PR. - `yarn format-check-cpp` passes. - Not run: the issue's Snack in RNTester while watching the simulator logs. Differential Revision: D135061332 Pull Request resolved: #60323
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:
A while ago someone on GitHub reported that box shadow on iOS was causing frame drops when animating a large, pretty blurry shadow: #49128. This week I finally got around to fixing this!
The slowness was happening since we were using CG to draw this shadow, which is very CPU intensive and, to my knowledge, does not take advantage of GPUs to do anything. Couple that with an animating, large, blurry shadow and we have frame issues. These shadows were taking very long to draw, to get the image of the shadow (which then needs to be copied into some texture 3 times as big, composited, put on the screen etc) took 12-14ms :o, thats very slow.
To fix this I figured out how to get CA's shadow APIs working, which take advantage of the GPU. The enable inset shadows and spread you have to get creative with a mix of
shadowPathandmaskwith aCAShapeLayer, but we got it done! Things are much faster, I am not sure how to time this but using a real device shows no frame drops :DChangelog: [iOS][Fixed] - Box shadows on iOS are faster
Differential Revision: D72823334