Skip to content

Commit 600d45b

Browse files
committed
fix(fabric): Switch default Text color to labelColor
1 parent 70f3149 commit 600d45b

5 files changed

Lines changed: 11 additions & 5 deletions

File tree

packages/react-native/Libraries/Text/RCTTextAttributes.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ - (CGFloat)effectiveFontSizeMultiplier
277277

278278
- (RCTPlatformColor *)effectiveForegroundColor // [macOS]
279279
{
280-
RCTPlatformColor *effectiveForegroundColor = _foregroundColor ?: [RCTPlatformColor blackColor]; // [macOS]
280+
RCTPlatformColor *effectiveForegroundColor = _foregroundColor ?: [RCTTextAttributes defaultForegroundColor]; // [macOS]
281281

282282
if (!isnan(_opacity)) {
283283
effectiveForegroundColor =

packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ - (instancetype)initWithFrame:(CGRect)frame
6969
_textInputDelegateAdapter = [[RCTBackedTextViewDelegateAdapter alloc] initWithTextView:self];
7070

7171
self.backgroundColor = [RCTPlatformColor clearColor]; // [macOS]
72-
self.textColor = [RCTPlatformColor blackColor]; // [macOS]
72+
self.textColor = [RCTPlatformColor labelColor]; // [macOS]
7373
// This line actually removes 5pt (default value) left and right padding in UITextView.
7474
#if !TARGET_OS_OSX // [macOS]
7575
self.textContainer.lineFragmentPadding = 0;

packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ - (void)enforceTextAttributesIfNeeded
127127

128128
NSDictionary<NSAttributedStringKey, id> *textAttributes = [[_textAttributes effectiveTextAttributes] mutableCopy];
129129
if ([textAttributes valueForKey:NSForegroundColorAttributeName] == nil) {
130-
[textAttributes setValue:[RCTPlatformColor blackColor] forKey:NSForegroundColorAttributeName]; // [macOS]
130+
[textAttributes setValue:[RCTPlatformColor labelColor] forKey:NSForegroundColorAttributeName]; // [macOS]
131131
}
132132

133133
backedTextInputView.defaultTextAttributes = textAttributes;

packages/react-native/ReactCommon/react/renderer/attributedstring/TextAttributes.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ TextAttributes TextAttributes::defaultTextAttributes() {
178178
static auto textAttributes = [] {
179179
auto textAttributes = TextAttributes{};
180180
// Non-obvious (can be different among platforms) default text attributes.
181-
textAttributes.foregroundColor = blackColor();
181+
// [macOS textAttributes.foregroundColor = blackColor();
182+
// Leave foregroundColor unset so each platform can apply a dynamic default
183+
// (e.g. labelColor) that adapts to light/dark mode.
184+
// macOS]
182185
textAttributes.backgroundColor = clearColor();
183186
textAttributes.fontSize = 14.0;
184187
textAttributes.fontSizeMultiplier = 1.0;

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex
144144

145145
inline static RCTPlatformColor *RCTEffectiveForegroundColorFromTextAttributes(const TextAttributes &textAttributes) // [macOS]
146146
{
147-
RCTPlatformColor *effectiveForegroundColor = RCTUIColorFromSharedColor(textAttributes.foregroundColor) ? RCTUIColorFromSharedColor(textAttributes.foregroundColor) : [RCTPlatformColor blackColor]; // [macOS]
147+
RCTPlatformColor *effectiveForegroundColor = RCTUIColorFromSharedColor(textAttributes.foregroundColor) ?: [RCTPlatformColor labelColor]; // [macOS]
148148

149149
if (!isnan(textAttributes.opacity)) {
150150
effectiveForegroundColor = [effectiveForegroundColor
@@ -182,6 +182,9 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex
182182

183183
if (textAttributes.foregroundColor || !isnan(textAttributes.opacity)) {
184184
attributes[NSForegroundColorAttributeName] = effectiveForegroundColor;
185+
} else {
186+
// [macOS] Apply dynamic default (labelColor) so text adapts to dark mode
187+
attributes[NSForegroundColorAttributeName] = effectiveForegroundColor;
185188
}
186189

187190
if (textAttributes.backgroundColor || !isnan(textAttributes.opacity)) {

0 commit comments

Comments
 (0)