mirror of
https://github.com/status-im/react-native.git
synced 2025-01-29 10:45:04 +00:00
67a79010ca
Summary: @public Previously, all ConcreteShadowNode subclasses had to override `getComponentName()` function to specialize a name of the component. And often it was all that those subclasses do. Now, it's a template argument; and many ShadowNode classes can be created as oneliners via *just* specializing ConcreteShadowNode template. Unfortunately, C++ does not allow to use `std::string`s or string literals as template arguments, but it allows to use pointers. Moreover, those pointers must point to some linked data, hence, those values must be declared in .cpp (not .h) files. For simplicity, we put those constants in Props classes, (but this is not a strong requirement). Reviewed By: mdvacca Differential Revision: D8942826 fbshipit-source-id: 4fd517e2485eb8f8c20a51df9b3496941856d8a5
76 lines
2.0 KiB
C++
76 lines
2.0 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/components/text/ParagraphProps.h>
|
|
#include <fabric/components/text/TextShadowNode.h>
|
|
#include <fabric/components/view/ConcreteViewShadowNode.h>
|
|
#include <fabric/core/ConcreteShadowNode.h>
|
|
#include <fabric/core/ShadowNode.h>
|
|
#include <fabric/core/LayoutContext.h>
|
|
#include <fabric/textlayoutmanager/TextLayoutManager.h>
|
|
#include <folly/Optional.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
extern const char ParagraphComponentName[];
|
|
|
|
/*
|
|
* `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<
|
|
ParagraphComponentName,
|
|
ParagraphProps
|
|
>,
|
|
public BaseTextShadowNode {
|
|
|
|
public:
|
|
|
|
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
|
|
|
/*
|
|
* 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_;
|
|
|
|
/*
|
|
* Cached attributed string that represents the content of the subtree started
|
|
* from the node.
|
|
*/
|
|
mutable folly::Optional<AttributedString> cachedAttributedString_ {};
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|