From d78d97ac9ca9997334659fcdf55c0be2c770b2f8 Mon Sep 17 00:00:00 2001 From: Dawid Malecki Date: Wed, 4 Nov 2026 13:22:06 +0100 Subject: [PATCH] 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 761ee0b4ec4e..48dd90691b8b 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 @@ -222,6 +222,7 @@ AndroidTextInputProps::AndroidTextInputProps( {false})), fontWeight(convertFontWeight(context, rawProps, sourceProps.fontWeight)), fontFamily(convertRawProp(context, rawProps, "fontFamily", sourceProps.fontFamily, {})), + fontVariant(convertRawProp(context, rawProps, "fontVariant", sourceProps.fontVariant, {})), textInputEvents(convertRawProp(context, rawProps, sourceProps.textInputEvents)), // See AndroidTextInputComponentDescriptor for usage // TODO T63008435: can these, and this feature, be removed entirely? @@ -308,6 +309,7 @@ void AndroidTextInputProps::setProp( RAW_SET_PROP_SWITCH_CASE_BASIC(textAlign); RAW_SET_PROP_SWITCH_CASE_BASIC(includeFontPadding); RAW_SET_PROP_SWITCH_CASE_BASIC(fontFamily); + RAW_SET_PROP_SWITCH_CASE_BASIC(fontVariant); TEXT_INPUT_EVENT_CASE(KeyPress); TEXT_INPUT_EVENT_CASE(SelectionChange); TEXT_INPUT_EVENT_CASE(ContentSizeChange); @@ -721,6 +723,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 0c4508649496..b952f6848cc2 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 @@ -18,6 +18,7 @@ #include #include #include +#include namespace facebook::react { @@ -138,6 +139,7 @@ class AndroidTextInputProps final : public BaseTextInputProps { bool includeFontPadding{false}; std::string fontWeight{}; std::string fontFamily{}; + std::optional> fontVariant{}; // Named so it doesn't hide BaseViewProps::events. AndroidTextInputEvents textInputEvents{}; 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 f5c61e289aff..76d758ee0e62 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;