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