Skip to content

Commit 56de124

Browse files
coadoclaude
andcommitted
Send null when removing TextInput returnKeyLabel, autoComplete and textAlign
Summary: Removing these props sent an empty string, which `ReactTextInputManager` does not treat like the `null` sent by raw props. For `returnKeyLabel` it calls `setImeActionLabel("", ...)`, which sets a blank action label instead of clearing it. For `autoComplete` and `textAlign` the resulting state is the same, but each removal logs an "Invalid autoComplete" or "Invalid textAlign" warning. These props now send `null` when removed. The other string props still send an empty string: their setters treat it like `null`, except `fontFamily`, where an empty string resets the typeface and `null` keeps the previous font family. 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 null when removing TextInput returnKeyLabel, autoComplete and textAlign Test Plan: `AndroidTextInputPropsDiffTest.removedStringsAreSentAsNull` 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 0755ac4 commit 56de124

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ static void updateEventProp(
8282
}
8383
}
8484

85+
// Some ReactTextInputManager setters treat an empty string differently from
86+
// null, which is what raw props send for a removed prop.
87+
static folly::dynamic stringOrNull(const std::string& value) {
88+
return value.empty() ? folly::dynamic(nullptr) : folly::dynamic(value);
89+
}
90+
8591
// ReactTextInputManager resets a color to the platform default for null, while
8692
// 0 is transparent.
8793
static folly::dynamic colorOrNull(const SharedColor& color) {
@@ -565,11 +571,11 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
565571

566572
// Android text input props
567573
if (autoComplete != oldProps->autoComplete) {
568-
result["autoComplete"] = autoComplete;
574+
result["autoComplete"] = stringOrNull(autoComplete);
569575
}
570576

571577
if (returnKeyLabel != oldProps->returnKeyLabel) {
572-
result["returnKeyLabel"] = returnKeyLabel;
578+
result["returnKeyLabel"] = stringOrNull(returnKeyLabel);
573579
}
574580

575581
if (numberOfLines != oldProps->numberOfLines) {
@@ -685,7 +691,7 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
685691
}
686692

687693
if (textAlign != oldProps->textAlign) {
688-
result["textAlign"] = textAlign;
694+
result["textAlign"] = stringOrNull(textAlign);
689695
}
690696

691697
if (includeFontPadding != oldProps->includeFontPadding) {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ TEST(AndroidTextInputPropsDiffTest, fontVariantIsSentAsAnArray) {
7979
});
8080
}
8181

82+
// ReactTextInputManager treats an empty string differently from null for these:
83+
// a blank IME action label, or a warning about an invalid value.
84+
TEST(AndroidTextInputPropsDiffTest, removedStringsAreSentAsNull) {
85+
using folly::dynamic;
86+
expectPayloadsMatchRawProps<AndroidTextInputProps>({
87+
{dynamic::object("returnKeyLabel", "Go")("autoComplete", "email")(
88+
"textAlign", "center")},
89+
{dynamic::object("returnKeyLabel", nullptr)("autoComplete", nullptr)(
90+
"textAlign", nullptr)},
91+
});
92+
}
93+
8294
} // namespace facebook::react
8395

8496
#endif

0 commit comments

Comments
 (0)