Files
react-native/ReactCommon/fabric/components/slider/platform/android/SliderMeasurementsManager.cpp
Joshua Gross edceba9a9c Slider component - cache measurements, don't create measure manager on iOS
Summary: Small perf wins for both iOS and Android.

Reviewed By: PeteTheHeat

Differential Revision: D14237532

fbshipit-source-id: 2be114d36adfa6e8540cb8cbca5412782791d8ce
2019-02-27 12:48:26 -08:00

69 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.
*/
#include "SliderMeasurementsManager.h"
#include <fb/fbjni.h>
#include <react/core/conversions.h>
#include <react/jni/ReadableNativeMap.h>
using namespace facebook::jni;
namespace facebook {
namespace react {
Size SliderMeasurementsManager::measure(
LayoutConstraints layoutConstraints) const {
{
std::lock_guard<std::mutex> lock(mutex_);
if (hasBeenMeasured_) {
return cachedMeasurement_;
}
}
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("RCTSlider");
auto measurement = yogaMeassureToSize(measure(
fabricUIManager,
componentName.get(),
nullptr,
nullptr,
minWidth,
maxWidth,
minHeight,
maxHeight));
std::lock_guard<std::mutex> lock(mutex_);
cachedMeasurement_ = measurement;
return measurement;
}
} // namespace react
} // namespace facebook