From 601fae6bd0c9209114c9154ec68c49578664e365 Mon Sep 17 00:00:00 2001 From: Dawid Malecki Date: Wed, 4 Nov 2026 13:19:13 +0100 Subject: [PATCH 1/6] Send TextInput event props when props diffing is enabled Summary: `ReactTextInputManager` only sets up the watchers behind `onKeyPress`, `onSelectionChange`, `onContentSizeChange` and `onScroll` once it receives the matching prop. `AndroidTextInputProps` had no fields for these props, so `getDiffProps` never sent them and the events never fired with props diffing on. `TextInput.js` always passes `onScroll` and `onSelectionChange`, so every TextInput would be affected. This adds the fields and sends them. JS sends a handler as `true`. Removing a handler sends `false`, which the setters treat the same as the `null` sent by raw props. 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 event props when props diffing is enabled Test Plan: `AndroidTextInputPropsDiffTest.eventHandlerPropsAreSent` compares the props diffing payload with the raw props payload. It fails without this change and passes with it. `python -m scripts.cxx-api.parser --validate` passes at this commit. Co-Authored-By: Claude Opus 5.5 --- .../AndroidTextInputProps.cpp | 30 +++++++++++++++++ .../androidtextinput/AndroidTextInputProps.h | 9 +++++ .../tests/AndroidTextInputPropsDiffTest.cpp | 33 +++++++++++++++++++ .../ReactAndroidFrameworksCxx.api | 4 +++ 4 files changed, 76 insertions(+) create mode 100644 packages/react-native/ReactCommon/react/renderer/components/textinput/tests/AndroidTextInputPropsDiffTest.cpp 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 ce2a3ac666e6..4f61b16479bb 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 @@ -151,6 +151,16 @@ AndroidTextInputProps::AndroidTextInputProps( {false})), fontWeight(convertRawProp(context, rawProps, "fontWeight", sourceProps.fontWeight, {})), fontFamily(convertRawProp(context, rawProps, "fontFamily", sourceProps.fontFamily, {})), + onKeyPress(convertRawProp(context, rawProps, "onKeyPress", sourceProps.onKeyPress, {false})), + onSelectionChange(convertRawProp(context, rawProps, + "onSelectionChange", + sourceProps.onSelectionChange, + {false})), + onContentSizeChange(convertRawProp(context, rawProps, + "onContentSizeChange", + sourceProps.onContentSizeChange, + {false})), + onScroll(convertRawProp(context, rawProps, "onScroll", sourceProps.onScroll, {false})), // See AndroidTextInputComponentDescriptor for usage // TODO T63008435: can these, and this feature, be removed entirely? hasPadding(hasValue(rawProps, sourceProps.hasPadding, "padding")), @@ -227,6 +237,10 @@ void AndroidTextInputProps::setProp( RAW_SET_PROP_SWITCH_CASE_BASIC(includeFontPadding); RAW_SET_PROP_SWITCH_CASE_BASIC(fontWeight); RAW_SET_PROP_SWITCH_CASE_BASIC(fontFamily); + RAW_SET_PROP_SWITCH_CASE_BASIC(onKeyPress); + RAW_SET_PROP_SWITCH_CASE_BASIC(onSelectionChange); + RAW_SET_PROP_SWITCH_CASE_BASIC(onContentSizeChange); + RAW_SET_PROP_SWITCH_CASE_BASIC(onScroll); case CONSTEXPR_RAW_PROPS_KEY_HASH("value"): { fromRawValue(context, value, this->value, {}); @@ -628,6 +642,22 @@ folly::dynamic AndroidTextInputProps::getDiffProps( : folly::dynamic(nullptr); } + if (onKeyPress != oldProps->onKeyPress) { + result["onKeyPress"] = onKeyPress; + } + + if (onSelectionChange != oldProps->onSelectionChange) { + result["onSelectionChange"] = onSelectionChange; + } + + if (onContentSizeChange != oldProps->onContentSizeChange) { + result["onContentSizeChange"] = onContentSizeChange; + } + + if (onScroll != oldProps->onScroll) { + result["onScroll"] = onScroll; + } + return result; } diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h index 8bfc984e2529..32b3070d33e2 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h @@ -109,6 +109,15 @@ class AndroidTextInputProps final : public BaseTextInputProps { std::string fontWeight{}; std::string fontFamily{}; + /* + * Whether JS listens to these events. ReactTextInputManager only sets up the + * native watchers for them when these props are sent. + */ + bool onKeyPress{false}; + bool onSelectionChange{false}; + bool onContentSizeChange{false}; + bool onScroll{false}; + /** * Auxiliary information to detect if these props are set or not. * See AndroidTextInputComponentDescriptor for usage. 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 new file mode 100644 index 000000000000..dcd7ba82b16a --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/tests/AndroidTextInputPropsDiffTest.cpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +#if defined(ANDROID) && defined(RN_SERIALIZABLE_STATE) + +#include +#include + +namespace facebook::react { + +// ReactTextInputManager only sets up the event watchers when these props are +// sent. JS sends a handler as `true`, and false resets it like null does. +TEST(AndroidTextInputPropsDiffTest, eventHandlerPropsAreSent) { + using folly::dynamic; + expectPayloadsMatchRawProps({ + {dynamic::object("onKeyPress", true)("onSelectionChange", true)( + "onContentSizeChange", true)("onScroll", true)}, + {dynamic::object("onKeyPress", nullptr)("onSelectionChange", nullptr)( + "onContentSizeChange", nullptr)("onScroll", nullptr), + dynamic::object("onKeyPress", false)("onSelectionChange", false)( + "onContentSizeChange", false)("onScroll", false)}, + }); +} + +} // namespace facebook::react + +#endif diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api index b9463dbd17f1..4efffc1f8cd2 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api @@ -1184,6 +1184,10 @@ class facebook::react::AndroidTextInputProps : public facebook::react::BaseTextI public bool hasPaddingTop; public bool hasPaddingVertical; public bool includeFontPadding; + public bool onContentSizeChange; + public bool onKeyPress; + public bool onScroll; + public bool onSelectionChange; public bool secureTextEntry; public bool selectTextOnFocus; public bool showSoftInputOnFocus; From e9cdacc99799ff85580f537b2533cabf59d67a01 Mon Sep 17 00:00:00 2001 From: Dawid Malecki Date: Wed, 4 Nov 2026 13:21:25 +0100 Subject: [PATCH 2/6] 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 --- .../androidtextinput/AndroidTextInputProps.cpp | 11 +++++++++++ .../textinput/tests/AndroidTextInputPropsDiffTest.cpp | 11 +++++++++++ 2 files changed, 22 insertions(+) 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 From 3a3b8bfa0c43ca1f029fc4b51abbf134d85905c1 Mon Sep 17 00:00:00 2001 From: Dawid Malecki Date: Wed, 4 Nov 2026 13:21:31 +0100 Subject: [PATCH 3/6] Send null when removing TextInput color props with props diffing Summary: Removing `placeholderTextColor`, `selectionColor`, `selectionHandleColor`, `cursorColor` or `underlineColorAndroid` sent the value of the unset `SharedColor`, which is 0. `ReactTextInputManager` treats 0 as transparent and only restores the platform default for `null`, so the placeholder, the selection highlight, the handles or the cursor became invisible. These props now send `null` when removed, the same as raw props. An explicit `transparent` is still sent as 0. `textShadowColor` used the same pattern and is changed with them, although `ReactTextInputManager` has no setter for it. 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 color props with props diffing Test Plan: `AndroidTextInputPropsDiffTest.removedColorsAreSentAsNull` 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 | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 6 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 242d4ce659ff..ad0296c3f010 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 @@ -446,23 +446,23 @@ folly::dynamic AndroidTextInputProps::getDiffProps( } if (placeholderTextColor != oldProps->placeholderTextColor) { - result["placeholderTextColor"] = *placeholderTextColor; + result["placeholderTextColor"] = colorOrNull(placeholderTextColor); } if (cursorColor != oldProps->cursorColor) { - result["cursorColor"] = *cursorColor; + result["cursorColor"] = colorOrNull(cursorColor); } if (selectionColor != oldProps->selectionColor) { - result["selectionColor"] = *selectionColor; + result["selectionColor"] = colorOrNull(selectionColor); } if (selectionHandleColor != oldProps->selectionHandleColor) { - result["selectionHandleColor"] = *selectionHandleColor; + result["selectionHandleColor"] = colorOrNull(selectionHandleColor); } if (underlineColorAndroid != oldProps->underlineColorAndroid) { - result["underlineColorAndroid"] = *underlineColorAndroid; + result["underlineColorAndroid"] = colorOrNull(underlineColorAndroid); } if (maxLength != oldProps->maxLength) { @@ -589,7 +589,7 @@ folly::dynamic AndroidTextInputProps::getDiffProps( } if (textShadowColor != oldProps->textShadowColor) { - result["textShadowColor"] = *textShadowColor; + result["textShadowColor"] = colorOrNull(textShadowColor); } if (textShadowRadius != oldProps->textShadowRadius) { 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 79cd448b8fe6..d549c31fd8d9 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 @@ -39,6 +39,22 @@ TEST(AndroidTextInputPropsDiffTest, colorIsSent) { }); } +TEST(AndroidTextInputPropsDiffTest, removedColorsAreSentAsNull) { + using folly::dynamic; + for (const auto* prop : + {"placeholderTextColor", + "selectionColor", + "selectionHandleColor", + "cursorColor", + "underlineColorAndroid", + "textShadowColor"}) { + expectPayloadsMatchRawProps({ + {dynamic::object(prop, static_cast(0xFFFF0000))}, + {dynamic::object(prop, nullptr)}, + }); + } +} + } // namespace facebook::react #endif From 6deaee7b50366f7dfb88752b5307edbb88e00cfd Mon Sep 17 00:00:00 2001 From: Dawid Malecki Date: Wed, 4 Nov 2026 13:21:54 +0100 Subject: [PATCH 4/6] Send null when removing TextInput fontSize with props diffing Summary: `fontSize` was sent from a flat field that defaults to 0, so removing it called `setFontSize(0)` and made the placeholder and any new text invisible. This sends `fontSize` from `textAttributes.fontSize`, which is NaN when unset, and sends `null` when it is removed. `ReactTextInputManager` then applies its default font size, the same as with raw props. It also means an explicit `fontSize: 0` is now sent like any other value. 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 fontSize with props diffing Test Plan: `AndroidTextInputPropsDiffTest.removedFontSizeIsSentAsNull` 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 | 8 ++++++-- .../tests/AndroidTextInputPropsDiffTest.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 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 ad0296c3f010..1498b534ba1c 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 @@ -11,6 +11,7 @@ #include #include #include +#include namespace facebook::react { @@ -625,8 +626,11 @@ folly::dynamic AndroidTextInputProps::getDiffProps( result["letterSpacing"] = letterSpacing; } - if (fontSize != oldProps->fontSize) { - result["fontSize"] = fontSize; + if (!floatEquality( + textAttributes.fontSize, oldProps->textAttributes.fontSize)) { + result["fontSize"] = std::isnan(textAttributes.fontSize) + ? folly::dynamic(nullptr) + : textAttributes.fontSize; } if (textAlign != oldProps->textAlign) { 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 d549c31fd8d9..7928294876b1 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 @@ -55,6 +55,18 @@ TEST(AndroidTextInputPropsDiffTest, removedColorsAreSentAsNull) { } } +// 0 is the default of the flat field, and a font size of 0 hides the +// placeholder and new text. +TEST(AndroidTextInputPropsDiffTest, removedFontSizeIsSentAsNull) { + using folly::dynamic; + expectPayloadsMatchRawProps({ + {dynamic::object("fontSize", 20)}, + {dynamic::object("fontSize", 0)}, + {dynamic::object("fontSize", 20)}, + {dynamic::object("fontSize", nullptr)}, + }); +} + } // namespace facebook::react #endif From bae8a08366f1db356683ed09f6e45a049005861d Mon Sep 17 00:00:00 2001 From: Dawid Malecki Date: Wed, 4 Nov 2026 13:22:06 +0100 Subject: [PATCH 5/6] Send TextInput fontVariant when props diffing is enabled Summary: `AndroidTextInputProps::getDiffProps` never sent `fontVariant`, so the prop had no effect on the native view with props diffing on. `ReactTextInputManager` reads an array, and `textAttributes.fontVariant` can't produce one that matches what JS sent: the `FontVariant` enum has no ligature or contextual values, although `ReactTypefaceUtils.parseFontVariant` supports them. This adds a flat field that keeps the array from JS and sends it as is, and `null` when it is removed. 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 fontVariant when props diffing is enabled Test Plan: `AndroidTextInputPropsDiffTest.fontVariantIsSentAsAnArray` 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 | 7 +++++++ .../androidtextinput/AndroidTextInputProps.h | 2 ++ .../tests/AndroidTextInputPropsDiffTest.cpp | 12 ++++++++++++ .../api-snapshots/ReactAndroidFrameworksCxx.api | 1 + 4 files changed, 22 insertions(+) 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 1498b534ba1c..be62807fbe0c 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 @@ -158,6 +158,7 @@ AndroidTextInputProps::AndroidTextInputProps( {false})), fontWeight(convertRawProp(context, rawProps, "fontWeight", sourceProps.fontWeight, {})), fontFamily(convertRawProp(context, rawProps, "fontFamily", sourceProps.fontFamily, {})), + fontVariant(convertRawProp(context, rawProps, "fontVariant", sourceProps.fontVariant, {})), onKeyPress(convertRawProp(context, rawProps, "onKeyPress", sourceProps.onKeyPress, {false})), onSelectionChange(convertRawProp(context, rawProps, "onSelectionChange", @@ -244,6 +245,7 @@ void AndroidTextInputProps::setProp( RAW_SET_PROP_SWITCH_CASE_BASIC(includeFontPadding); RAW_SET_PROP_SWITCH_CASE_BASIC(fontWeight); RAW_SET_PROP_SWITCH_CASE_BASIC(fontFamily); + RAW_SET_PROP_SWITCH_CASE_BASIC(fontVariant); RAW_SET_PROP_SWITCH_CASE_BASIC(onKeyPress); RAW_SET_PROP_SWITCH_CASE_BASIC(onSelectionChange); RAW_SET_PROP_SWITCH_CASE_BASIC(onContentSizeChange); @@ -649,6 +651,11 @@ folly::dynamic AndroidTextInputProps::getDiffProps( result["fontFamily"] = fontFamily; } + if (fontVariant != oldProps->fontVariant) { + result["fontVariant"] = + fontVariant.has_value() ? toDynamic(fontVariant.value()) : nullptr; + } + if (textAttributes.fontVariationSettings != oldProps->textAttributes.fontVariationSettings) { result["fontVariationSettings"] = diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h index 32b3070d33e2..76bcec3ce466 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h @@ -17,6 +17,7 @@ #include #include #include +#include namespace facebook::react { @@ -108,6 +109,7 @@ class AndroidTextInputProps final : public BaseTextInputProps { bool includeFontPadding{false}; std::string fontWeight{}; std::string fontFamily{}; + std::optional> fontVariant{}; /* * Whether JS listens to these events. ReactTextInputManager only sets up the 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 7928294876b1..2fd5377a0456 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 @@ -67,6 +67,18 @@ TEST(AndroidTextInputPropsDiffTest, removedFontSizeIsSentAsNull) { }); } +// ReactTextInputManager reads an array, and supports values that the +// FontVariant enum in the text attributes can't represent. +TEST(AndroidTextInputPropsDiffTest, fontVariantIsSentAsAnArray) { + using folly::dynamic; + expectPayloadsMatchRawProps({ + {dynamic::object( + "fontVariant", dynamic::array("small-caps", "common-ligatures"))}, + {dynamic::object("fontVariant", dynamic::array())}, + {dynamic::object("fontVariant", nullptr)}, + }); +} + } // namespace facebook::react #endif diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api index 4efffc1f8cd2..a1973dcf4afa 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api @@ -1202,6 +1202,7 @@ class facebook::react::AndroidTextInputProps : public facebook::react::BaseTextI public folly::dynamic getDynamic() const; public int inlineImagePadding; public int numberOfLines; + public std::optional> fontVariant; public std::string autoComplete; public std::string fontFamily; public std::string fontStyle; From a793487494faa8421aa656a5470e2beef3f39bd7 Mon Sep 17 00:00:00 2001 From: Dawid Malecki Date: Wed, 4 Nov 2026 13:22:11 +0100 Subject: [PATCH 6/6] 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