mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
f18358dda6
Summary: `BaseTextShadowNode::getAttributedString()` was replaced with simular method `BaseTextShadowNode::buildAttributedString()` which does same work with following differences: * Besides returning `AttributedString`, it retures an array of `Attachment`s elements of which points to `ShadowNode`s that form attachments; * Now we use single `AttributedString` to construct result instead of concatenation objects recurvily walking the tree. We will use the array of attachments later. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D20268048 fbshipit-source-id: 371c548826bdfd5c4f4b18915d68977724885ce6
64 lines
1.8 KiB
C++
64 lines
1.8 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 <react/attributedstring/AttributedString.h>
|
|
#include <react/attributedstring/TextAttributes.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
/*
|
|
* Base class (one of) for shadow nodes that represents attributed text,
|
|
* such as Text and Paragraph (but not RawText).
|
|
*/
|
|
class BaseTextShadowNode {
|
|
public:
|
|
/*
|
|
* Represents additional information associated with some fragments which
|
|
* represent embedded into text component (such as an image or inline view).
|
|
*/
|
|
class Attachment final {
|
|
public:
|
|
/*
|
|
* Unowning pointer to a `ShadowNode` that represents the attachment.
|
|
* Cannot be `null`.
|
|
*/
|
|
ShadowNode const *shadowNode;
|
|
|
|
/*
|
|
* Index of the fragment in `AttributedString` that represents the
|
|
* the attachment.
|
|
*/
|
|
size_t fragmentIndex;
|
|
};
|
|
|
|
/*
|
|
* A list of `Attachment`s.
|
|
* Performance-wise, the prevailing case is when there are no attachments
|
|
* at all, therefore we don't need an inline buffer (`small_vector`).
|
|
*/
|
|
using Attachments = std::vector<Attachment>;
|
|
|
|
/*
|
|
* Builds an `AttributedString` which represents text content of the node.
|
|
* This is static so that both Paragraph (which subclasses BaseText) and
|
|
* TextInput (which does not) can use this.
|
|
* TODO T53299884: decide if this should be moved out and made a static
|
|
* function, or if TextInput should inherit from BaseTextShadowNode.
|
|
*/
|
|
static void buildAttributedString(
|
|
TextAttributes const &baseTextAttributes,
|
|
ShadowNode const &parentNode,
|
|
AttributedString &outAttributedString,
|
|
Attachments &outAttachments);
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|