From 68fe124fdc0d03d2d44942ba86c90df0b20d81f1 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Sun, 25 Jun 2023 00:29:55 -0700 Subject: [PATCH] Convert ReactApplication to kotlin (#37987) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37987 Convert ReactApplication to kotlin bypass-github-export-checks changelog: [internal] internal Reviewed By: cortinico Differential Revision: D46772472 fbshipit-source-id: 70c6b9fad3e4e365434b59f184753ca23cf5ed56 --- .../react-native/ReactAndroid/build.gradle | 5 ++++ .../facebook/react/ReactActivityDelegate.java | 2 +- .../com/facebook/react/ReactApplication.java | 26 ------------------- .../com/facebook/react/ReactApplication.kt | 24 +++++++++++++++++ 4 files changed, 30 insertions(+), 27 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactApplication.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactApplication.kt diff --git a/packages/react-native/ReactAndroid/build.gradle b/packages/react-native/ReactAndroid/build.gradle index 665c0f02901..29f34c4ccdc 100644 --- a/packages/react-native/ReactAndroid/build.gradle +++ b/packages/react-native/ReactAndroid/build.gradle @@ -471,6 +471,11 @@ android { targetCompatibility = JavaVersion.VERSION_11 } + kotlinOptions { + // Using '-Xjvm-default=all' to support usage of @JvmDefault in kotlin files + freeCompilerArgs = ['-Xjvm-default=all'] + } + defaultConfig { minSdk = 21 targetSdk = 33 diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java index 5c942e90140..1031586c47e 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactActivityDelegate.java @@ -89,7 +89,7 @@ public class ReactActivityDelegate { } public ReactHostInterface getReactHost() { - return ((ReactApplication) getPlainActivity().getApplication()).getReactHostInterface(); + return ((ReactApplication) getPlainActivity().getApplication()).reactHostInterface(); } public ReactInstanceManager getReactInstanceManager() { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactApplication.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactApplication.java deleted file mode 100644 index b8abe0cf169..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactApplication.java +++ /dev/null @@ -1,26 +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; - -import androidx.annotation.Nullable; -import com.facebook.react.interfaces.ReactHostInterface; - -/** Interface that represents an instance of a React Native application */ -public interface ReactApplication { - - /** Get the default {@link ReactNativeHost} for this app. */ - ReactNativeHost getReactNativeHost(); - - /** - * Get the default {@link ReactHostInterface} for this app. This method will be used by the new - * architecture of react native - */ - default @Nullable ReactHostInterface getReactHostInterface() { - return null; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactApplication.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactApplication.kt new file mode 100644 index 00000000000..eae538cd80d --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactApplication.kt @@ -0,0 +1,24 @@ +/* + * 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 + +import com.facebook.react.common.annotations.UnstableReactNativeAPI +import com.facebook.react.interfaces.ReactHostInterface + +@OptIn(UnstableReactNativeAPI::class) +/** Interface that represents an instance of a React Native application */ +interface ReactApplication { + /** Get the default [ReactNativeHost] for this app. */ + fun getReactNativeHost(): ReactNativeHost + + /** + * Get the default [ReactHostInterface] for this app. This method will be used by the new + * architecture of react native + */ + @JvmDefault fun reactHostInterface(): ReactHostInterface? = null +}