mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
4a1d532674
Summary: Convert FabricUIManager.measure params to floats. Currently we convert parameters to ints across the JNI boundary, and then back to floats several times in Java. This is unnecessary and actually makes measurements trickier. The new implementation uses floats across the JNI boundary and uses Float.POSITIVE_INFINITY to represent unconstrained values, which is consistent with Fabric C++ as well. Reviewed By: shergin, mdvacca Differential Revision: D15176108 fbshipit-source-id: cf849b3773007637f059279460163872f300a4aa
70 lines
2.2 KiB
C++
70 lines
2.2 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_;
|
|
}
|
|
|
|
Size TextLayoutManager::measure(
|
|
AttributedString attributedString,
|
|
ParagraphAttributes paragraphAttributes,
|
|
LayoutConstraints layoutConstraints) const {
|
|
const jni::global_ref<jobject> &fabricUIManager =
|
|
contextContainer_->getInstance<jni::global_ref<jobject>>(
|
|
"FabricUIManager");
|
|
|
|
static auto measure =
|
|
jni::findClassStatic("com/facebook/react/fabric/FabricUIManager")
|
|
->getMethod<jlong(
|
|
jstring,
|
|
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()));
|
|
return yogaMeassureToSize(measure(
|
|
fabricUIManager,
|
|
componentName.get(),
|
|
attributedStringRM.get(),
|
|
paragraphAttributesRM.get(),
|
|
minimumSize.width,
|
|
maximumSize.width,
|
|
minimumSize.height,
|
|
maximumSize.height));
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|