Skip to content

fix(graphics): make default text colors portable - #3174

Open
Jason Morse (JasonVMo) wants to merge 1 commit into
mainfrom
user/jasonvmo/cpp-text-color
Open

Jason Morse (JasonVMo) wants to merge 1 commit into
mainfrom
user/jasonvmo/cpp-text-color

Conversation

@JasonVMo

Copy link
Copy Markdown

Summary:

The shared TextAttributes::defaultTextAttributes() calls defaultForegroundTextColor(), but its only definition is in Apple's HostPlatformColor.mm. Android and generic C++ graphics builds do not compile that file and cannot link the default text attributes.

  • Define the shared factory in Color.cpp and delegate to the selected graphics backend. Android/C++ keep their upstream opaque-black default, including generic C++ builds hosted on macOS.
  • Keep Apple's cached semantic labelColor behavior unchanged, including iOS: fix(fabric): Switch default Text color to labelColor #2878 explicitly intended the existing Paper behavior on both Apple platforms.
  • Add a regression to the existing ColorTest.cpp suite. This repairs a fork-only helper; an upstream product change or application-layer workaround would not resolve the missing symbol.

Test Plan:

Standalone compiler validation used Apple Clang 21/Xcode 26.4.1 and GoogleTest v1.16.0 restored into a disposable worktree-local harness after the first compile reported missing gtest/gtest.h. No Pods or original-checkout dependencies were modified.

  • .color-validation/color-test-cxx — passed, 2/2 tests.
  • .color-validation/color-test-android — passed, 2/2 tests using the Android color backend hosted on macOS, not an Android device/NDK build.
  • .color-validation/color-test-apple — passed, 2/2 tests using the actual Apple graphics sources, actual RCTUIKit headers, and an AppKit-initialized GoogleTest runner.
  • The new regression linked against baseline Color.cpp — expected link failure, undefined facebook::react::defaultForegroundTextColor().
  • .color-validation/default-color-cxx and .color-validation/default-color-android — passed, both equal blackColor().
  • .color-validation/apple-default-color — passed, the actual factory still equals NSColor.labelColor under Aqua, DarkAqua, accessibility Aqua, and accessibility DarkAqua; light and dark results remain different.
  • iOS and visionOS simulator syntax checks below — passed; visionOS emitted two existing traitCollectionWithTraitsFromCollections: deprecation warnings.
  • git diff --check — passed.
  • Changed-range xcrun clang-format --output-replacements-xml --lines=<changed ranges> <file> checks — passed, zero replacements across all six files. Whole-file xcrun clang-format --dry-run --Werror failed on existing formatting outside the changes; those lines were not reformatted.
Exact standalone suite compiler commands

The worktree-local React header-search symlink points at the repository's actual packages/react-native/ReactApple/Libraries/RCTUIKit directory. The Apple runner only calls [NSApplication sharedApplication], initializes GoogleTest, and runs its tests.

SDK=/Applications/Xcode_26.4.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
GRAPHICS=packages/react-native/ReactCommon/react/renderer/graphics
COMMON=(
  -isysroot "$SDK" -std=c++20 -include memory -include cstdint
  -I packages/react-native/ReactCommon
  -I .color-validation/googletest/googletest/include
  -I .color-validation/googletest/googletest
  -Wno-character-conversion
)
GTEST=(
  .color-validation/googletest/googletest/src/gtest-all.cc
  .color-validation/googletest/googletest/src/gtest_main.cc
)
APPLE_SOURCES=(
  "$GRAPHICS/platform/ios/react/renderer/graphics/HostPlatformColor.mm"
  "$GRAPHICS/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.mm"
  packages/react-native/ReactCommon/react/utils/ManagedObjectWrapper.mm
)

for PLATFORM in cxx android; do
  clang++ "${COMMON[@]}" -I "$GRAPHICS/platform/$PLATFORM" \
    "$GRAPHICS/tests/ColorTest.cpp" "$GRAPHICS/Color.cpp" \
    "$GRAPHICS/ColorComponents.cpp" "${GTEST[@]}" -pthread \
    -o ".color-validation/color-test-$PLATFORM"
  ".color-validation/color-test-$PLATFORM"
done

clang++ "${COMMON[@]}" -fobjc-arc -DREACT_NATIVE_PRODUCTION \
  -I .color-validation -I "$GRAPHICS/platform/ios" \
  "$GRAPHICS/tests/ColorTest.cpp" "$GRAPHICS/Color.cpp" \
  "$GRAPHICS/ColorComponents.cpp" "${APPLE_SOURCES[@]}" \
  .color-validation/googletest/googletest/src/gtest-all.cc \
  .color-validation/appkit-test-main.mm \
  -pthread -framework AppKit -framework QuartzCore \
  -o .color-validation/color-test-apple
.color-validation/color-test-apple
clang++ -target arm64-apple-ios15.1-simulator \
  -isysroot /Applications/Xcode_26.4.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk \
  -std=c++20 -fobjc-arc -DREACT_NATIVE_PRODUCTION -include memory -include cstdint \
  -I .color-validation \
  -I packages/react-native/ReactCommon/react/renderer/graphics/platform/ios \
  -I packages/react-native/ReactCommon -fsyntax-only \
  packages/react-native/ReactCommon/react/renderer/graphics/Color.cpp \
  packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm

clang++ -target arm64-apple-xros1.0-simulator \
  -isysroot /Applications/Xcode_26.4.1.app/Contents/Developer/Platforms/XRSimulator.platform/Developer/SDKs/XRSimulator.sdk \
  -std=c++20 -fobjc-arc -DREACT_NATIVE_PRODUCTION -include memory -include cstdint \
  -I .color-validation \
  -I packages/react-native/ReactCommon/react/renderer/graphics/platform/ios \
  -I packages/react-native/ReactCommon -fsyntax-only \
  packages/react-native/ReactCommon/react/renderer/graphics/Color.cpp \
  packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm

Not run: CocoaPods/Xcode/RNTester integration or Paper builds, Android NDK/device integration, iOS/visionOS runtime, Metro, and JS Jest/Flow/lint/format suites (no JS changes). No UI behavior changes are intended on Apple platforms, so no UI screenshots are included.

Define the shared text-color factory through the selected graphics backend so Android and generic C++ link without the Apple implementation. Preserve Apple's existing semantic label color and cover the factory in ColorTest.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 33ea5c72-8bbd-448d-aa21-c9b99dd03c96
@JasonVMo

Copy link
Copy Markdown
Author

Additional validation: the six independent main fixes (#3170–#3175) were combined at e9667492e9 in an isolated worktree. After regenerating Pods from packages/rn-tester, RNTester-macOS and RNTester for arm64/x86_64 iOS simulators both built successfully. Exact commands, corrected codegen invocation, and limitations are recorded in #3175 (integration validation comment). This is build evidence, not live UI or sanitizer qualification; no PR was merged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant