Skip to content

Commit

Permalink
HeadlessJsTaskSupportModule.java->.kt (facebook#45816)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#45816

# Changelog:
[Internal] -

As in the title.

Differential Revision: D60446972
  • Loading branch information
rshest authored and facebook-github-bot committed Jul 30, 2024
1 parent c394ef6 commit 2e36d63
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 62 deletions.
7 changes: 6 additions & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 2e36d63

Please sign in to comment.