Skip to content

Commit e9cdacc

Browse files
coadoclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 601fae6 commit e9cdacc

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ hasValue(const RawProps& rawProps, bool defaultValue, const char* name) {
3333
return false;
3434
}
3535

36+
// ReactTextInputManager resets a color to the platform default for null, while
37+
// 0 is transparent.
38+
static folly::dynamic colorOrNull(const SharedColor& color) {
39+
return color ? folly::dynamic(*color) : folly::dynamic(nullptr);
40+
}
41+
3642
AndroidTextInputProps::AndroidTextInputProps(
3743
const PropsParserContext &context,
3844
const AndroidTextInputProps &sourceProps,
@@ -610,6 +616,11 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
610616
result["textTransform"] = textTransform;
611617
}
612618

619+
if (textAttributes.foregroundColor !=
620+
oldProps->textAttributes.foregroundColor) {
621+
result["color"] = colorOrNull(textAttributes.foregroundColor);
622+
}
623+
613624
if (letterSpacing != oldProps->letterSpacing) {
614625
result["letterSpacing"] = letterSpacing;
615626
}

‎packages/react-native/ReactCommon/react/renderer/components/textinput/tests/AndroidTextInputPropsDiffTest.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ TEST(AndroidTextInputPropsDiffTest, eventHandlerPropsAreSent) {
2828
});
2929
}
3030

31+
// Text typed into an empty input uses the color of the native view, not the
32+
// color in the attributed string of the state.
33+
TEST(AndroidTextInputPropsDiffTest, colorIsSent) {
34+
using folly::dynamic;
35+
expectPayloadsMatchRawProps<AndroidTextInputProps>({
36+
{dynamic::object("color", static_cast<int32_t>(0xFFFF0000))},
37+
{dynamic::object("color", 0)},
38+
{dynamic::object("color", nullptr)},
39+
});
40+
}
41+
3142
} // namespace facebook::react
3243

3344
#endif

0 commit comments

Comments
 (0)