Skip to content

Commit 3edc8d4

Browse files
Nick Lefeverfacebook-github-bot
authored andcommitted
Add getDiffProps for Paragraph component (facebook#51219)
Summary: Pull Request resolved: facebook#51219 See title Changelog: [Internal] Reviewed By: javache Differential Revision: D74473177 fbshipit-source-id: 88d8d29a1640fd9217460ac04f172f821bb47a91
1 parent 571a0ae commit 3edc8d4

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ jni::local_ref<jobject> getProps(
227227
strcmp(newShadowView.componentName, "Image") == 0 ||
228228
strcmp(newShadowView.componentName, "ScrollView") == 0 ||
229229
strcmp(newShadowView.componentName, "RawText") == 0 ||
230-
strcmp(newShadowView.componentName, "Text") == 0)) {
230+
strcmp(newShadowView.componentName, "Text") == 0 ||
231+
strcmp(newShadowView.componentName, "Paragraph") == 0)) {
231232
return ReadableNativeMap::newObjectCxxArgs(
232233
newProps->getDiffProps(oldProps));
233234
}

packages/react-native/ReactCommon/react/renderer/components/text/ParagraphProps.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,76 @@ SharedDebugStringConvertibleList ParagraphProps::getDebugProps() const {
152152
}
153153
#endif
154154

155+
#ifdef ANDROID
156+
157+
folly::dynamic ParagraphProps::getDiffProps(const Props* prevProps) const {
158+
static const auto defaultProps = ParagraphProps();
159+
160+
const ParagraphProps* oldProps = prevProps == nullptr
161+
? &defaultProps
162+
: static_cast<const ParagraphProps*>(prevProps);
163+
164+
folly::dynamic result = ViewProps::getDiffProps(oldProps);
165+
166+
BaseTextProps::appendTextAttributesProps(result, oldProps);
167+
168+
if (paragraphAttributes.maximumNumberOfLines !=
169+
oldProps->paragraphAttributes.maximumNumberOfLines) {
170+
result["numberOfLine"] = paragraphAttributes.maximumNumberOfLines;
171+
}
172+
173+
if (paragraphAttributes.ellipsizeMode !=
174+
oldProps->paragraphAttributes.ellipsizeMode) {
175+
result["ellipsizeMode"] = toString(paragraphAttributes.ellipsizeMode);
176+
}
177+
178+
if (paragraphAttributes.textBreakStrategy !=
179+
oldProps->paragraphAttributes.textBreakStrategy) {
180+
result["textBreakStrategy"] =
181+
toString(paragraphAttributes.textBreakStrategy);
182+
}
183+
184+
if (paragraphAttributes.adjustsFontSizeToFit !=
185+
oldProps->paragraphAttributes.adjustsFontSizeToFit) {
186+
result["adjustsFontSizeToFit"] = paragraphAttributes.adjustsFontSizeToFit;
187+
}
188+
189+
if (paragraphAttributes.minimumFontScale !=
190+
oldProps->paragraphAttributes.minimumFontScale) {
191+
result["minimumFontScale"] = paragraphAttributes.minimumFontScale;
192+
}
193+
194+
if (paragraphAttributes.minimumFontSize !=
195+
oldProps->paragraphAttributes.minimumFontSize) {
196+
result["minimumFontSize"] = paragraphAttributes.minimumFontSize;
197+
}
198+
199+
if (paragraphAttributes.maximumFontSize !=
200+
oldProps->paragraphAttributes.maximumFontSize) {
201+
result["maximumFontSize"] = paragraphAttributes.maximumFontSize;
202+
}
203+
204+
if (paragraphAttributes.includeFontPadding !=
205+
oldProps->paragraphAttributes.includeFontPadding) {
206+
result["includeFontPadding"] = paragraphAttributes.includeFontPadding;
207+
}
208+
209+
if (paragraphAttributes.android_hyphenationFrequency !=
210+
oldProps->paragraphAttributes.android_hyphenationFrequency) {
211+
result["android_hyphenationFrequency"] =
212+
toString(paragraphAttributes.android_hyphenationFrequency);
213+
}
214+
215+
if (isSelectable != oldProps->isSelectable) {
216+
result["selectable"] = isSelectable;
217+
}
218+
219+
if (onTextLayout != oldProps->onTextLayout) {
220+
result["onTextLayout"] = onTextLayout;
221+
}
222+
223+
return result;
224+
}
225+
226+
#endif
155227
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/components/text/ParagraphProps.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ class ParagraphProps : public ViewProps, public BaseTextProps {
5757
#if RN_DEBUG_STRING_CONVERTIBLE
5858
SharedDebugStringConvertibleList getDebugProps() const override;
5959
#endif
60+
61+
#ifdef ANDROID
62+
63+
folly::dynamic getDiffProps(const Props* prevProps) const override;
64+
65+
#endif
6066
};
6167

6268
} // namespace facebook::react

0 commit comments

Comments
 (0)