Skip to content

Commit

Permalink
Convert com.facebook.react.jstasks to Kotlin (facebook#48147)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#48147

This converts all the classes inside `com.facebook.react.jstasks` to Kotlin

Changelog:
[Internal] [Changed] -

Reviewed By: javache

Differential Revision: D66875442
  • Loading branch information
cortinico authored and facebook-github-bot committed Dec 6, 2024
1 parent 26eb564 commit e564fe0
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 382 deletions.
36 changes: 24 additions & 12 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -2902,23 +2902,35 @@ public final class com/facebook/react/jscexecutor/JSCExecutorFactory : com/faceb
public fun toString ()Ljava/lang/String;
}

public class com/facebook/react/jstasks/HeadlessJsTaskConfig {
public final class com/facebook/react/jstasks/HeadlessJsTaskConfig {
public fun <init> (Lcom/facebook/react/jstasks/HeadlessJsTaskConfig;)V
public fun <init> (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;)V
public fun <init> (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;J)V
public fun <init> (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;JZ)V
public fun <init> (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;JZLcom/facebook/react/jstasks/HeadlessJsTaskRetryPolicy;)V
}

public class com/facebook/react/jstasks/HeadlessJsTaskContext {
public fun addTaskEventListener (Lcom/facebook/react/jstasks/HeadlessJsTaskEventListener;)V
public fun finishTask (I)V
public static fun getInstance (Lcom/facebook/react/bridge/ReactContext;)Lcom/facebook/react/jstasks/HeadlessJsTaskContext;
public fun hasActiveTasks ()Z
public fun isTaskRunning (I)Z
public fun removeTaskEventListener (Lcom/facebook/react/jstasks/HeadlessJsTaskEventListener;)V
public fun retryTask (I)Z
public fun startTask (Lcom/facebook/react/jstasks/HeadlessJsTaskConfig;)I
public synthetic fun <init> (Ljava/lang/String;Lcom/facebook/react/bridge/WritableMap;JZLcom/facebook/react/jstasks/HeadlessJsTaskRetryPolicy;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getData ()Lcom/facebook/react/bridge/WritableMap;
public final fun getRetryPolicy ()Lcom/facebook/react/jstasks/HeadlessJsTaskRetryPolicy;
public final fun getTaskKey ()Ljava/lang/String;
public final fun getTimeout ()J
public final fun isAllowedInForeground ()Z
}

public final class com/facebook/react/jstasks/HeadlessJsTaskContext {
public static final field Companion Lcom/facebook/react/jstasks/HeadlessJsTaskContext$Companion;
public synthetic fun <init> (Lcom/facebook/react/bridge/ReactContext;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun addTaskEventListener (Lcom/facebook/react/jstasks/HeadlessJsTaskEventListener;)V
public final fun finishTask (I)V
public static final fun getInstance (Lcom/facebook/react/bridge/ReactContext;)Lcom/facebook/react/jstasks/HeadlessJsTaskContext;
public final fun hasActiveTasks ()Z
public final fun isTaskRunning (I)Z
public final fun removeTaskEventListener (Lcom/facebook/react/jstasks/HeadlessJsTaskEventListener;)V
public final fun retryTask (I)Z
public final fun startTask (Lcom/facebook/react/jstasks/HeadlessJsTaskConfig;)I
}

public final class com/facebook/react/jstasks/HeadlessJsTaskContext$Companion {
public final fun getInstance (Lcom/facebook/react/bridge/ReactContext;)Lcom/facebook/react/jstasks/HeadlessJsTaskContext;
}

public abstract interface class com/facebook/react/jstasks/HeadlessJsTaskEventListener {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.jstasks

import com.facebook.react.bridge.WritableMap

/**
* Class that holds the various parameters needed to start a JS task.
*
* @property taskKey the key for the JS task to execute. This is the same key that you call
* `AppRegistry.registerTask` with in JS.
* @property data a map of parameters passed to the JS task executor.
* @property timeout the amount of time (in ms) after which the React instance should be terminated
* regardless of whether the task has completed or not. This is meant as a safeguard against
* accidentally keeping the device awake for long periods of time because JS crashed or some
* request timed out. A value of 0 means no timeout (should only be used for long-running tasks
* such as music playback).
* @property allowedInForeground whether to allow this task to run while the app is in the
* foreground (i.e. there is a host in resumed mode for the current ReactContext). Only set this
* to true if you really need it. Note that tasks run in the same JS thread as UI code, so doing
* expensive operations would degrade user experience.
* @property allowedInForeground whether to allow this task to run while the app is in the
* foreground (i.e. there is a host in resumed mode for the current ReactContext). Only set this
* to true if you really need it. Note that tasks run in the same JS thread as UI code, so doing
* expensive operations would degrade user experience.
* @property retryPolicy the number of times & delays the task should be retried on error.
*/
public class HeadlessJsTaskConfig
@JvmOverloads
constructor(
public val taskKey: String,
public val data: WritableMap,
public val timeout: Long = 0,
public val isAllowedInForeground: Boolean = false,
public val retryPolicy: HeadlessJsTaskRetryPolicy? = NoRetryPolicy.INSTANCE
) {

/**
* Copy constructor to create a HeadlessJsTaskConfig from an existing one. Equivalent to calling
* [HeadlessJsTaskConfig] with `false` for `allowedInBackground`.
*/
public constructor(
source: HeadlessJsTaskConfig
) : this(
source.taskKey,
source.data.copy(),
source.timeout,
source.isAllowedInForeground,
source.retryPolicy?.copy())
}
Loading

0 comments on commit e564fe0

Please sign in to comment.