Skip to content

Commit 6deaee7

Browse files
coadoclaude
andcommitted
Send null when removing TextInput fontSize with props diffing
Summary: `fontSize` was sent from a flat field that defaults to 0, so removing it called `setFontSize(0)` and made the placeholder and any new text invisible. This sends `fontSize` from `textAttributes.fontSize`, which is NaN when unset, and sends `null` when it is removed. `ReactTextInputManager` then applies its default font size, the same as with raw props. It also means an explicit `fontSize: 0` is now sent like any other value. 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 fontSize with props diffing Test Plan: `AndroidTextInputPropsDiffTest.removedFontSizeIsSentAsNull` 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 3a3b8bf commit 6deaee7

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <react/renderer/core/graphicsConversions.h>
1212
#include <react/renderer/core/propsConversions.h>
1313
#include <react/utils/FloatComparison.h>
14+
#include <cmath>
1415

1516
namespace facebook::react {
1617

@@ -625,8 +626,11 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
625626
result["letterSpacing"] = letterSpacing;
626627
}
627628

628-
if (fontSize != oldProps->fontSize) {
629-
result["fontSize"] = fontSize;
629+
if (!floatEquality(
630+
textAttributes.fontSize, oldProps->textAttributes.fontSize)) {
631+
result["fontSize"] = std::isnan(textAttributes.fontSize)
632+
? folly::dynamic(nullptr)
633+
: textAttributes.fontSize;
630634
}
631635

632636
if (textAlign != oldProps->textAlign) {

‎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
@@ -55,6 +55,18 @@ TEST(AndroidTextInputPropsDiffTest, removedColorsAreSentAsNull) {
5555
}
5656
}
5757

58+
// 0 is the default of the flat field, and a font size of 0 hides the
59+
// placeholder and new text.
60+
TEST(AndroidTextInputPropsDiffTest, removedFontSizeIsSentAsNull) {
61+
using folly::dynamic;
62+
expectPayloadsMatchRawProps<AndroidTextInputProps>({
63+
{dynamic::object("fontSize", 20)},
64+
{dynamic::object("fontSize", 0)},
65+
{dynamic::object("fontSize", 20)},
66+
{dynamic::object("fontSize", nullptr)},
67+
});
68+
}
69+
5870
} // namespace facebook::react
5971

6072
#endif

0 commit comments

Comments
 (0)