From 601fae6bd0c9209114c9154ec68c49578664e365 Mon Sep 17 00:00:00 2001 From: Dawid Malecki Date: Wed, 4 Nov 2026 13:19:13 +0100 Subject: [PATCH 1/3] 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/3] 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/3] 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