Skip to content

Commit 241ebeb

Browse files
committed
add defaultForegroundTextColor()
1 parent 600d45b commit 241ebeb

4 files changed

Lines changed: 13 additions & 7 deletions

File tree

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +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-
// [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]
181+
textAttributes.foregroundColor = defaultForegroundTextColor(); // [macOS]
185182
textAttributes.backgroundColor = clearColor();
186183
textAttributes.fontSize = 14.0;
187184
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: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ 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;
188185
}
189186

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

0 commit comments

Comments
 (0)