Skip to content

Commit d78d97a

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 20db8e0 commit d78d97a

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
@@ -222,6 +222,7 @@ AndroidTextInputProps::AndroidTextInputProps(
222222
{false})),
223223
fontWeight(convertFontWeight(context, rawProps, sourceProps.fontWeight)),
224224
fontFamily(convertRawProp(context, rawProps, "fontFamily", sourceProps.fontFamily, {})),
225+
fontVariant(convertRawProp(context, rawProps, "fontVariant", sourceProps.fontVariant, {})),
225226
textInputEvents(convertRawProp(context, rawProps, sourceProps.textInputEvents)),
226227
// See AndroidTextInputComponentDescriptor for usage
227228
// TODO T63008435: can these, and this feature, be removed entirely?
@@ -308,6 +309,7 @@ void AndroidTextInputProps::setProp(
308309
RAW_SET_PROP_SWITCH_CASE_BASIC(textAlign);
309310
RAW_SET_PROP_SWITCH_CASE_BASIC(includeFontPadding);
310311
RAW_SET_PROP_SWITCH_CASE_BASIC(fontFamily);
312+
RAW_SET_PROP_SWITCH_CASE_BASIC(fontVariant);
311313
TEXT_INPUT_EVENT_CASE(KeyPress);
312314
TEXT_INPUT_EVENT_CASE(SelectionChange);
313315
TEXT_INPUT_EVENT_CASE(ContentSizeChange);
@@ -721,6 +723,11 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
721723
result["fontFamily"] = fontFamily;
722724
}
723725

726+
if (fontVariant != oldProps->fontVariant) {
727+
result["fontVariant"] =
728+
fontVariant.has_value() ? toDynamic(fontVariant.value()) : nullptr;
729+
}
730+
724731
if (textAttributes.fontVariationSettings !=
725732
oldProps->textAttributes.fontVariationSettings) {
726733
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
@@ -18,6 +18,7 @@
1818
#include <react/renderer/components/textinput/basePrimitives.h>
1919
#include <cstdint>
2020
#include <unordered_map>
21+
#include <vector>
2122

2223
namespace facebook::react {
2324

@@ -138,6 +139,7 @@ class AndroidTextInputProps final : public BaseTextInputProps {
138139
bool includeFontPadding{false};
139140
std::string fontWeight{};
140141
std::string fontFamily{};
142+
std::optional<std::vector<std::string>> fontVariant{};
141143

142144
// Named so it doesn't hide BaseViewProps::events.
143145
AndroidTextInputEvents textInputEvents{};

‎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)