From bae8a08366f1db356683ed09f6e45a049005861d 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 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;