Skip to content

Commit 0cdf5c1

Browse files
Nick Lefeverfacebook-github-bot
authored andcommitted
Add updateDiffProps to BaseTextProps (facebook#51217)
Summary: Pull Request resolved: facebook#51217 Add helper method to build the prop diffing based on the BaseTextProps which are used by the Text and Paragraph props. Changelog: [Internal] Reviewed By: javache Differential Revision: D74473004 fbshipit-source-id: 0ae8c0c033ee136da3b8376bd485f8926310dcd4
1 parent 3461e98 commit 0cdf5c1

File tree

2 files changed

+198
-0
lines changed

2 files changed

+198
-0
lines changed

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

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,194 @@ SharedDebugStringConvertibleList BaseTextProps::getDebugProps() const {
356356
}
357357
#endif
358358

359+
#ifdef ANDROID
360+
361+
static folly::dynamic toDynamic(const Size& size) {
362+
folly::dynamic sizeResult = folly::dynamic::object();
363+
sizeResult["width"] = size.width;
364+
sizeResult["height"] = size.height;
365+
return sizeResult;
366+
}
367+
368+
void BaseTextProps::appendTextAttributesProps(
369+
folly::dynamic& result,
370+
const BaseTextProps* oldProps) const {
371+
if (textAttributes.foregroundColor !=
372+
oldProps->textAttributes.foregroundColor) {
373+
result["color"] = *textAttributes.foregroundColor;
374+
}
375+
376+
if (textAttributes.fontFamily != oldProps->textAttributes.fontFamily) {
377+
result["fontFamily"] = textAttributes.fontFamily;
378+
}
379+
380+
if (textAttributes.fontSize != oldProps->textAttributes.fontSize) {
381+
result["fontSize"] = textAttributes.fontSize;
382+
}
383+
384+
if (textAttributes.fontSizeMultiplier !=
385+
oldProps->textAttributes.fontSizeMultiplier) {
386+
result["fontSizeMultiplier"] = textAttributes.fontSizeMultiplier;
387+
}
388+
389+
if (textAttributes.fontWeight != oldProps->textAttributes.fontWeight) {
390+
result["fontWeight"] = textAttributes.fontWeight.has_value()
391+
? toString(textAttributes.fontWeight.value())
392+
: nullptr;
393+
}
394+
395+
if (textAttributes.fontStyle != oldProps->textAttributes.fontStyle) {
396+
result["fontStyle"] = textAttributes.fontStyle.has_value()
397+
? toString(textAttributes.fontStyle.value())
398+
: nullptr;
399+
}
400+
401+
if (textAttributes.fontVariant != oldProps->textAttributes.fontVariant) {
402+
result["fontVariant"] = textAttributes.fontVariant.has_value()
403+
? toString(textAttributes.fontVariant.value())
404+
: nullptr;
405+
}
406+
407+
if (textAttributes.allowFontScaling !=
408+
oldProps->textAttributes.allowFontScaling) {
409+
result["allowFontScaling"] = textAttributes.allowFontScaling.has_value()
410+
? textAttributes.allowFontScaling.value()
411+
: folly::dynamic(nullptr);
412+
}
413+
414+
if (textAttributes.maxFontSizeMultiplier !=
415+
oldProps->textAttributes.maxFontSizeMultiplier) {
416+
result["maxFontSizeMultiplier"] = textAttributes.maxFontSizeMultiplier;
417+
}
418+
419+
if (textAttributes.dynamicTypeRamp !=
420+
oldProps->textAttributes.dynamicTypeRamp) {
421+
result["dynamicTypeRamp"] = textAttributes.dynamicTypeRamp.has_value()
422+
? toString(textAttributes.dynamicTypeRamp.value())
423+
: nullptr;
424+
}
425+
426+
if (textAttributes.letterSpacing != oldProps->textAttributes.letterSpacing) {
427+
result["letterSpacing"] = textAttributes.letterSpacing;
428+
}
429+
430+
if (textAttributes.textTransform != oldProps->textAttributes.textTransform) {
431+
result["textTransform"] = textAttributes.textTransform.has_value()
432+
? toString(textAttributes.textTransform.value())
433+
: nullptr;
434+
}
435+
436+
if (textAttributes.textAlignVertical !=
437+
oldProps->textAttributes.textAlignVertical) {
438+
result["textAlignVertical"] = textAttributes.textAlignVertical.has_value()
439+
? toString(textAttributes.textAlignVertical.value())
440+
: nullptr;
441+
}
442+
443+
if (textAttributes.lineHeight != oldProps->textAttributes.lineHeight) {
444+
result["lineHeight"] = textAttributes.lineHeight;
445+
}
446+
447+
if (textAttributes.alignment != oldProps->textAttributes.alignment) {
448+
result["textAlign"] = textAttributes.alignment.has_value()
449+
? toString(textAttributes.alignment.value())
450+
: nullptr;
451+
}
452+
453+
if (textAttributes.baseWritingDirection !=
454+
oldProps->textAttributes.baseWritingDirection) {
455+
result["baseWritingDirection"] =
456+
textAttributes.baseWritingDirection.has_value()
457+
? toString(textAttributes.baseWritingDirection.value())
458+
: nullptr;
459+
}
460+
461+
if (textAttributes.lineBreakStrategy !=
462+
oldProps->textAttributes.lineBreakStrategy) {
463+
result["lineBreakStrategyIOS"] =
464+
textAttributes.lineBreakStrategy.has_value()
465+
? toString(textAttributes.lineBreakStrategy.value())
466+
: nullptr;
467+
}
468+
469+
if (textAttributes.lineBreakMode != oldProps->textAttributes.lineBreakMode) {
470+
result["lineBreakModeIOS"] = textAttributes.lineBreakMode.has_value()
471+
? toString(textAttributes.lineBreakMode.value())
472+
: nullptr;
473+
}
474+
475+
if (textAttributes.textDecorationColor !=
476+
oldProps->textAttributes.textDecorationColor) {
477+
result["textDecorationColor"] = *textAttributes.textDecorationColor;
478+
}
479+
480+
if (textAttributes.textDecorationLineType !=
481+
oldProps->textAttributes.textDecorationLineType) {
482+
result["textDecorationLine"] =
483+
textAttributes.textDecorationLineType.has_value()
484+
? toString(textAttributes.textDecorationLineType.value())
485+
: nullptr;
486+
}
487+
488+
if (textAttributes.textDecorationStyle !=
489+
oldProps->textAttributes.textDecorationStyle) {
490+
result["textDecorationStyle"] =
491+
textAttributes.textDecorationStyle.has_value()
492+
? toString(textAttributes.textDecorationStyle.value())
493+
: nullptr;
494+
}
495+
496+
if (textAttributes.textShadowOffset !=
497+
oldProps->textAttributes.textShadowOffset) {
498+
result["textShadowOffset"] = textAttributes.textShadowOffset.has_value()
499+
? toDynamic(textAttributes.textShadowOffset.value())
500+
: nullptr;
501+
}
502+
503+
if (textAttributes.textShadowRadius !=
504+
oldProps->textAttributes.textShadowRadius) {
505+
result["textShadowRadius"] = textAttributes.textShadowRadius;
506+
}
507+
508+
if (textAttributes.textShadowColor !=
509+
oldProps->textAttributes.textShadowColor) {
510+
result["textShadowColor"] = *textAttributes.textShadowColor;
511+
}
512+
513+
if (textAttributes.isHighlighted != oldProps->textAttributes.isHighlighted) {
514+
result["isHighlighted"] = textAttributes.isHighlighted.has_value()
515+
? textAttributes.isHighlighted.value()
516+
: folly::dynamic(nullptr);
517+
}
518+
519+
if (textAttributes.isPressable != oldProps->textAttributes.isPressable) {
520+
result["isPressable"] = textAttributes.isPressable.has_value()
521+
? textAttributes.isPressable.value()
522+
: folly::dynamic(nullptr);
523+
}
524+
525+
if (textAttributes.accessibilityRole !=
526+
oldProps->textAttributes.accessibilityRole) {
527+
result["accessibilityRole"] = textAttributes.accessibilityRole.has_value()
528+
? toString(textAttributes.accessibilityRole.value())
529+
: nullptr;
530+
}
531+
532+
if (textAttributes.role != oldProps->textAttributes.role) {
533+
result["role"] = textAttributes.role.has_value()
534+
? toString(textAttributes.role.value())
535+
: nullptr;
536+
}
537+
538+
if (textAttributes.opacity != oldProps->textAttributes.opacity) {
539+
result["opacity"] = textAttributes.opacity;
540+
}
541+
542+
if (textAttributes.backgroundColor !=
543+
oldProps->textAttributes.backgroundColor) {
544+
result["backgroundColor"] = *textAttributes.backgroundColor;
545+
}
546+
}
547+
548+
#endif
359549
} // namespace facebook::react

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ class BaseTextProps {
4141
#if RN_DEBUG_STRING_CONVERTIBLE
4242
SharedDebugStringConvertibleList getDebugProps() const;
4343
#endif
44+
45+
#ifdef ANDROID
46+
47+
void appendTextAttributesProps(
48+
folly::dynamic& result,
49+
const BaseTextProps* prevProps) const;
50+
51+
#endif
4452
};
4553

4654
} // namespace facebook::react

0 commit comments

Comments
 (0)