mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
d41e95fb1a
Summary: changelog: [internal] This diff introduces a mechanism to cache NSTextStorage on Paragraph's state. The old renderer already has caching for NSTextStorage: https://github.com/facebook/react-native/blob/main/Libraries/Text/Text/RCTTextShadowView.m#L21 Fabric will store `NSTextStorage` inside `ParagraphLayoutManager` which is owned by state. There is one notable change which is not gated: Paragraph's state strongly owns `TextLayoutManager`, not `ParagraphShadowNode` like previously. This shouldn't change anything Reviewed By: mdvacca Differential Revision: D43692171 fbshipit-source-id: efe6077222a30ab6d89abd9916534b9a96e745d4
60 lines
1.9 KiB
C++
60 lines
1.9 KiB
C++
/*
|
|
* 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/attributedstring/AttributedString.h>
|
|
#include <react/renderer/attributedstring/ParagraphAttributes.h>
|
|
#include <react/renderer/core/LayoutConstraints.h>
|
|
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
|
|
|
|
namespace facebook::react {
|
|
|
|
/*
|
|
* Serves as a middle man between `ParagraphShadowNode` and `TextLayoutManager`.
|
|
* On iOS, caches `NSTextStorage` for individual `ParagraphShadowNode` to make
|
|
* sure only one `NSTextStorage` is created for every string. `NSTextStorage`
|
|
* can be re created on native views layer but it is expensive. On Android, this
|
|
* class does not cache anything.
|
|
*/
|
|
class ParagraphLayoutManager {
|
|
public:
|
|
TextMeasurement measure(
|
|
AttributedString const &attributedString,
|
|
ParagraphAttributes const ¶graphAttributes,
|
|
LayoutConstraints layoutConstraints) const;
|
|
|
|
LinesMeasurements measureLines(
|
|
AttributedString const &attributedString,
|
|
ParagraphAttributes const ¶graphAttributes,
|
|
Size size) const;
|
|
|
|
void setTextLayoutManager(
|
|
std::shared_ptr<TextLayoutManager const> textLayoutManager) const;
|
|
|
|
/*
|
|
* Returns an opaque pointer to platform-specific `TextLayoutManager`.
|
|
* Is used on a native views layer to delegate text rendering to the manager.
|
|
*/
|
|
std::shared_ptr<TextLayoutManager const> getTextLayoutManager() const;
|
|
|
|
/*
|
|
* Returns opaque shared_ptr holding `NSTextStorage`.
|
|
* May be nullptr.
|
|
* Is used on a native views layer to prevent `NSTextStorage` from being
|
|
* created twice.
|
|
*/
|
|
std::shared_ptr<void> getHostTextStorage() const;
|
|
|
|
private:
|
|
std::shared_ptr<TextLayoutManager const> mutable textLayoutManager_{};
|
|
std::shared_ptr<void> mutable hostTextStorage_{};
|
|
|
|
size_t mutable hash_{};
|
|
};
|
|
} // namespace facebook::react
|