Files
react-native/ReactCommon/react/renderer/components/text/ParagraphShadowNode.h
T
Valentin Shergin d6341c4fad Fabric: Using ShadowNodeTraits::Trait::MeasurableYogaNode in ParagraphShadowNode
Summary:
Similarly to D25937710 (https://github.com/facebook/react-native/commit/3d166a0a4c08fdaae9174625d7baba247f84fdea) we are moving away from using imperative methods that dirty Yoga node.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D26069354

fbshipit-source-id: 3d4e1bd4715a204d90174c7ea29b56438778bfa3
2021-01-31 22:21:51 -08:00

109 lines
3.4 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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 <folly/Optional.h>
#include <react/renderer/components/text/ParagraphEventEmitter.h>
#include <react/renderer/components/text/ParagraphProps.h>
#include <react/renderer/components/text/ParagraphState.h>
#include <react/renderer/components/text/TextShadowNode.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
#include <react/renderer/core/ConcreteShadowNode.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/core/ShadowNode.h>
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
namespace facebook {
namespace react {
extern char const 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,
ParagraphEventEmitter,
ParagraphState>,
public BaseTextShadowNode {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;
static ShadowNodeTraits BaseTraits() {
auto traits = ConcreteViewShadowNode::BaseTraits();
traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
traits.set(ShadowNodeTraits::Trait::TextKind);
traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
#ifdef ANDROID
// Unsetting `FormsStackingContext` trait is essential on Android where we
// can't mount views inside `TextView`.
traits.unset(ShadowNodeTraits::Trait::FormsStackingContext);
#endif
return traits;
}
/*
* Associates a shared TextLayoutManager with the node.
* `ParagraphShadowNode` uses the manager to measure text content
* and construct `ParagraphState` objects.
*/
void setTextLayoutManager(SharedTextLayoutManager textLayoutManager);
#pragma mark - LayoutableShadowNode
void layout(LayoutContext layoutContext) override;
Size measureContent(
LayoutContext const &layoutContext,
LayoutConstraints const &layoutConstraints) const override;
/*
* Internal representation of the nested content of the node in a format
* suitable for future processing.
*/
class Content final {
public:
AttributedString attributedString;
ParagraphAttributes paragraphAttributes;
Attachments attachments;
};
private:
/*
* Builds (if needed) and returns a reference to a `Content` object.
*/
Content const &getContent(LayoutContext const &layoutContext) const;
/*
* Builds and returns a `Content` object with given `layoutConstraints`.
*/
Content getContentWithMeasuredAttachments(
LayoutContext const &layoutContext,
LayoutConstraints const &layoutConstraints) const;
/*
* Creates a `State` object (with `AttributedText` and
* `TextLayoutManager`) if needed.
*/
void updateStateIfNeeded(Content const &content);
SharedTextLayoutManager textLayoutManager_;
/*
* Cached content of the subtree started from the node.
*/
mutable better::optional<Content> content_{};
};
} // namespace react
} // namespace facebook