mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
299c984964
Summary: We use `ViewManager.onMeasure` to perform measurements of Android views and pass the measured size back to Yoga. For Android in order to the report correct dimensions of a View, this View must be created using a Context that has a theme associated with it. Before, `onMeasure` only had ReactApplicationContext passed as the first parameter and ReactSwitch, for example, could not be measured correctly (because it uses the size of the thumb drawable, which is extracted from the current theme). This diff adds surfaceId as the first parameter of `FabricUIManager.measure`, so that we can retrieve ThemedReactContext and pass it to `ViewManager.onMeasure`. The size of the Switch component is still incorrect, but at least the size reported back to Yoga is the same as in Paper. So there is more investigation necessary why this happens in Fabric. I will investigate and publish another diff with the fix. Reviewed By: JoshuaGross, shergin Differential Revision: D17625959 fbshipit-source-id: 48197a61240fb13042bef3e9f5d681acacc702fb
69 lines
1.7 KiB
C++
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 "AndroidSwitchMeasurementsManager.h"
|
|
|
|
#include <fb/fbjni.h>
|
|
#include <react/core/conversions.h>
|
|
#include <react/jni/ReadableNativeMap.h>
|
|
|
|
using namespace facebook::jni;
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
Size AndroidSwitchMeasurementsManager::measure(
|
|
SurfaceId surfaceId,
|
|
LayoutConstraints layoutConstraints) const {
|
|
{
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
if (hasBeenMeasured_) {
|
|
return cachedMeasurement_;
|
|
}
|
|
}
|
|
|
|
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("AndroidSwitch");
|
|
|
|
auto measurement = yogaMeassureToSize(measure(
|
|
fabricUIManager,
|
|
surfaceId,
|
|
componentName.get(),
|
|
nullptr,
|
|
nullptr,
|
|
nullptr,
|
|
minimumSize.width,
|
|
maximumSize.width,
|
|
minimumSize.height,
|
|
maximumSize.height));
|
|
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
cachedMeasurement_ = measurement;
|
|
return measurement;
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|