From c3f672cef7d4f287d3d729d33650f917ed132a0c Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Fri, 30 Jun 2023 06:02:01 -0700 Subject: [PATCH] Use vals inside ReactApplication (#38088) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38088 For better Kotlin interop we should be using `val` in this interface rather than just `fun`. This is not a breaking change as Java users can still use `getReactNativeHost()` as before. Changelog: [Internal] [Changed] - Use vals inside ReactApplication Reviewed By: javache Differential Revision: D47053030 fbshipit-source-id: 4a7fbc71a76be54e1cf7daef499b9bc3e8fc615a --- .../src/main/java/com/facebook/react/ReactApplication.kt | 7 +++---- .../app/src/main/java/com/helloworld/MainApplication.kt | 4 +--- 2 files changed, 4 insertions(+), 7 deletions(-) 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 index 4bd21d7bdd2..2712ae20eb7 100644 --- 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 @@ -14,13 +14,12 @@ import com.facebook.react.interfaces.ReactHostInterface /** Interface that represents an instance of a React Native application */ interface ReactApplication { /** Get the default [ReactNativeHost] for this app. */ - fun getReactNativeHost(): ReactNativeHost + val reactNativeHost: ReactNativeHost /** * Get the default [ReactHostInterface] for this app. This method will be used by the new * architecture of react native */ - fun getReactHostInterface(): ReactHostInterface? { - return null - } + val reactHostInterface: ReactHostInterface? + get() = null } diff --git a/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.kt b/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.kt index f1c5e490fca..7da676738b0 100644 --- a/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.kt +++ b/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.kt @@ -11,7 +11,7 @@ import com.facebook.soloader.SoLoader class MainApplication : Application(), ReactApplication { - private val reactNativeHost: ReactNativeHost = + override val reactNativeHost: ReactNativeHost = object : DefaultReactNativeHost(this) { override fun getPackages(): List { // Packages that cannot be autolinked yet can be added manually here, for example: @@ -27,8 +27,6 @@ class MainApplication : Application(), ReactApplication { override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED } - override fun getReactNativeHost(): ReactNativeHost = reactNativeHost - override fun onCreate() { super.onCreate() SoLoader.init(this, false)