mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
205de0538c
Summary: ... and slighly new behaviour for one of them. The method does nothing if given `key` already exists in the container. This diff finishes the transition of ContextContainer from an internal bag of things with unclear yet ownership into a legit dedicated dependency injection container for the product code. The original names of methods imply that the container can have only one object of a given type which is no longer true. The new API is much more generic and idiomatic to C++, it mimics `std:map` API which is intuitive to anyone who familiar with C++ containers. Besides the naming, `insert` method changed the semantic a bit; now it does nothing in case of inserting an object with a key that already exists. That might seem counterintuitive for "normal" people, but C++ has some wired reasons for that and, hopefully, it's expected behavior in the C++ community. Fun fact: We need this to fix hot-reload. Reviewed By: sahrens Differential Revision: D15681736 fbshipit-source-id: 194f342528446a911eaf072ba3a94a5d8af3cb52
71 lines
2.2 KiB
C++
71 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_->at<jni::global_ref<jobject>>("FabricUIManager");
|
|
|
|
static auto measure =
|
|
jni::findClassStatic("com/facebook/react/fabric/FabricUIManager")
|
|
->getMethod<jlong(
|
|
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()));
|
|
return yogaMeassureToSize(measure(
|
|
fabricUIManager,
|
|
componentName.get(),
|
|
attributedStringRM.get(),
|
|
paragraphAttributesRM.get(),
|
|
nullptr,
|
|
minimumSize.width,
|
|
maximumSize.width,
|
|
minimumSize.height,
|
|
maximumSize.height));
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|