Repository navigation
[iOS] Fix NaN passed to CoreGraphics for outset boxShadow with negative spread on small views - #60323
Conversation
A negative spread larger than half the view made CGRectInset return CGRectNull, which reached CGPathAddArc as NaN. Cap each axis's inset at half the layer size so the rect collapses to zero, centred on the layer, as it did before react#50636. Fixes react#60302.
|
Hi @harpreetkbadhan! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D135061332. |
Visual regressionNo visual differences at android: no capture |
zeyap
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
This pull request was successfully merged by @harpreetkbadhan in 0fcf6ec When will my fix make it into a release? | How to file a pick request? |
Summary:
Fixes #60302.
On iOS, an outset
boxShadowwith a negative spread logs CoreGraphicsinvalid 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'sshadow-smis enough to trigger it, because its second layer has-1pxspread.RCTGetOutsetBoxShadowLayerbuilds the shadow rect withCGRectInset(bounds, -spread, -spread). When that would make the width or height negative,CGRectInsetreturnsCGRectNull(origin at infinity). The null rect then goes intoRCTPathCreateWithRoundedRectfor both the shadow path and the padded mask path, andCGPathAddArcreceives NaN. This has been happening since #50636 (0.80). Before that, the shadow rect size was clamped withfmax(…, 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,
CGRectInsetgets exactly the same arguments as before, so zero, positive and small negative spreads are unchanged. With a zero-sized rect,RCTPathCreateWithRoundedRectalready clamps every corner radius to 0, so no NaN reaches CoreGraphics. The inset branch in the same file already handles this case with aCGRectIsNullcheck.Changelog:
[IOS] [FIXED] - Fix NaN passed to CoreGraphics when an outset
boxShadowwith negative spread is applied to a view smaller than the spread, e.g. a zero-sized viewTest Plan:
Added
React/Tests/Fabric/RCTBoxShadowTests.mm(5 tests), which checks the shadow path and mask path bounds fromRCTGetBoxShadowLayer:-1spread → 98×0 rect, centred)To run them, I enabled the
React-RCTFabrictest spec locally (:testspecs => ['Tests']inscripts/cocoapods/fabric.rb), ranpod installinpackages/rn-tester(pluspod update hermes-engine --no-repo-updateto match the local Hermes version), then:{{inf, inf}, {0, 0}}, and the log has 16invalid numeric value (NaN…) to CoreGraphics APImessages, 8 per failing test, matching the issue's 2 paths × 4 corner arcs.Executed 27 tests, with 0 failures, covering all ofReact/Tests/Fabric, including the existingRCTGradientUtilsTestsandAppleEventBeatTests. No CoreGraphics NaN messages.Notes:
RCTGradientUtilsTests(Interpolate gradient color stops outside the 0–100% range #59774).Tests/**/*.mmglob, the test spec currently fails to compile onmainfor an unrelated reason:React/Tests/Text/RCTSelectableParagraphComponentViewTests.mmcan't findreact/renderer/element/ComponentBuilder.h. I narrowed the glob toTests/Fabric/*.mmlocally to run these tests. That change is not part of this PR.yarn format-check-cpppasses.