Skip to content

Commit 9a35818

Browse files
danilobuergerfacebook-github-bot
authored andcommitted
Use trait collection to resolve border colors (#32492)
Summary: 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: #32492 Test Plan: Same test plan as #29728 Reviewed By: sammy-SC Differential Revision: D33819225 Pulled By: cortinico fbshipit-source-id: 2f8024be7ee7b32d1852373b47fa1437cc569391
1 parent 731429e commit 9a35818

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

React/Views/RCTView.m

+29-17
Original file line numberDiff line numberDiff line change
@@ -706,33 +706,45 @@ - (RCTCornerRadii)cornerRadii
706706
};
707707
}
708708

709-
- (RCTBorderColors)borderColors
709+
- (RCTBorderColors)borderColorsWithTraitCollection:(UITraitCollection *)traitCollection
710710
{
711711
const BOOL isRTL = _reactLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft;
712712

713+
UIColor *directionAwareBorderLeftColor = nil;
714+
UIColor *directionAwareBorderRightColor = nil;
715+
713716
if ([[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) {
714717
UIColor *borderStartColor = _borderStartColor ?: _borderLeftColor;
715718
UIColor *borderEndColor = _borderEndColor ?: _borderRightColor;
716719

717-
UIColor *directionAwareBorderLeftColor = isRTL ? borderEndColor : borderStartColor;
718-
UIColor *directionAwareBorderRightColor = isRTL ? borderStartColor : borderEndColor;
719-
720-
return (RCTBorderColors){
721-
(_borderTopColor ?: _borderColor).CGColor,
722-
(directionAwareBorderLeftColor ?: _borderColor).CGColor,
723-
(_borderBottomColor ?: _borderColor).CGColor,
724-
(directionAwareBorderRightColor ?: _borderColor).CGColor,
725-
};
720+
directionAwareBorderLeftColor = isRTL ? borderEndColor : borderStartColor;
721+
directionAwareBorderRightColor = isRTL ? borderStartColor : borderEndColor;
722+
} else {
723+
directionAwareBorderLeftColor = (isRTL ? _borderEndColor : _borderStartColor) ?: _borderLeftColor;
724+
directionAwareBorderRightColor = (isRTL ? _borderStartColor : _borderEndColor) ?: _borderRightColor;
726725
}
727726

728-
UIColor *directionAwareBorderLeftColor = isRTL ? _borderEndColor : _borderStartColor;
729-
UIColor *directionAwareBorderRightColor = isRTL ? _borderStartColor : _borderEndColor;
727+
UIColor *borderColor = _borderColor;
728+
UIColor *borderTopColor = _borderTopColor;
729+
UIColor *borderBottomColor = _borderBottomColor;
730+
731+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
732+
if (@available(iOS 13.0, *)) {
733+
borderColor = [borderColor resolvedColorWithTraitCollection:self.traitCollection];
734+
borderTopColor = [borderTopColor resolvedColorWithTraitCollection:self.traitCollection];
735+
directionAwareBorderLeftColor =
736+
[directionAwareBorderLeftColor resolvedColorWithTraitCollection:self.traitCollection];
737+
borderBottomColor = [borderBottomColor resolvedColorWithTraitCollection:self.traitCollection];
738+
directionAwareBorderRightColor =
739+
[directionAwareBorderRightColor resolvedColorWithTraitCollection:self.traitCollection];
740+
}
741+
#endif
730742

731743
return (RCTBorderColors){
732-
(_borderTopColor ?: _borderColor).CGColor,
733-
(directionAwareBorderLeftColor ?: _borderLeftColor ?: _borderColor).CGColor,
734-
(_borderBottomColor ?: _borderColor).CGColor,
735-
(directionAwareBorderRightColor ?: _borderRightColor ?: _borderColor).CGColor,
744+
(borderTopColor ?: borderColor).CGColor,
745+
(directionAwareBorderLeftColor ?: borderColor).CGColor,
746+
(borderBottomColor ?: borderColor).CGColor,
747+
(directionAwareBorderRightColor ?: borderColor).CGColor,
736748
};
737749
}
738750

@@ -758,7 +770,7 @@ - (void)displayLayer:(CALayer *)layer
758770

759771
const RCTCornerRadii cornerRadii = [self cornerRadii];
760772
const UIEdgeInsets borderInsets = [self bordersAsInsets];
761-
const RCTBorderColors borderColors = [self borderColors];
773+
const RCTBorderColors borderColors = [self borderColorsWithTraitCollection:self.traitCollection];
762774

763775
BOOL useIOSBorderRendering = RCTCornerRadiiAreEqual(cornerRadii) && RCTBorderInsetsAreEqual(borderInsets) &&
764776
RCTBorderColorsAreEqual(borderColors) && _borderStyle == RCTBorderStyleSolid &&

0 commit comments

Comments
 (0)