Files
react-native/ReactCommon/fabric/components/text/basetext/BaseTextShadowNode.h
T
David VaccaandFacebook GitHub Bot 4b596fd5b3 Extend Text to support measurement of empty Texts
Summary:
This diff extends the measurement of Text components in order to support empty strings.
This is required for parity with Paper.
I created a follow up task to analyze support of empty string as part of the Text infrastructure of Fabric in the future.

changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D21761171

fbshipit-source-id: d2aa074052b09732af5d35723f19014090fcabbf
2020-05-28 15:10:47 -07:00

71 lines
2.0 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);
/**
* Returns a character used to measure empty strings in native platforms.
*/
inline static std::string getEmptyPlaceholder() {
return "I";
}
};
} // namespace react
} // namespace facebook