Skip to content

Commit c251c59

Browse files
authored
fix(fabric): Switch default Text color to labelColor (#2878)
1 parent 44ba85f commit c251c59

File tree

7 files changed

+17
-5
lines changed

7 files changed

+17
-5
lines changed

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ 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+
textAttributes.foregroundColor = defaultForegroundTextColor(); // [macOS]
182182
textAttributes.backgroundColor = clearColor();
183183
textAttributes.fontSize = 14.0;
184184
textAttributes.fontSizeMultiplier = 1.0;

packages/react-native/ReactCommon/react/renderer/graphics/Color.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ SharedColor colorFromRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
7070
SharedColor clearColor();
7171
SharedColor blackColor();
7272
SharedColor whiteColor();
73+
SharedColor defaultForegroundTextColor(); // [macOS]
7374

7475
#ifdef RN_SERIALIZABLE_STATE
7576
inline folly::dynamic toDynamic(const SharedColor& sharedColor) {

packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import <Foundation/Foundation.h>
1111
#import <React/RCTUIKit.h> // [macOS]
1212
#import <objc/runtime.h>
13+
#import <react/renderer/graphics/Color.h> // [macOS]
1314
#import <react/renderer/graphics/RCTPlatformColorUtils.h>
1415
#import <react/utils/ManagedObjectWrapper.h>
1516
#import <string>
@@ -342,6 +343,16 @@ int32_t ColorFromUIColor(const std::shared_ptr<void> &uiColor)
342343
return Color(wrapManagedObject(semanticColor));
343344
}
344345

346+
// [macOS
347+
SharedColor defaultForegroundTextColor() {
348+
static SharedColor color = [] {
349+
std::vector<std::string> items = {"labelColor"};
350+
return SharedColor(Color::createSemanticColor(items));
351+
}();
352+
return color;
353+
}
354+
// macOS]
355+
345356
} // namespace facebook::react
346357

347358
NS_ASSUME_NONNULL_END

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

Lines changed: 1 addition & 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

0 commit comments

Comments
 (0)