Files
react-native/ReactCommon/fabric/textlayoutmanager/platform/android/TextLayoutManager.h
T
Valentin Shergin f32aa2a516 Fabric: Moving MeasureCache into TextLayoutManager
Summary:
We will have several consumers for the measure infra soon (TextInput will use the same TextLayoutManager). It makes sense to move the cache there.
In the future, iOS and Android implementations will probably use a bit different (platform-specific) cache implementations because we will implement the ability to measure "opaque"/platform-specific text containers alongside with normal AttributeStrings.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D18445855

fbshipit-source-id: 7b7a65152ac13c74525da695612ae034904e82bf
2019-11-18 14:28:44 -08:00

65 lines
1.7 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 <memory>
#include <react/attributedstring/AttributedString.h>
#include <react/attributedstring/ParagraphAttributes.h>
#include <react/core/LayoutConstraints.h>
#include <react/utils/ContextContainer.h>
#include <react/utils/SimpleThreadSafeCache.h>
namespace facebook {
namespace react {
class TextLayoutManager;
using SharedTextLayoutManager = std::shared_ptr<const TextLayoutManager>;
/*
* Cross platform facade for Android-specific TextLayoutManager.
*/
class TextLayoutManager {
public:
TextLayoutManager(const ContextContainer::Shared &contextContainer)
: contextContainer_(contextContainer){};
~TextLayoutManager();
/*
* Measures `attributedString` using native text rendering infrastructure.
*/
Size measure(
AttributedString attributedString,
ParagraphAttributes paragraphAttributes,
LayoutConstraints layoutConstraints) const;
/*
* Returns an opaque pointer to platform-specific TextLayoutManager.
* Is used on a native views layer to delegate text rendering to the manager.
*/
void *getNativeTextLayoutManager() const;
private:
Size doMeasure(
AttributedString attributedString,
ParagraphAttributes paragraphAttributes,
LayoutConstraints layoutConstraints) const;
using MeasureCacheKey =
std::tuple<AttributedString, ParagraphAttributes, LayoutConstraints>;
using MeasureCache = SimpleThreadSafeCache<MeasureCacheKey, Size, 256>;
void *self_;
ContextContainer::Shared contextContainer_;
MeasureCache measureCache_{};
};
} // namespace react
} // namespace facebook