Files
react-native/ReactCommon/fabric/textlayoutmanager/platform/android/TextLayoutManager.cpp
T
David Vacca 959fdf6049 ReadableNativeMap -> ReadableMap
Summary:
This diff refactors JNI methods used by the Binding.cpp class in order to use ReadableMap instead of ReadableNativeMap
This will be helpful to provide a different implementation of ReadableMap from C++

Reviewed By: shergin

Differential Revision: D14077762

fbshipit-source-id: 595b0c2d3a2d6070112257b65c1141a8af36f0e1
2019-02-14 00:07:40 -08:00

74 lines
2.3 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,
jint,
jint,
jint,
jint)>("measure");
auto minimumSize = layoutConstraints.minimumSize;
auto maximumSize = layoutConstraints.maximumSize;
int minWidth = (int)minimumSize.width;
int minHeight = (int)minimumSize.height;
int maxWidth = (int)maximumSize.width;
int maxHeight = (int)maximumSize.height;
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(),
minWidth,
maxWidth,
minHeight,
maxHeight));
}
} // namespace react
} // namespace facebook