mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
90ada5abb1
Summary: This diff changes API we use to measure text. Previously, a platform-specific measure infra returned just the size of the text, now it returns the size and an array of frames that describe where attachments are placed. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D20268041 fbshipit-source-id: 7c065607b6af18a36318db0aab24dad0f171d33a
89 lines
2.8 KiB
C++
89 lines
2.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.
|
|
*/
|
|
|
|
#include "TextLayoutManager.h"
|
|
|
|
#include <react/attributedstring/conversions.h>
|
|
#include <react/core/conversions.h>
|
|
#include <react/jni/ReadableNativeMap.h>
|
|
|
|
using namespace facebook::jni;
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
TextLayoutManager::~TextLayoutManager() {}
|
|
|
|
void *TextLayoutManager::getNativeTextLayoutManager() const {
|
|
return self_;
|
|
}
|
|
|
|
TextMeasurement TextLayoutManager::measure(
|
|
AttributedStringBox attributedStringBox,
|
|
ParagraphAttributes paragraphAttributes,
|
|
LayoutConstraints layoutConstraints) const {
|
|
auto &attributedString = attributedStringBox.getValue();
|
|
|
|
return measureCache_.get(
|
|
{attributedString, paragraphAttributes, layoutConstraints},
|
|
[&](TextMeasureCacheKey const &key) {
|
|
return doMeasure(
|
|
attributedString, paragraphAttributes, layoutConstraints);
|
|
});
|
|
}
|
|
|
|
TextMeasurement TextLayoutManager::doMeasure(
|
|
AttributedString attributedString,
|
|
ParagraphAttributes paragraphAttributes,
|
|
LayoutConstraints layoutConstraints) const {
|
|
const jni::global_ref<jobject> &fabricUIManager =
|
|
contextContainer_->at<jni::global_ref<jobject>>("FabricUIManager");
|
|
|
|
static auto measure =
|
|
jni::findClassStatic("com/facebook/react/fabric/FabricUIManager")
|
|
->getMethod<jlong(
|
|
jint,
|
|
jstring,
|
|
ReadableMap::javaobject,
|
|
ReadableMap::javaobject,
|
|
ReadableMap::javaobject,
|
|
jfloat,
|
|
jfloat,
|
|
jfloat,
|
|
jfloat)>("measure");
|
|
|
|
auto minimumSize = layoutConstraints.minimumSize;
|
|
auto maximumSize = layoutConstraints.maximumSize;
|
|
|
|
local_ref<JString> componentName = make_jstring("RCTText");
|
|
local_ref<ReadableNativeMap::javaobject> attributedStringRNM =
|
|
ReadableNativeMap::newObjectCxxArgs(toDynamic(attributedString));
|
|
local_ref<ReadableNativeMap::javaobject> paragraphAttributesRNM =
|
|
ReadableNativeMap::newObjectCxxArgs(toDynamic(paragraphAttributes));
|
|
|
|
local_ref<ReadableMap::javaobject> attributedStringRM = make_local(
|
|
reinterpret_cast<ReadableMap::javaobject>(attributedStringRNM.get()));
|
|
local_ref<ReadableMap::javaobject> paragraphAttributesRM = make_local(
|
|
reinterpret_cast<ReadableMap::javaobject>(paragraphAttributesRNM.get()));
|
|
auto size = yogaMeassureToSize(measure(
|
|
fabricUIManager,
|
|
-1,
|
|
componentName.get(),
|
|
attributedStringRM.get(),
|
|
paragraphAttributesRM.get(),
|
|
nullptr,
|
|
minimumSize.width,
|
|
maximumSize.width,
|
|
minimumSize.height,
|
|
maximumSize.height));
|
|
|
|
return TextMeasurement{size, {}};
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|