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
This commit is contained in:
David Vacca 2019-10-24 19:53:05 -07:00 коммит произвёл Facebook Github Bot
Родитель 34816f4d47
Коммит 13db6cb731
3 изменённых файлов: 16 добавлений и 2 удалений

Просмотреть файл

@ -6,6 +6,7 @@
*/
#include "ParagraphShadowNode.h"
#include <Glog/logging.h>
#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

Просмотреть файл

@ -8,6 +8,7 @@
#pragma once
#include <react/attributedstring/AttributedString.h>
#include <react/attributedstring/ParagraphAttributes.h>
#include <react/textlayoutmanager/TextLayoutManager.h>
#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 &paragraphAttributes,
SharedTextLayoutManager const &layoutManager)
: attributedString(attributedString), layoutManager(layoutManager) {}
: attributedString(attributedString),
paragraphAttributes(paragraphAttributes),
layoutManager(layoutManager) {}
ParagraphState() = default;
ParagraphState(folly::dynamic const &data) {
assert(false && "Not supported");

Просмотреть файл

@ -16,6 +16,8 @@ namespace react {
inline folly::dynamic toDynamic(ParagraphState const &paragraphState) {
folly::dynamic newState = folly::dynamic::object();
newState["attributedString"] = toDynamic(paragraphState.attributedString);
newState["paragraphAttributes"] =
toDynamic(paragraphState.paragraphAttributes);
newState["hash"] = newState["attributedString"]["hash"];
return newState;
}