Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) Meta Platforms, Inc. and 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 <react/renderer/core/ConcreteComponentDescriptor.h>
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
#include <react/utils/ContextContainer.h>

namespace facebook::react {

constexpr const char *const TextLayoutManagerKey = "TextLayoutManager";

template <typename ShadowNodeT>
class BaseParagraphComponentDescriptor : public ConcreteComponentDescriptor<ShadowNodeT> {
public:
explicit BaseParagraphComponentDescriptor(const ComponentDescriptorParameters &parameters)
: ConcreteComponentDescriptor<ShadowNodeT>(parameters),
textLayoutManager_(getManagerByName<TextLayoutManager>(this->contextContainer_, TextLayoutManagerKey))
{
}

ComponentName getComponentName() const override
{
return ShadowNodeT::Name();
}

protected:
void adopt(ShadowNode &shadowNode) const override
{
ConcreteComponentDescriptor<ShadowNodeT>::adopt(shadowNode);

auto &paragraphShadowNode = static_cast<ShadowNodeT &>(shadowNode);

// `ParagraphShadowNode` uses `TextLayoutManager` to measure text content
// and communicate text rendering metrics to mounting layer.
paragraphShadowNode.setTextLayoutManager(textLayoutManager_);
}

private:
// Every `ParagraphShadowNode` has a reference to a shared `TextLayoutManager`
const std::shared_ptr<const TextLayoutManager> textLayoutManager_;
};

} // namespace facebook::react

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,16 @@

#pragma once

#include <react/renderer/components/text/BaseParagraphComponentDescriptor.h>
#include <react/renderer/components/text/ParagraphShadowNode.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h>
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
#include <react/utils/ContextContainer.h>

namespace facebook::react {

extern const char TextLayoutManagerKey[];

/*
* Descriptor for <Paragraph> component.
*/
class ParagraphComponentDescriptor final : public ConcreteComponentDescriptor<ParagraphShadowNode> {
class ParagraphComponentDescriptor final : public BaseParagraphComponentDescriptor<ParagraphShadowNode> {
public:
explicit ParagraphComponentDescriptor(const ComponentDescriptorParameters &parameters)
: ConcreteComponentDescriptor<ParagraphShadowNode>(parameters),
textLayoutManager_(getManagerByName<TextLayoutManager>(contextContainer_, TextLayoutManagerKey))
{
}

protected:
void adopt(ShadowNode &shadowNode) const override
{
ConcreteComponentDescriptor::adopt(shadowNode);

auto &paragraphShadowNode = static_cast<ParagraphShadowNode &>(shadowNode);

// `ParagraphShadowNode` uses `TextLayoutManager` to measure text content
// and communicate text rendering metrics to mounting layer.
paragraphShadowNode.setTextLayoutManager(textLayoutManager_);
}

private:
// Every `ParagraphShadowNode` has a reference to a shared `TextLayoutManager`
const std::shared_ptr<const TextLayoutManager> textLayoutManager_;
using BaseParagraphComponentDescriptor::BaseParagraphComponentDescriptor;
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern const char ParagraphComponentName[];
* containing and displaying text. Text content is represented as nested <Text>
* and <RawText> components.
*/
class ParagraphShadowNode final
class ParagraphShadowNode
: public ConcreteViewShadowNode<ParagraphComponentName, ParagraphProps, ParagraphEventEmitter, ParagraphState>,
public BaseTextShadowNode {
public:
Expand Down
Loading