Skip to content

Paint iOS box shadows below child content - #60366

Draft
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/ios-box-shadow-paint-order
Draft

ide wants to merge 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

Copy link
Copy Markdown

Visual regression

No visual differences at 526db5e6511c.

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

This branch has not been deployed

No deployments
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. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant