diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index 02574182c301..200dd1e14e73 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -1480,7 +1480,10 @@ - (void)invalidateLayer RCTCornerRadiiFromBorderRadii(borderMetrics.borderRadii), RCTUIEdgeInsetsFromEdgeInsets(borderMetrics.borderWidths), self.layer.bounds.size); - shadowLayer.zPosition = _borderLayer.zPosition; + // Below the border and the children, as CSS paints box shadows + // (https://drafts.csswg.org/css-backgrounds-3/#shadow-layers). Outset shadows sit above the + // background, unlike CSS, but are masked to outside the border box. + shadowLayer.zPosition = BACKGROUND_COLOR_ZPOSITION + 0.5; [layer addSublayer:shadowLayer]; [_boxShadowLayers addObject:shadowLayer]; } diff --git a/packages/react-native/React/Tests/Mounting/RCTViewComponentViewTests.mm b/packages/react-native/React/Tests/Mounting/RCTViewComponentViewTests.mm index 5c00390702c8..1698ab1cf3d6 100644 --- a/packages/react-native/React/Tests/Mounting/RCTViewComponentViewTests.mm +++ b/packages/react-native/React/Tests/Mounting/RCTViewComponentViewTests.mm @@ -408,4 +408,26 @@ - (void)testSquareDottedAndDashedOutlinesAreDrawnWithCoreGraphics } } +#pragma mark - box shadow paint order + +- (void)testInsetBoxShadowIsBelowChildrenWithoutBorderLayer +{ + RCTViewComponentView *view = [RCTViewComponentView new]; + view.frame = CGRectMake(0, 0, 100, 100); + + // A view without borders draws with Core Animation and has no border layer. + auto props = std::make_shared(); + props->boxShadow = {BoxShadow{.spreadDistance = 8, .color = colorFromRGBA(0, 0, 0, 255), .inset = true}}; + [view updateProps:props oldProps:ViewShadowNode::defaultSharedProps()]; + + UIView *child = [UIView new]; + [view addSubview:child]; + [view finalizeUpdates:RNComponentViewUpdateMaskProps]; + + NSArray *shadowLayers = [view valueForKey:@"_boxShadowLayers"]; + XCTAssertEqual(shadowLayers.count, 1u); + XCTAssertNil([view valueForKey:@"_borderLayer"]); + XCTAssertLessThan(shadowLayers.firstObject.zPosition, child.layer.zPosition); +} + @end