From 1730949e94aa23927a90d2a64d91977b7e2904d6 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Tue, 26 Apr 2022 05:11:05 -0700 Subject: [PATCH] Expose scheduler through FabricUIManager Summary: Allows to access `react::renderer::Scheduler` given `FabricUIManager` from Java side. Changelog: [Added] Added `FabricUIManager` binding with FBJNI Reviewed By: javache Differential Revision: D35313399 fbshipit-source-id: 54e7adcceae40368c2735ddfc8a083f87b08dc5e --- .../com/facebook/react/fabric/jni/Binding.h | 3 ++- .../react/fabric/jni/JFabricUIManager.cpp | 18 +++++++++++++ .../react/fabric/jni/JFabricUIManager.h | 25 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 ReactAndroid/src/main/java/com/facebook/react/fabric/jni/JFabricUIManager.cpp create mode 100644 ReactAndroid/src/main/java/com/facebook/react/fabric/jni/JFabricUIManager.h diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h index b7df029f3d2..9b0a1fd49cc 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/Binding.h @@ -43,6 +43,8 @@ class Binding : public jni::HybridClass, static void registerNatives(); + std::shared_ptr getScheduler(); + private: void setConstraints( jint surfaceId, @@ -133,7 +135,6 @@ class Binding : public jni::HybridClass, std::shared_ptr mountingManager_; std::shared_ptr scheduler_; - std::shared_ptr getScheduler(); std::shared_ptr verifyMountingManager( std::string const &locationHint); diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/JFabricUIManager.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/JFabricUIManager.cpp new file mode 100644 index 00000000000..595cccd6c7a --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/JFabricUIManager.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include "JFabricUIManager.h" + +namespace facebook::react { + +Binding *JFabricUIManager::getBinding() { + static const auto bindingField = + javaClassStatic()->getField("mBinding"); + + return getFieldValue(bindingField)->cthis(); +} +} // namespace facebook::react diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/JFabricUIManager.h b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/JFabricUIManager.h new file mode 100644 index 00000000000..dffb09905cc --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/JFabricUIManager.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include +#include "Binding.h" + +using namespace facebook::jni; + +namespace facebook::react { + +class JFabricUIManager : public JavaClass { + public: + static constexpr auto kJavaDescriptor = + "Lcom/facebook/react/fabric/FabricUIManager;"; + + Binding *getBinding(); +}; + +} // namespace facebook::react