mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Integrate AndroidSwitch into Fabric on Android
Summary: In this diff we integrate the Switch component on Android in Fabric. Since the component has a custom measure function, we need to write some C++ to call the measure method in Java. The component isn't fully functional yet (setNativeProps isn't supported in Fabric) and has some problems with measuring itself. I will fix the component in the next diffs in this stack. Reviewed By: JoshuaGross Differential Revision: D17571258 fbshipit-source-id: be4e201495b9b197ddec44ee3484357bfb6225a8
This commit is contained in:
committed by
Facebook Github Bot
parent
6aae8e0756
commit
d0dd1aed29
+65
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 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(
|
||||
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(
|
||||
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,
|
||||
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
|
||||
Reference in New Issue
Block a user