Skip to content

Commit

Permalink
Use trait collection to resolve border colors (facebook#32492)
Browse files Browse the repository at this point in the history
Summary:
facebook@c974cbf changed the border colors to be of UIColor instead of CGColor. This allowed working with dark mode to switch the border colors automatically. However, in certain situation the system can't resolve the current trait collection (see https://stackoverflow.com/a/57177411/2525941). This commit resolves the colors with the current trait collection to ensure the right colors are selected. This matches with the behavior of how the background color is resolved (also in displayLayer:).

## Changelog

[iOS] [Fixed] - Resolve border platform color based on current trait collection

Pull Request resolved: facebook#32492

Test Plan: Same test plan as facebook#29728

Reviewed By: sammy-SC

Differential Revision: D33819225

Pulled By: cortinico

fbshipit-source-id: 2f8024be7ee7b32d1852373b47fa1437cc569391
  • Loading branch information
danilobuerger authored and Shawn Dempsey committed Feb 13, 2023
1 parent f4b6653 commit d088656
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,13 @@ - (RCTCornerRadii)cornerRadii
};
}

- (RCTBorderColors)borderColors
- (RCTBorderColors)borderColorsWithTraitCollection:(UITraitCollection *)traitCollection
{
const BOOL isRTL = _reactLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft;

UIColor *directionAwareBorderLeftColor = nil;
UIColor *directionAwareBorderRightColor = nil;

if ([[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) {
RCTUIColor *borderStartColor = _borderStartColor ?: _borderLeftColor; // macOS RCTUIColor
RCTUIColor *borderEndColor = _borderEndColor ?: _borderRightColor; // macOS RCTUIColor
Expand All @@ -1147,10 +1150,10 @@ - (RCTBorderColors)borderColors
RCTUIColor *directionAwareBorderRightColor = isRTL ? _borderStartColor : _borderEndColor; // macOS RCTUIColor

return (RCTBorderColors){
(_borderTopColor ?: _borderColor).CGColor,
(directionAwareBorderLeftColor ?: _borderLeftColor ?: _borderColor).CGColor,
(_borderBottomColor ?: _borderColor).CGColor,
(directionAwareBorderRightColor ?: _borderRightColor ?: _borderColor).CGColor,
(borderTopColor ?: borderColor).CGColor,
(directionAwareBorderLeftColor ?: borderColor).CGColor,
(borderBottomColor ?: borderColor).CGColor,
(directionAwareBorderRightColor ?: borderColor).CGColor,
};
}

Expand Down Expand Up @@ -1181,7 +1184,7 @@ - (void)displayLayer:(CALayer *)layer

const RCTCornerRadii cornerRadii = [self cornerRadii];
const UIEdgeInsets borderInsets = [self bordersAsInsets];
const RCTBorderColors borderColors = [self borderColors];
const RCTBorderColors borderColors = [self borderColorsWithTraitCollection:self.traitCollection];

BOOL useIOSBorderRendering = RCTCornerRadiiAreEqual(cornerRadii) && RCTBorderInsetsAreEqual(borderInsets) &&
RCTBorderColorsAreEqual(borderColors) && _borderStyle == RCTBorderStyleSolid &&
Expand Down

0 comments on commit d088656

Please sign in to comment.