Skip to content

Paint iOS box shadows below child content - #60366

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
expo:@ide/ios-box-shadow-paint-order
Dec 1, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
expo:@ide/ios-box-shadow-paint-order

Conversation

@ide

@ide ide commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

On iOS a boxShadow draws over the view's children when the view has no border layer, as a view with no border does. Each shadow layer gets _borderLayer.zPosition, so without a border layer it gets 0, the same as the children, and it is added after them. An inset ring that an opaque child should cover shows over the child, and an outset shadow covers the part of a child that overflows the view.

CSS paints box shadows below the element's content: inset shadows immediately above its background and below its border, outset shadows immediately below its background (css-backgrounds-3). This change gives the shadow layers a fixed z-position between the background layers (BACKGROUND_COLOR_ZPOSITION) and the border layer. Outset shadows therefore sit above the background, unlike CSS, but they are masked to the outside of the border box, where there is no background, so the difference is not visible.

Views with a border layer already drew shadows below the children; their shadows now sit just below the border layer instead of level with it, which is not visible either, since an inset shadow is masked to the inside of the padding box.

Changelog:

[IOS] [FIXED] - Draw boxShadow below the view's children when the view has no separate border layer: an inset shadow no longer covers them, and an outset shadow no longer covers a child that overflows the view

Test Plan:

testInsetBoxShadowIsBelowChildrenWithoutBorderLayer in RCTViewComponentViewTests is new. With RCTViewComponentView.mm from main it fails (0 is not less than 0). Run with Xcode 27.1 on an iOS 27.0 simulator; RNTester builds:

xcodebuild test -workspace packages/rn-tester/RNTesterPods.xcworkspace -scheme React-RCTFabric-Unit-Tests \
  -destination 'platform=iOS Simulator,id=<iPhone 18 Pro>'

RNTester's Podfile does not install the React-RCTFabric Tests test spec. To run it (locally, not in this change): add :testspecs => ['Tests'] to that pod in scripts/cocoapods/fabric.rb, narrow the test spec's source_files to this test file (RCTSelectableParagraphComponentViewTests.mm does not compile in open source), and add an empty Swift file to it so the bundle links the Swift runtime RCTSwiftUI needs.

Not checked on screen. In RNTester, take a view with no border and an opaque child. With boxShadow: 'inset 0 0 0 8px black' and a child that fills the view, a black ring shows over the child before and not after. With boxShadow: '0 0 0 8px black' and a child that extends past the view's edge, the shadow shows over the overflow before and not after.

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 28, 2026
@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 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Visual regression

No visual differences at 3c058a2bc043.

android: no capture

A `boxShadow` drew over the view's children when the view had no border
layer. Each shadow layer copied `_borderLayer.zPosition`, and a view
whose border Core Animation draws (no border, or a uniform border on a
clipping view) has no border layer, so the shadow got z-position 0.
Children also have z-position 0 and the shadow layers are added after
them, so the shadow painted on top: an inset shadow over every child,
and an outset shadow over a child that overflows the view.

CSS paints inset shadows above the element's background and all box
shadows below its border and content
(https://drafts.csswg.org/css-backgrounds-3/#shadow-layers). Give the
shadow layers a fixed z-position between the background layers and the
border layer. Outset shadows then sit above the background, but they
are masked to the outside of the border box.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ide
ide force-pushed the @ide/ios-box-shadow-paint-order branch from 526db5e to 3c058a2 Compare November 29, 2026 12:01
@ide
ide marked this pull request as ready for review November 29, 2026 13:49
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 29, 2026
@meta-codesync

meta-codesync Bot commented Nov 30, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D135059381.

@zeyap zeyap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@ide

ide commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

@javache the "Facebook Internal - Linter" check fails on this one, and its result is only visible inside Meta. The changed lines pass clang-format here. If it flags something in this change, tell me what and I will fix it on this branch.

@meta-codesync
meta-codesync Bot merged commit 03a6765 into react:main Dec 1, 2026
90 of 91 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @ide in 03a6765

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Dec 1, 2026
@ide
ide deleted the @ide/ios-box-shadow-paint-order branch December 1, 2026 11:07
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. Merged This PR has been merged. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants