Replace NativeRunnable with fbjni implementation (#33776)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/33776

The implementations of these modules is pretty much identical, and we're already shipping the fbjni version of this anyway.

Changelog: [Internal]

Reviewed By: mhorowitz

Differential Revision: D36200330

fbshipit-source-id: 135ee621e1e4c5eb9616ce7f442fc6d4b946f865
This commit is contained in:
Pieter De Baets
2022-05-09 05:13:38 -07:00
committed by Facebook GitHub Bot
parent 883a93871c
commit 80f7367149
6 changed files with 9 additions and 96 deletions
@@ -1,25 +0,0 @@
/*
* 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.
*/
package com.facebook.react.bridge.queue;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
/** A Runnable that has a native run implementation. */
@DoNotStrip
public class NativeRunnable implements Runnable {
private final HybridData mHybridData;
@DoNotStrip
private NativeRunnable(HybridData hybridData) {
mHybridData = hybridData;
}
public native void run();
}
@@ -5,26 +5,22 @@
* LICENSE file in the root directory of this source tree.
*/
#include <fbjni/fbjni.h>
#include <react/jni/JNativeRunnable.h>
#include "JBackgroundExecutor.h"
#include <fbjni/NativeRunnable.h>
#include <fbjni/fbjni.h>
namespace facebook {
namespace react {
using namespace facebook::jni;
using facebook::react::JNativeRunnable;
using facebook::react::Runnable;
BackgroundExecutor JBackgroundExecutor::create(const std::string &name) {
auto instance = make_global(newInstance(name));
return [instance = std::move(instance)](std::function<void()> &&runnable) {
static auto method =
javaClassStatic()->getMethod<void(Runnable::javaobject)>(
javaClassStatic()->getMethod<void(JRunnable::javaobject)>(
"queueRunnable");
auto jrunnable = JNativeRunnable::newObjectCxxArgs(std::move(runnable));
method(instance, jrunnable.get());
};
-1
View File
@@ -8,7 +8,6 @@ EXPORTED_HEADERS = [
"JavaScriptExecutorHolder.h",
"JCallback.h",
"JMessageQueueThread.h",
"JNativeRunnable.h",
"JReactMarker.h",
"JSLoader.h",
"JSLogging.h",
@@ -35,7 +35,6 @@
#include <logger/react_native_log.h>
#include "CxxModuleWrapper.h"
#include "JNativeRunnable.h"
#include "JReactCxxErrorHandler.h"
#include "JReactSoftExceptionLogger.h"
#include "JavaScriptExecutorHolder.h"
@@ -155,8 +154,6 @@ void CatalystInstanceImpl::registerNatives() {
"warnOnLegacyNativeModuleSystemUse",
CatalystInstanceImpl::warnOnLegacyNativeModuleSystemUse),
});
JNativeRunnable::registerNatives();
}
void log(ReactNativeLogLevel level, const char *message) {
@@ -11,11 +11,10 @@
#include <mutex>
#include <fb/log.h>
#include <fbjni/NativeRunnable.h>
#include <fbjni/fbjni.h>
#include <jsi/jsi.h>
#include "JNativeRunnable.h"
namespace facebook {
namespace react {
@@ -69,11 +68,10 @@ void JMessageQueueThread::runOnQueue(std::function<void()> &&runnable) {
jni::ThreadScope guard;
static auto method =
JavaMessageQueueThread::javaClassStatic()
->getMethod<jboolean(Runnable::javaobject)>("runOnQueue");
method(
m_jobj,
JNativeRunnable::newObjectCxxArgs(wrapRunnable(std::move(runnable)))
.get());
->getMethod<jboolean(JRunnable::javaobject)>("runOnQueue");
auto jrunnable =
JNativeRunnable::newObjectCxxArgs(wrapRunnable(std::move(runnable)));
method(m_jobj, jrunnable.get());
}
void JMessageQueueThread::runOnQueueSync(std::function<void()> &&runnable) {
@@ -1,52 +0,0 @@
/*
* 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 <functional>
#include <jni.h>
using namespace facebook::jni;
namespace facebook {
namespace react {
struct Runnable : public JavaClass<Runnable> {
public:
static constexpr auto kJavaDescriptor = "Ljava/lang/Runnable;";
};
/**
* The c++ interface for the Java NativeRunnable class
*/
class JNativeRunnable : public HybridClass<JNativeRunnable, Runnable> {
public:
static auto constexpr kJavaDescriptor =
"Lcom/facebook/react/bridge/queue/NativeRunnable;";
void run() {
m_runnable();
}
static void registerNatives() {
javaClassStatic()->registerNatives({
makeNativeMethod("run", JNativeRunnable::run),
});
}
private:
friend HybridBase;
JNativeRunnable(std::function<void()> runnable)
: m_runnable(std::move(runnable)) {}
std::function<void()> m_runnable;
};
} // namespace react
} // namespace facebook