From ef10ac2e49c8c11a989c23e5b99c1536ca9edd7b Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Tue, 2 Apr 2024 13:00:01 -0700 Subject: [PATCH] Kotlinify CallInvokerHolderImpl Summary: Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Differential Revision: D55655061 --- .../ReactAndroid/api/ReactAndroid.api | 2 +- .../turbomodule/core/NativeModuleSoLoader.kt | 6 ++-- ...lderImpl.java => CallInvokerHolderImpl.kt} | 29 +++++++++---------- 3 files changed, 18 insertions(+), 19 deletions(-) rename packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/{CallInvokerHolderImpl.java => CallInvokerHolderImpl.kt} (53%) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index cfb0292319a075..cd7b358ee46456 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -3873,7 +3873,7 @@ public abstract interface class com/facebook/react/touch/ReactInterceptingViewGr public abstract fun setOnInterceptTouchEventListener (Lcom/facebook/react/touch/OnInterceptTouchEventListener;)V } -public class com/facebook/react/turbomodule/core/CallInvokerHolderImpl : com/facebook/react/turbomodule/core/interfaces/CallInvokerHolder { +public final class com/facebook/react/turbomodule/core/CallInvokerHolderImpl : com/facebook/react/turbomodule/core/interfaces/CallInvokerHolder { } public class com/facebook/react/turbomodule/core/NativeMethodCallInvokerHolderImpl : com/facebook/react/turbomodule/core/interfaces/NativeMethodCallInvokerHolder { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/NativeModuleSoLoader.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/NativeModuleSoLoader.kt index 4d6509f01e6694..9dd54b55a5f04d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/NativeModuleSoLoader.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/NativeModuleSoLoader.kt @@ -9,13 +9,13 @@ package com.facebook.react.internal.turbomodule.core import com.facebook.soloader.SoLoader -internal class NativeModuleSoLoader { - companion object { +public class NativeModuleSoLoader { + public companion object { private var isSoLibraryLoaded = false @Synchronized @JvmStatic - fun maybeLoadSoLibrary() { + public fun maybeLoadSoLibrary() { if (!isSoLibraryLoaded) { SoLoader.loadLibrary("turbomodulejsijni") isSoLibraryLoaded = true diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/CallInvokerHolderImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/CallInvokerHolderImpl.kt similarity index 53% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/CallInvokerHolderImpl.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/CallInvokerHolderImpl.kt index 455eeb840773a6..a89b6a6d0a7bce 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/CallInvokerHolderImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/CallInvokerHolderImpl.kt @@ -5,31 +5,30 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.turbomodule.core; +package com.facebook.react.turbomodule.core -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.jni.HybridData; -import com.facebook.proguard.annotations.DoNotStrip; -import com.facebook.react.common.annotations.FrameworkAPI; -import com.facebook.react.internal.turbomodule.core.NativeModuleSoLoader; -import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder; +import com.facebook.jni.HybridData +import com.facebook.proguard.annotations.DoNotStrip +import com.facebook.react.common.annotations.FrameworkAPI +import com.facebook.react.internal.turbomodule.core.NativeModuleSoLoader +import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder /** * JSCallInvoker is created at a different time/place (i.e: in CatalystInstance) than * TurboModuleManager. Therefore, we need to wrap JSCallInvoker within a hybrid class so that we may * pass it from CatalystInstance, through Java, to TurboModuleManager::initHybrid. */ -@Nullsafe(Nullsafe.Mode.LOCAL) @FrameworkAPI -public class CallInvokerHolderImpl implements CallInvokerHolder { +public class CallInvokerHolderImpl : CallInvokerHolder { + @DoNotStrip private val mHybridData: HybridData - @DoNotStrip private final HybridData mHybridData; - - static { - NativeModuleSoLoader.maybeLoadSoLibrary(); + private constructor(hybridData: HybridData) { + mHybridData = hybridData } - private CallInvokerHolderImpl(HybridData hd) { - mHybridData = hd; + private companion object { + init { + NativeModuleSoLoader.maybeLoadSoLibrary() + } } }