From 934803a1678e5fb8aaec05ebb69644eda7ffa0f4 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Wed, 3 Apr 2024 01:06:05 -0700 Subject: [PATCH 1/4] Kotlinify NotificationOnlyHandler (#43745) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43745 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Differential Revision: https://internalfb.com/D55601731 --- .../NotificationOnlyHandler.java | 24 ------------------- .../NotificationOnlyHandler.kt | 20 ++++++++++++++++ 2 files changed, 20 insertions(+), 24 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/NotificationOnlyHandler.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/NotificationOnlyHandler.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/NotificationOnlyHandler.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/NotificationOnlyHandler.java deleted file mode 100644 index bbfe4400dd0f..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/NotificationOnlyHandler.java +++ /dev/null @@ -1,24 +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.packagerconnection; - -import androidx.annotation.Nullable; -import com.facebook.common.logging.FLog; -import com.facebook.infer.annotation.Nullsafe; - -@Nullsafe(Nullsafe.Mode.LOCAL) -public abstract class NotificationOnlyHandler implements RequestHandler { - private static final String TAG = JSPackagerClient.class.getSimpleName(); - - public final void onRequest(@Nullable Object params, Responder responder) { - responder.error("Request is not supported"); - FLog.e(TAG, "Request is not supported"); - } - - public abstract void onNotification(@Nullable Object params); -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/NotificationOnlyHandler.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/NotificationOnlyHandler.kt new file mode 100644 index 000000000000..e4c0822efd49 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/packagerconnection/NotificationOnlyHandler.kt @@ -0,0 +1,20 @@ +/* + * 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.packagerconnection + +import com.facebook.common.logging.FLog + +public abstract class NotificationOnlyHandler : RequestHandler { + + override final fun onRequest(params: Any?, responder: Responder) { + responder.error("Request is not supported") + FLog.e(JSPackagerClient::class.java.simpleName, "Request is not supported") + } + + override abstract fun onNotification(params: Any?) +} From 90012e3e0919f9d6f2d5c3dd237c896bfcb6dbdb Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Wed, 3 Apr 2024 01:06:05 -0700 Subject: [PATCH 2/4] Kotlinify NativeKind Differential Revision: D55640039 --- .../react/uimanager/{NativeKind.java => NativeKind.kt} | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) rename packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/{NativeKind.java => NativeKind.kt} (86%) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeKind.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeKind.kt similarity index 86% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeKind.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeKind.kt index 35d40c382414..7cc3313bc075 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeKind.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/NativeKind.kt @@ -5,16 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.uimanager; - -import com.facebook.infer.annotation.Nullsafe; +package com.facebook.react.uimanager // Common conditionals: // - `kind == PARENT` checks whether the node can host children in the native tree. // - `kind != NONE` checks whether the node appears in the native tree. -@Nullsafe(Nullsafe.Mode.LOCAL) -public enum NativeKind { +public enum class NativeKind { // Node is in the native hierarchy and the HierarchyOptimizer should assume it can host children // (e.g. because it's a ViewGroup). Note that it's okay if the node doesn't support children. When // the HierarchyOptimizer generates children manipulation commands for that node, the @@ -24,5 +21,5 @@ public enum NativeKind { // because it isn't a ViewGroup). Consequently, its children need to be hosted by an ancestor. LEAF, // Node is not in the native hierarchy. - NONE + NONE, } From f1d028ed5a56d5ae7100dd0e9ab6ce843016cfdf Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Wed, 3 Apr 2024 01:06:05 -0700 Subject: [PATCH 3/4] Kotlinify LifecycleState Differential Revision: D55642371 --- .../common/{LifecycleState.java => LifecycleState.kt} | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) rename packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/{LifecycleState.java => LifecycleState.kt} (87%) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/LifecycleState.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/LifecycleState.kt similarity index 87% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/LifecycleState.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/LifecycleState.kt index e106d2dbc1d5..d1f62216050a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/LifecycleState.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/LifecycleState.kt @@ -5,9 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.common; - -import com.facebook.infer.annotation.Nullsafe; +package com.facebook.react.common /** * Lifecycle state for an Activity. The state right after pause and right before resume are the @@ -23,8 +21,7 @@ *

RESUMED is used when a ReactRootView is rendered on the screen and the user can interact with * it. */ -@Nullsafe(Nullsafe.Mode.LOCAL) -public enum LifecycleState { +public enum class LifecycleState { BEFORE_CREATE, BEFORE_RESUME, RESUMED, From 8e62953210742222066b1387ac2cec1feb514cf6 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Wed, 3 Apr 2024 01:06:22 -0700 Subject: [PATCH 4/4] Kotlinify DispatchCommandMountItem (#43781) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43781 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Reviewed By: cortinico Differential Revision: D55642568 --- .../ReactAndroid/api/ReactAndroid.api | 4 ++-- ...tItem.java => DispatchCommandMountItem.kt} | 19 +++++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) rename packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/{DispatchCommandMountItem.java => DispatchCommandMountItem.kt} (55%) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 03b14a6a8f2b..1c1ddf86c852 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2777,8 +2777,8 @@ public abstract interface class com/facebook/react/fabric/mounting/mountitems/Ba public abstract class com/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem : com/facebook/react/fabric/mounting/mountitems/MountItem { public fun ()V - public fun getRetries ()I - public fun incrementRetries ()V + public final fun getRetries ()I + public final fun incrementRetries ()V } public abstract interface class com/facebook/react/fabric/mounting/mountitems/MountItem { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem.kt similarity index 55% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem.kt index feedcc4bc2f4..e44050f72fee 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/DispatchCommandMountItem.kt @@ -5,27 +5,22 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.fabric.mounting.mountitems; +package com.facebook.react.fabric.mounting.mountitems -import androidx.annotation.UiThread; -import com.facebook.infer.annotation.Nullsafe; +import androidx.annotation.UiThread /** * This is a common interface for View Command operations. Once we delete the deprecated {@link * DispatchIntCommandMountItem}, we can delete this interface too. It provides a set of common * operations to simplify generic operations on all types of ViewCommands. */ -@Nullsafe(Nullsafe.Mode.LOCAL) -public abstract class DispatchCommandMountItem implements MountItem { - private int mNumRetries = 0; +public abstract class DispatchCommandMountItem : MountItem { + private var numRetries: Int = 0 @UiThread - public void incrementRetries() { - mNumRetries++; + public fun incrementRetries() { + numRetries++ } - @UiThread - public int getRetries() { - return mNumRetries; - } + @UiThread public fun getRetries(): Int = numRetries }