Repository navigation
Commit 03a6765
authored
Paint iOS box shadows below child content
## 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](https://drafts.csswg.org/css-backgrounds-3/#shadow-layers)). 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:
```sh
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.
Differential Revision: D135059381
Pull Request resolved: #603661 parent 0fcf6ec commit 03a6765
2 files changed
Lines changed: 26 additions & 1 deletion
File tree
- packages/react-native/React
- Fabric/Mounting/ComponentViews/View
- Tests/Mounting
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1480 | 1480 | | |
1481 | 1481 | | |
1482 | 1482 | | |
1483 | | - | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
1484 | 1487 | | |
1485 | 1488 | | |
1486 | 1489 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
408 | 408 | | |
409 | 409 | | |
410 | 410 | | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
411 | 433 | | |
0 commit comments