Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ hasValue(const RawProps& rawProps, bool defaultValue, const char* name) {
return false;
}

// Some ReactTextInputManager setters treat an empty string differently from
// null, which is what raw props send for a removed prop.
static folly::dynamic stringOrNull(const std::string& value) {
return value.empty() ? folly::dynamic(nullptr) : folly::dynamic(value);
}

// ReactTextInputManager resets a color to the platform default for null, while
// 0 is transparent.
static folly::dynamic colorOrNull(const SharedColor& color) {
Expand Down Expand Up @@ -516,11 +522,11 @@ folly::dynamic AndroidTextInputProps::getDiffProps(

// Android text input props
if (autoComplete != oldProps->autoComplete) {
result["autoComplete"] = autoComplete;
result["autoComplete"] = stringOrNull(autoComplete);
}

if (returnKeyLabel != oldProps->returnKeyLabel) {
result["returnKeyLabel"] = returnKeyLabel;
result["returnKeyLabel"] = stringOrNull(returnKeyLabel);
}

if (numberOfLines != oldProps->numberOfLines) {
Expand Down Expand Up @@ -636,7 +642,7 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
}

if (textAlign != oldProps->textAlign) {
result["textAlign"] = textAlign;
result["textAlign"] = stringOrNull(textAlign);
}

if (includeFontPadding != oldProps->includeFontPadding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ TEST(AndroidTextInputPropsDiffTest, fontVariantIsSentAsAnArray) {
});
}

// ReactTextInputManager treats an empty string differently from null for these:
// a blank IME action label, or a warning about an invalid value.
TEST(AndroidTextInputPropsDiffTest, removedStringsAreSentAsNull) {
using folly::dynamic;
expectPayloadsMatchRawProps<AndroidTextInputProps>({
{dynamic::object("returnKeyLabel", "Go")("autoComplete", "email")(
"textAlign", "center")},
{dynamic::object("returnKeyLabel", nullptr)("autoComplete", nullptr)(
"textAlign", nullptr)},
});
}

} // namespace facebook::react

#endif
Loading