forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HeadlessJsTaskSupportModule.java->.kt (facebook#45816)
Summary: Pull Request resolved: facebook#45816 # Changelog: [Internal] - As in the title. Differential Revision: D60446972
- Loading branch information
1 parent
c394ef6
commit 2e36d63
Showing
3 changed files
with
60 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 0 additions & 61 deletions
61
...actAndroid/src/main/java/com/facebook/react/modules/core/HeadlessJsTaskSupportModule.java
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
...ReactAndroid/src/main/java/com/facebook/react/modules/core/HeadlessJsTaskSupportModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |