Skip to content

Commit a793487

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 bae8a08 commit a793487

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
@@ -34,6 +34,12 @@ hasValue(const RawProps& rawProps, bool defaultValue, const char* name) {
3434
return false;
3535
}
3636

37+
// Some ReactTextInputManager setters treat an empty string differently from
38+
// null, which is what raw props send for a removed prop.
39+
static folly::dynamic stringOrNull(const std::string& value) {
40+
return value.empty() ? folly::dynamic(nullptr) : folly::dynamic(value);
41+
}
42+
3743
// ReactTextInputManager resets a color to the platform default for null, while
3844
// 0 is transparent.
3945
static folly::dynamic colorOrNull(const SharedColor& color) {
@@ -516,11 +522,11 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
516522

517523
// Android text input props
518524
if (autoComplete != oldProps->autoComplete) {
519-
result["autoComplete"] = autoComplete;
525+
result["autoComplete"] = stringOrNull(autoComplete);
520526
}
521527

522528
if (returnKeyLabel != oldProps->returnKeyLabel) {
523-
result["returnKeyLabel"] = returnKeyLabel;
529+
result["returnKeyLabel"] = stringOrNull(returnKeyLabel);
524530
}
525531

526532
if (numberOfLines != oldProps->numberOfLines) {
@@ -636,7 +642,7 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
636642
}
637643

638644
if (textAlign != oldProps->textAlign) {
639-
result["textAlign"] = textAlign;
645+
result["textAlign"] = stringOrNull(textAlign);
640646
}
641647

642648
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)