From 80f73671495c4330ddf7e1db85a42c629a557ee2 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 9 May 2022 05:13:38 -0700 Subject: [PATCH] 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 --- .../react/bridge/queue/NativeRunnable.java | 25 --------- .../react/fabric/jni/JBackgroundExecutor.cpp | 12 ++--- ReactAndroid/src/main/jni/react/jni/BUCK | 1 - .../jni/react/jni/CatalystInstanceImpl.cpp | 3 -- .../jni/react/jni/JMessageQueueThread.cpp | 12 ++--- .../src/main/jni/react/jni/JNativeRunnable.h | 52 ------------------- 6 files changed, 9 insertions(+), 96 deletions(-) delete mode 100644 ReactAndroid/src/main/java/com/facebook/react/bridge/queue/NativeRunnable.java delete mode 100644 ReactAndroid/src/main/jni/react/jni/JNativeRunnable.h diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/NativeRunnable.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/NativeRunnable.java deleted file mode 100644 index 3573938d3d9..00000000000 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/queue/NativeRunnable.java +++ /dev/null @@ -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(); -} diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/JBackgroundExecutor.cpp b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/JBackgroundExecutor.cpp index 88117cbb845..e6d4f641f5e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/JBackgroundExecutor.cpp +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/jni/JBackgroundExecutor.cpp @@ -5,26 +5,22 @@ * LICENSE file in the root directory of this source tree. */ -#include -#include - #include "JBackgroundExecutor.h" +#include +#include + 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 &&runnable) { static auto method = - javaClassStatic()->getMethod( + javaClassStatic()->getMethod( "queueRunnable"); - auto jrunnable = JNativeRunnable::newObjectCxxArgs(std::move(runnable)); method(instance, jrunnable.get()); }; diff --git a/ReactAndroid/src/main/jni/react/jni/BUCK b/ReactAndroid/src/main/jni/react/jni/BUCK index ab384eefa38..787eb0f14bd 100644 --- a/ReactAndroid/src/main/jni/react/jni/BUCK +++ b/ReactAndroid/src/main/jni/react/jni/BUCK @@ -8,7 +8,6 @@ EXPORTED_HEADERS = [ "JavaScriptExecutorHolder.h", "JCallback.h", "JMessageQueueThread.h", - "JNativeRunnable.h", "JReactMarker.h", "JSLoader.h", "JSLogging.h", diff --git a/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp b/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp index 61911ce6e35..6a936c66f66 100644 --- a/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp +++ b/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp @@ -35,7 +35,6 @@ #include #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) { diff --git a/ReactAndroid/src/main/jni/react/jni/JMessageQueueThread.cpp b/ReactAndroid/src/main/jni/react/jni/JMessageQueueThread.cpp index 5f4caf8051c..dcb4fcdb9ae 100644 --- a/ReactAndroid/src/main/jni/react/jni/JMessageQueueThread.cpp +++ b/ReactAndroid/src/main/jni/react/jni/JMessageQueueThread.cpp @@ -11,11 +11,10 @@ #include #include +#include #include #include -#include "JNativeRunnable.h" - namespace facebook { namespace react { @@ -69,11 +68,10 @@ void JMessageQueueThread::runOnQueue(std::function &&runnable) { jni::ThreadScope guard; static auto method = JavaMessageQueueThread::javaClassStatic() - ->getMethod("runOnQueue"); - method( - m_jobj, - JNativeRunnable::newObjectCxxArgs(wrapRunnable(std::move(runnable))) - .get()); + ->getMethod("runOnQueue"); + auto jrunnable = + JNativeRunnable::newObjectCxxArgs(wrapRunnable(std::move(runnable))); + method(m_jobj, jrunnable.get()); } void JMessageQueueThread::runOnQueueSync(std::function &&runnable) { diff --git a/ReactAndroid/src/main/jni/react/jni/JNativeRunnable.h b/ReactAndroid/src/main/jni/react/jni/JNativeRunnable.h deleted file mode 100644 index cd1a022e4c5..00000000000 --- a/ReactAndroid/src/main/jni/react/jni/JNativeRunnable.h +++ /dev/null @@ -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 - -#include - -using namespace facebook::jni; - -namespace facebook { -namespace react { - -struct Runnable : public JavaClass { - public: - static constexpr auto kJavaDescriptor = "Ljava/lang/Runnable;"; -}; - -/** - * The c++ interface for the Java NativeRunnable class - */ -class JNativeRunnable : public HybridClass { - 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 runnable) - : m_runnable(std::move(runnable)) {} - - std::function m_runnable; -}; - -} // namespace react -} // namespace facebook