From 08af9eaa29e51f83909d41309acf197b7dae594f Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Wed, 3 Apr 2024 02:43:36 -0700 Subject: [PATCH] Kotlinify ComponentFactory (#43783) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43783 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Reviewed By: alanleedev Differential Revision: D55643354 fbshipit-source-id: de6b676ae138f823c0521f1dcc48f3bcb7fd4e04 --- .../ReactAndroid/api/ReactAndroid.api | 2 +- .../react/fabric/ComponentFactory.java | 32 ------------------- .../facebook/react/fabric/ComponentFactory.kt | 25 +++++++++++++++ 3 files changed, 26 insertions(+), 33 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentFactory.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentFactory.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 1c1ddf86c85..4e8b9a8fe19 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2488,7 +2488,7 @@ public class com/facebook/react/fabric/BindingImpl : com/facebook/react/fabric/B public fun unregisterSurface (Lcom/facebook/react/fabric/SurfaceHandlerBinding;)V } -public class com/facebook/react/fabric/ComponentFactory { +public final class com/facebook/react/fabric/ComponentFactory { public fun ()V } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentFactory.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentFactory.java deleted file mode 100644 index f0be02df1e7..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentFactory.java +++ /dev/null @@ -1,32 +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.fabric; - -import androidx.annotation.NonNull; -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.jni.HybridData; -import com.facebook.proguard.annotations.DoNotStrip; - -@Nullsafe(Nullsafe.Mode.LOCAL) -@DoNotStrip -public class ComponentFactory { - - static { - FabricSoLoader.staticInit(); - } - - @NonNull @DoNotStrip private final HybridData mHybridData; - - @DoNotStrip - private static native HybridData initHybrid(); - - @DoNotStrip - public ComponentFactory() { - mHybridData = initHybrid(); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentFactory.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentFactory.kt new file mode 100644 index 00000000000..bd863d6cd55 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/ComponentFactory.kt @@ -0,0 +1,25 @@ +/* + * 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.fabric + +import com.facebook.jni.HybridData +import com.facebook.proguard.annotations.DoNotStripAny + +@DoNotStripAny +public class ComponentFactory { + + @Suppress("NoHungarianNotation") private val mHybridData: HybridData = initHybrid() + + private companion object { + init { + FabricSoLoader.staticInit() + } + + @JvmStatic private external fun initHybrid(): HybridData + } +}