Skip to content

Commit bae8a08

Browse files
coadoclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 6deaee7 commit bae8a08

4 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ AndroidTextInputProps::AndroidTextInputProps(
158158
{false})),
159159
fontWeight(convertRawProp(context, rawProps, "fontWeight", sourceProps.fontWeight, {})),
160160
fontFamily(convertRawProp(context, rawProps, "fontFamily", sourceProps.fontFamily, {})),
161+
fontVariant(convertRawProp(context, rawProps, "fontVariant", sourceProps.fontVariant, {})),
161162
onKeyPress(convertRawProp(context, rawProps, "onKeyPress", sourceProps.onKeyPress, {false})),
162163
onSelectionChange(convertRawProp(context, rawProps,
163164
"onSelectionChange",
@@ -244,6 +245,7 @@ void AndroidTextInputProps::setProp(
244245
RAW_SET_PROP_SWITCH_CASE_BASIC(includeFontPadding);
245246
RAW_SET_PROP_SWITCH_CASE_BASIC(fontWeight);
246247
RAW_SET_PROP_SWITCH_CASE_BASIC(fontFamily);
248+
RAW_SET_PROP_SWITCH_CASE_BASIC(fontVariant);
247249
RAW_SET_PROP_SWITCH_CASE_BASIC(onKeyPress);
248250
RAW_SET_PROP_SWITCH_CASE_BASIC(onSelectionChange);
249251
RAW_SET_PROP_SWITCH_CASE_BASIC(onContentSizeChange);
@@ -649,6 +651,11 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
649651
result["fontFamily"] = fontFamily;
650652
}
651653

654+
if (fontVariant != oldProps->fontVariant) {
655+
result["fontVariant"] =
656+
fontVariant.has_value() ? toDynamic(fontVariant.value()) : nullptr;
657+
}
658+
652659
if (textAttributes.fontVariationSettings !=
653660
oldProps->textAttributes.fontVariationSettings) {
654661
result["fontVariationSettings"] =

‎packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputProps.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <react/renderer/components/textinput/BaseTextInputProps.h>
1818
#include <react/renderer/components/textinput/basePrimitives.h>
1919
#include <unordered_map>
20+
#include <vector>
2021

2122
namespace facebook::react {
2223

@@ -108,6 +109,7 @@ class AndroidTextInputProps final : public BaseTextInputProps {
108109
bool includeFontPadding{false};
109110
std::string fontWeight{};
110111
std::string fontFamily{};
112+
std::optional<std::vector<std::string>> fontVariant{};
111113

112114
/*
113115
* Whether JS listens to these events. ReactTextInputManager only sets up the

‎packages/react-native/ReactCommon/react/renderer/components/textinput/tests/AndroidTextInputPropsDiffTest.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ TEST(AndroidTextInputPropsDiffTest, removedFontSizeIsSentAsNull) {
6767
});
6868
}
6969

70+
// ReactTextInputManager reads an array, and supports values that the
71+
// FontVariant enum in the text attributes can't represent.
72+
TEST(AndroidTextInputPropsDiffTest, fontVariantIsSentAsAnArray) {
73+
using folly::dynamic;
74+
expectPayloadsMatchRawProps<AndroidTextInputProps>({
75+
{dynamic::object(
76+
"fontVariant", dynamic::array("small-caps", "common-ligatures"))},
77+
{dynamic::object("fontVariant", dynamic::array())},
78+
{dynamic::object("fontVariant", nullptr)},
79+
});
80+
}
81+
7082
} // namespace facebook::react
7183

7284
#endif

‎scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,7 @@ class facebook::react::AndroidTextInputProps : public facebook::react::BaseTextI
12021202
public folly::dynamic getDynamic() const;
12031203
public int inlineImagePadding;
12041204
public int numberOfLines;
1205+
public std::optional<std::vector<std::string>> fontVariant;
12051206
public std::string autoComplete;
12061207
public std::string fontFamily;
12071208
public std::string fontStyle;

0 commit comments

Comments
 (0)