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 02574182c30..50a82adaef5 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,9 @@ - (void)invalidateLayer RCTCornerRadiiFromBorderRadii(borderMetrics.borderRadii), RCTUIEdgeInsetsFromEdgeInsets(borderMetrics.borderWidths), self.layer.bounds.size); - shadowLayer.zPosition = _borderLayer.zPosition; + // CSS paints box shadows above the background and below the border and the children + // (https://drafts.csswg.org/css-backgrounds-3/#box-shadow). + 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 5c00390702c..1698ab1cf3d 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