Skip to content

Commit 02ca88d

Browse files
committed
Use trait collection to resolve border colors
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:).
1 parent d6db5c5 commit 02ca88d

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

React/Views/RCTView.m

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -706,33 +706,43 @@ - (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 = [directionAwareBorderLeftColor resolvedColorWithTraitCollection:self.traitCollection];
736+
borderBottomColor = [borderBottomColor resolvedColorWithTraitCollection:self.traitCollection];
737+
directionAwareBorderRightColor = [directionAwareBorderRightColor resolvedColorWithTraitCollection:self.traitCollection];
738+
}
739+
#endif
730740

731741
return (RCTBorderColors){
732-
(_borderTopColor ?: _borderColor).CGColor,
733-
(directionAwareBorderLeftColor ?: _borderLeftColor ?: _borderColor).CGColor,
734-
(_borderBottomColor ?: _borderColor).CGColor,
735-
(directionAwareBorderRightColor ?: _borderRightColor ?: _borderColor).CGColor,
742+
(borderTopColor ?: borderColor).CGColor,
743+
(directionAwareBorderLeftColor ?: borderColor).CGColor,
744+
(borderBottomColor ?: borderColor).CGColor,
745+
(directionAwareBorderRightColor ?: borderColor).CGColor,
736746
};
737747
}
738748

@@ -758,7 +768,7 @@ - (void)displayLayer:(CALayer *)layer
758768

759769
const RCTCornerRadii cornerRadii = [self cornerRadii];
760770
const UIEdgeInsets borderInsets = [self bordersAsInsets];
761-
const RCTBorderColors borderColors = [self borderColors];
771+
const RCTBorderColors borderColors = [self borderColorsWithTraitCollection:self.traitCollection];
762772

763773
BOOL useIOSBorderRendering = RCTCornerRadiiAreEqual(cornerRadii) && RCTBorderInsetsAreEqual(borderInsets) &&
764774
RCTBorderColorsAreEqual(borderColors) && _borderStyle == RCTBorderStyleSolid &&

0 commit comments

Comments
 (0)