Add getDiffProps for Paragraph component (#51219)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51219

See title

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D74473177

fbshipit-source-id: 88d8d29a1640fd9217460ac04f172f821bb47a91
This commit is contained in:
Nick Lefever
2025-05-12 04:01:03 -07:00
committed by Facebook GitHub Bot
parent 571a0ae7bc
commit 3edc8d4e2c
3 changed files with 80 additions and 1 deletions
@@ -227,7 +227,8 @@ jni::local_ref<jobject> getProps(
strcmp(newShadowView.componentName, "Image") == 0 ||
strcmp(newShadowView.componentName, "ScrollView") == 0 ||
strcmp(newShadowView.componentName, "RawText") == 0 ||
strcmp(newShadowView.componentName, "Text") == 0)) {
strcmp(newShadowView.componentName, "Text") == 0 ||
strcmp(newShadowView.componentName, "Paragraph") == 0)) {
return ReadableNativeMap::newObjectCxxArgs(
newProps->getDiffProps(oldProps));
}
@@ -152,4 +152,76 @@ SharedDebugStringConvertibleList ParagraphProps::getDebugProps() const {
}
#endif
#ifdef ANDROID
folly::dynamic ParagraphProps::getDiffProps(const Props* prevProps) const {
static const auto defaultProps = ParagraphProps();
const ParagraphProps* oldProps = prevProps == nullptr
? &defaultProps
: static_cast<const ParagraphProps*>(prevProps);
folly::dynamic result = ViewProps::getDiffProps(oldProps);
BaseTextProps::appendTextAttributesProps(result, oldProps);
if (paragraphAttributes.maximumNumberOfLines !=
oldProps->paragraphAttributes.maximumNumberOfLines) {
result["numberOfLine"] = paragraphAttributes.maximumNumberOfLines;
}
if (paragraphAttributes.ellipsizeMode !=
oldProps->paragraphAttributes.ellipsizeMode) {
result["ellipsizeMode"] = toString(paragraphAttributes.ellipsizeMode);
}
if (paragraphAttributes.textBreakStrategy !=
oldProps->paragraphAttributes.textBreakStrategy) {
result["textBreakStrategy"] =
toString(paragraphAttributes.textBreakStrategy);
}
if (paragraphAttributes.adjustsFontSizeToFit !=
oldProps->paragraphAttributes.adjustsFontSizeToFit) {
result["adjustsFontSizeToFit"] = paragraphAttributes.adjustsFontSizeToFit;
}
if (paragraphAttributes.minimumFontScale !=
oldProps->paragraphAttributes.minimumFontScale) {
result["minimumFontScale"] = paragraphAttributes.minimumFontScale;
}
if (paragraphAttributes.minimumFontSize !=
oldProps->paragraphAttributes.minimumFontSize) {
result["minimumFontSize"] = paragraphAttributes.minimumFontSize;
}
if (paragraphAttributes.maximumFontSize !=
oldProps->paragraphAttributes.maximumFontSize) {
result["maximumFontSize"] = paragraphAttributes.maximumFontSize;
}
if (paragraphAttributes.includeFontPadding !=
oldProps->paragraphAttributes.includeFontPadding) {
result["includeFontPadding"] = paragraphAttributes.includeFontPadding;
}
if (paragraphAttributes.android_hyphenationFrequency !=
oldProps->paragraphAttributes.android_hyphenationFrequency) {
result["android_hyphenationFrequency"] =
toString(paragraphAttributes.android_hyphenationFrequency);
}
if (isSelectable != oldProps->isSelectable) {
result["selectable"] = isSelectable;
}
if (onTextLayout != oldProps->onTextLayout) {
result["onTextLayout"] = onTextLayout;
}
return result;
}
#endif
} // namespace facebook::react
@@ -57,6 +57,12 @@ class ParagraphProps : public ViewProps, public BaseTextProps {
#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList getDebugProps() const override;
#endif
#ifdef ANDROID
folly::dynamic getDiffProps(const Props* prevProps) const override;
#endif
};
} // namespace facebook::react