diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index efeb734fc4ef9d..3293ed38c20290 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -3170,12 +3170,17 @@ public final class com/facebook/react/modules/core/ExceptionsManagerModule : com public final class com/facebook/react/modules/core/ExceptionsManagerModule$Companion { } -public class com/facebook/react/modules/core/HeadlessJsTaskSupportModule : com/facebook/fbreact/specs/NativeHeadlessJsTaskSupportSpec { +public final class com/facebook/react/modules/core/HeadlessJsTaskSupportModule : com/facebook/fbreact/specs/NativeHeadlessJsTaskSupportSpec { + public static final field Companion Lcom/facebook/react/modules/core/HeadlessJsTaskSupportModule$Companion; + public static final field NAME Ljava/lang/String; public fun (Lcom/facebook/react/bridge/ReactApplicationContext;)V public fun notifyTaskFinished (D)V public fun notifyTaskRetry (DLcom/facebook/react/bridge/Promise;)V } +public final class com/facebook/react/modules/core/HeadlessJsTaskSupportModule$Companion { +} + public abstract interface class com/facebook/react/modules/core/JSTimers : com/facebook/react/bridge/JavaScriptModule { public abstract fun callIdleCallbacks (D)V public abstract fun callTimers (Lcom/facebook/react/bridge/WritableArray;)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/HeadlessJsTaskSupportModule.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/HeadlessJsTaskSupportModule.java deleted file mode 100644 index 2f64909db921b2..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/HeadlessJsTaskSupportModule.java +++ /dev/null @@ -1,61 +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.modules.core; - -import com.facebook.common.logging.FLog; -import com.facebook.fbreact.specs.NativeHeadlessJsTaskSupportSpec; -import com.facebook.react.bridge.Promise; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.jstasks.HeadlessJsTaskContext; -import com.facebook.react.module.annotations.ReactModule; - -/** - * Simple native module that allows JS to notify native of having completed some task work, so that - * it can e.g. release any resources, stop timers etc. - */ -@ReactModule(name = NativeHeadlessJsTaskSupportSpec.NAME) -public class HeadlessJsTaskSupportModule extends NativeHeadlessJsTaskSupportSpec { - - public HeadlessJsTaskSupportModule(ReactApplicationContext reactContext) { - super(reactContext); - } - - @Override - public void notifyTaskRetry(double taskIdDouble, Promise promise) { - int taskId = (int) taskIdDouble; - - HeadlessJsTaskContext headlessJsTaskContext = - HeadlessJsTaskContext.getInstance(getReactApplicationContext()); - if (headlessJsTaskContext.isTaskRunning(taskId)) { - final boolean retryPosted = headlessJsTaskContext.retryTask(taskId); - promise.resolve(retryPosted); - } else { - FLog.w( - HeadlessJsTaskSupportModule.class, - "Tried to retry non-active task with id %d. Did it time out?", - taskId); - promise.resolve(false); - } - } - - @Override - public void notifyTaskFinished(double taskIdDouble) { - int taskId = (int) taskIdDouble; - - HeadlessJsTaskContext headlessJsTaskContext = - HeadlessJsTaskContext.getInstance(getReactApplicationContext()); - if (headlessJsTaskContext.isTaskRunning(taskId)) { - headlessJsTaskContext.finishTask(taskId); - } else { - FLog.w( - HeadlessJsTaskSupportModule.class, - "Tried to finish non-active task with id %d. Did it time out?", - taskId); - } - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/HeadlessJsTaskSupportModule.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/HeadlessJsTaskSupportModule.kt new file mode 100644 index 00000000000000..2be2509ea5af0c --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/core/HeadlessJsTaskSupportModule.kt @@ -0,0 +1,54 @@ +/* + * 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.modules.core + +import com.facebook.common.logging.FLog +import com.facebook.react.bridge.Promise +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.jstasks.HeadlessJsTaskContext +import com.facebook.react.module.annotations.ReactModule + +/** + * Simple native module that allows JS to notify native of having completed some task work, so that + * it can e.g. release any resources, stop timers etc. + */ +@ReactModule(name = com.facebook.fbreact.specs.NativeHeadlessJsTaskSupportSpec.NAME) +public class HeadlessJsTaskSupportModule(reactContext: ReactApplicationContext?) : + com.facebook.fbreact.specs.NativeHeadlessJsTaskSupportSpec(reactContext) { + override fun notifyTaskRetry(taskIdDouble: Double, promise: Promise) { + val taskId = taskIdDouble.toInt() + val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext()) + if (headlessJsTaskContext.isTaskRunning(taskId)) { + val retryPosted = headlessJsTaskContext.retryTask(taskId) + promise.resolve(retryPosted) + } else { + FLog.w( + HeadlessJsTaskSupportModule::class.java, + "Tried to retry non-active task with id %d. Did it time out?", + taskId) + promise.resolve(false) + } + } + + override fun notifyTaskFinished(taskIdDouble: Double) { + val taskId = taskIdDouble.toInt() + val headlessJsTaskContext = HeadlessJsTaskContext.getInstance(getReactApplicationContext()) + if (headlessJsTaskContext.isTaskRunning(taskId)) { + headlessJsTaskContext.finishTask(taskId) + } else { + FLog.w( + HeadlessJsTaskSupportModule::class.java, + "Tried to finish non-active task with id %d. Did it time out?", + taskId) + } + } + + public companion object { + public const val NAME: String = com.facebook.fbreact.specs.NativeHeadlessJsTaskSupportSpec.NAME + } +}