From a793487494faa8421aa656a5470e2beef3f39bd7 Mon Sep 17 00:00:00 2001 From: Dawid Malecki Date: Wed, 4 Nov 2026 13:22:11 +0100 Subject: [PATCH] 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 --- .../androidtextinput/AndroidTextInputProps.cpp | 12 +++++++++--- .../tests/AndroidTextInputPropsDiffTest.cpp | 12 ++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) 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 be62807fbe0c..fd09f93dd10c 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 @@ -34,6 +34,12 @@ hasValue(const RawProps& rawProps, bool defaultValue, const char* name) { return false; } +// Some ReactTextInputManager setters treat an empty string differently from +// null, which is what raw props send for a removed prop. +static folly::dynamic stringOrNull(const std::string& value) { + return value.empty() ? folly::dynamic(nullptr) : folly::dynamic(value); +} + // ReactTextInputManager resets a color to the platform default for null, while // 0 is transparent. static folly::dynamic colorOrNull(const SharedColor& color) { @@ -516,11 +522,11 @@ folly::dynamic AndroidTextInputProps::getDiffProps( // Android text input props if (autoComplete != oldProps->autoComplete) { - result["autoComplete"] = autoComplete; + result["autoComplete"] = stringOrNull(autoComplete); } if (returnKeyLabel != oldProps->returnKeyLabel) { - result["returnKeyLabel"] = returnKeyLabel; + result["returnKeyLabel"] = stringOrNull(returnKeyLabel); } if (numberOfLines != oldProps->numberOfLines) { @@ -636,7 +642,7 @@ folly::dynamic AndroidTextInputProps::getDiffProps( } if (textAlign != oldProps->textAlign) { - result["textAlign"] = textAlign; + result["textAlign"] = stringOrNull(textAlign); } if (includeFontPadding != oldProps->includeFontPadding) { 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 2fd5377a0456..0933dd50e5ac 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 @@ -79,6 +79,18 @@ TEST(AndroidTextInputPropsDiffTest, fontVariantIsSentAsAnArray) { }); } +// ReactTextInputManager treats an empty string differently from null for these: +// a blank IME action label, or a warning about an invalid value. +TEST(AndroidTextInputPropsDiffTest, removedStringsAreSentAsNull) { + using folly::dynamic; + expectPayloadsMatchRawProps({ + {dynamic::object("returnKeyLabel", "Go")("autoComplete", "email")( + "textAlign", "center")}, + {dynamic::object("returnKeyLabel", nullptr)("autoComplete", nullptr)( + "textAlign", nullptr)}, + }); +} + } // namespace facebook::react #endif