react-native/ReactCommon/fabric/text/paragraph/ParagraphShadowNode.h
Valentin Shergin d9ff1769aa Fabric/Text: <Paragraph> is now supporting text attributes
Summary:
I was shamed by Sebastian's sebmarkbage concerns (totally unrelated to this topic) about introducing another level of indirection into the system and decided to change my original plan not to support text attributes for the <Paragraph> component.

So, now <Paragraph> shares <View>, <Text> and <Paragraph> itself capabilities. That reduces the minimum amount of required components for trivial text fragment from three (Paragraph, Text, RawText) to two (Paragraph and RawText).

Special thanks for C++ for supporting multiple inheritance.

Reviewed By: mdvacca

Differential Revision: D7785889

fbshipit-source-id: dd9f2e2650bfbfd76d7d4b538adaf409f9429df3
2018-05-08 19:24:10 -07:00

70 lines
1.8 KiB
C++

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <fabric/core/ConcreteShadowNode.h>
#include <fabric/core/ShadowNode.h>
#include <fabric/core/LayoutContext.h>
#include <fabric/text/ParagraphProps.h>
#include <fabric/text/TextShadowNode.h>
#include <fabric/textlayoutmanager/TextLayoutManager.h>
#include <fabric/view/ConcreteViewShadowNode.h>
namespace facebook {
namespace react {
class ParagraphShadowNode;
using SharedParagraphShadowNode = std::shared_ptr<const ParagraphShadowNode>;
/*
* `ShadowNode` for <Paragraph> component, represents <View>-like component
* containing and displaying text. Text content is represented as nested <Text>
* and <RawText> components.
*/
class ParagraphShadowNode:
public ConcreteViewShadowNode<ParagraphProps>,
public BaseTextShadowNode {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;
ComponentName getComponentName() const override;
/*
* Returns a `AttributedString` which represents text content of the node.
*/
AttributedString getAttributedString() const;
/*
* Associates a shared TextLayoutManager with the node.
* `ParagraphShadowNode` uses the manager to measure text content
* and construct `ParagraphLocalData` objects.
*/
void setTextLayoutManager(SharedTextLayoutManager textLayoutManager);
#pragma mark - LayoutableShadowNode
void layout(LayoutContext layoutContext) override;
Size measure(LayoutConstraints layoutConstraints) const override;
private:
/*
* Creates a `LocalData` object (with `AttributedText` and
* `TextLayoutManager`) if needed.
*/
void updateLocalData();
SharedTextLayoutManager textLayoutManager_;
};
} // namespace react
} // namespace facebook