From 13db6cb731130ba5200043c8fdbc5da27c467c02 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Thu, 24 Oct 2019 19:53:05 -0700 Subject: [PATCH] Expose ParagraphAttributes into ParagraphState Summary: This diff extends ParagraphState to expose not only the AttributedString associated to Text components, but also ParagraphAttributes that describes the visual high level props of the Paragraph Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D18101407 fbshipit-source-id: 5f5d5ca35cc03e4bf983fd24654be9506d1901a1 --- .../text/paragraph/ParagraphShadowNode.cpp | 4 +++- .../components/text/paragraph/ParagraphState.h | 12 +++++++++++- .../fabric/components/text/paragraph/conversions.h | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp index ee02779f8b..85f1f849c7 100644 --- a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp +++ b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp @@ -6,6 +6,7 @@ */ #include "ParagraphShadowNode.h" +#include #include "ParagraphMeasurementCache.h" #include "ParagraphState.h" @@ -54,7 +55,8 @@ void ParagraphShadowNode::updateStateIfNeeded() { return; } - setStateData(ParagraphState{attributedString, textLayoutManager_}); + setStateData(ParagraphState{ + attributedString, getProps()->paragraphAttributes, textLayoutManager_}); } #pragma mark - LayoutableShadowNode diff --git a/ReactCommon/fabric/components/text/paragraph/ParagraphState.h b/ReactCommon/fabric/components/text/paragraph/ParagraphState.h index cb9c4c4f1c..e9726898ab 100644 --- a/ReactCommon/fabric/components/text/paragraph/ParagraphState.h +++ b/ReactCommon/fabric/components/text/paragraph/ParagraphState.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #ifdef ANDROID @@ -28,6 +29,12 @@ class ParagraphState final { */ AttributedString attributedString; + /* + * Represents all visual attributes of a paragraph of text represented as + * a ParagraphAttributes. + */ + ParagraphAttributes paragraphAttributes; + /* * `TextLayoutManager` provides a connection to platform-specific * text rendering infrastructure which is capable to render the @@ -38,8 +45,11 @@ class ParagraphState final { #ifdef ANDROID ParagraphState( AttributedString const &attributedString, + ParagraphAttributes const ¶graphAttributes, SharedTextLayoutManager const &layoutManager) - : attributedString(attributedString), layoutManager(layoutManager) {} + : attributedString(attributedString), + paragraphAttributes(paragraphAttributes), + layoutManager(layoutManager) {} ParagraphState() = default; ParagraphState(folly::dynamic const &data) { assert(false && "Not supported"); diff --git a/ReactCommon/fabric/components/text/paragraph/conversions.h b/ReactCommon/fabric/components/text/paragraph/conversions.h index 900cea332f..9e1f2f1f91 100644 --- a/ReactCommon/fabric/components/text/paragraph/conversions.h +++ b/ReactCommon/fabric/components/text/paragraph/conversions.h @@ -16,6 +16,8 @@ namespace react { inline folly::dynamic toDynamic(ParagraphState const ¶graphState) { folly::dynamic newState = folly::dynamic::object(); newState["attributedString"] = toDynamic(paragraphState.attributedString); + newState["paragraphAttributes"] = + toDynamic(paragraphState.paragraphAttributes); newState["hash"] = newState["attributedString"]["hash"]; return newState; }