From a2b52af3bcc273cf85f01510c24d4e8da1b45656 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Tue, 4 Jun 2024 05:57:33 -0700 Subject: [PATCH] Fix border drawn over children on iOS (#44777) Summary: Fixes https://github.com/facebook/react-native/issues/44690 In the code responsible for drawing border on iOS there's a comment saying: > iOS draws borders in front of the content whereas CSS draws them behind the content. For this reason, only use iOS border drawing when clipping or when the border is hidden. The condition that follows checks whether the content is clipped and the width and alpha channel of the border: https://github.com/facebook/react-native/blob/e0a2e86d0346bd7e40adf69311daa538ca8c9c5f/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm#L643-L644. The problem is when the color is not set at all - `colorComponentsFromColor(borderMetrics.borderColors.left).alpha` will be equal to 0 since the relevant `SharedColor` is `null`: https://github.com/facebook/react-native/blob/e0a2e86d0346bd7e40adf69311daa538ca8c9c5f/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm#L76-L86 Then it uses the path with the default iOS behavior (drawing the border on top of the content) instead of the custom one (with the border below) and it seems like it defaults to drawing black when the passed color is `nil`. This PR simply adds one more check to make sure the color is actually set before choosing the default platform behavior. ## Changelog: [IOS] [FIXED] - Fixed border being drawn over children when no color was set Pull Request resolved: https://github.com/facebook/react-native/pull/44777 Test Plan: Tested on the code from the issue. |Before|After| |-|-| |Screenshot 2024-06-04 at 11 18 14|Screenshot 2024-06-04 at 11 17 38| Reviewed By: cortinico Differential Revision: D58131337 Pulled By: cipolleschi fbshipit-source-id: 7da247d81ecec586de6f0023e0cb399f9966213d --- .../Mounting/ComponentViews/View/RCTViewComponentView.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 8b9f511d89aa57..8026a4bafc7635 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -633,8 +633,9 @@ - (void)invalidateLayer // iOS draws borders in front of the content whereas CSS draws them behind // the content. For this reason, only use iOS border drawing when clipping // or when the border is hidden. - borderMetrics.borderWidths.left == 0 || - colorComponentsFromColor(borderMetrics.borderColors.left).alpha == 0 || self.clipsToBounds); + borderMetrics.borderWidths.left == 0 || self.clipsToBounds || + (colorComponentsFromColor(borderMetrics.borderColors.left).alpha == 0 && + (*borderMetrics.borderColors.left).getUIColor() != nullptr)); CGColorRef backgroundColor = [_backgroundColor resolvedColorWithTraitCollection:self.traitCollection].CGColor;