From e9cdacc99799ff85580f537b2533cabf59d67a01 Mon Sep 17 00:00:00 2001 From: Dawid Malecki Date: Wed, 4 Nov 2026 13:21:25 +0100 Subject: [PATCH] Send TextInput color when props diffing is enabled Summary: `AndroidTextInputProps::getDiffProps` never sent `color`. The flat `color` field is not parsed, so the value is only available in `textAttributes.foregroundColor`. Existing text is colored by the attributed string in the state, but the native view kept its default text color, so text typed into an empty input ignored `color`. With a light `color` on a dark background the typed text was black. This sends `color` from the text attributes, and `null` when it is removed so that `ReactTextInputManager` restores the default text color. TextInput doesn't use props diffing yet: `getDiffPropsImplementationTarget()` returns `TextInput`, which doesn't match the `AndroidTextInput` component name. So the problem above only appears once that is enabled, and this change has no runtime effect until then. Changelog: [Internal] - Send TextInput color when props diffing is enabled Test Plan: `AndroidTextInputPropsDiffTest.colorIsSent` compares the props diffing payload with the raw props payload. It fails without this change and passes with it. Co-Authored-By: Claude Opus 5.5 --- .../androidtextinput/AndroidTextInputProps.cpp | 11 +++++++++++ .../textinput/tests/AndroidTextInputPropsDiffTest.cpp | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp index 4f61b16479bb..242d4ce659ff 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp @@ -33,6 +33,12 @@ hasValue(const RawProps& rawProps, bool defaultValue, const char* name) { return false; } +// ReactTextInputManager resets a color to the platform default for null, while +// 0 is transparent. +static folly::dynamic colorOrNull(const SharedColor& color) { + return color ? folly::dynamic(*color) : folly::dynamic(nullptr); +} + AndroidTextInputProps::AndroidTextInputProps( const PropsParserContext &context, const AndroidTextInputProps &sourceProps, @@ -610,6 +616,11 @@ folly::dynamic AndroidTextInputProps::getDiffProps( result["textTransform"] = textTransform; } + if (textAttributes.foregroundColor != + oldProps->textAttributes.foregroundColor) { + result["color"] = colorOrNull(textAttributes.foregroundColor); + } + if (letterSpacing != oldProps->letterSpacing) { result["letterSpacing"] = letterSpacing; } diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/tests/AndroidTextInputPropsDiffTest.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/tests/AndroidTextInputPropsDiffTest.cpp index dcd7ba82b16a..79cd448b8fe6 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/tests/AndroidTextInputPropsDiffTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/tests/AndroidTextInputPropsDiffTest.cpp @@ -28,6 +28,17 @@ TEST(AndroidTextInputPropsDiffTest, eventHandlerPropsAreSent) { }); } +// Text typed into an empty input uses the color of the native view, not the +// color in the attributed string of the state. +TEST(AndroidTextInputPropsDiffTest, colorIsSent) { + using folly::dynamic; + expectPayloadsMatchRawProps({ + {dynamic::object("color", static_cast(0xFFFF0000))}, + {dynamic::object("color", 0)}, + {dynamic::object("color", nullptr)}, + }); +} + } // namespace facebook::react #endif