Skip to content

Commit c3f672c

Browse files
cortinicofacebook-github-bot
authored andcommitted
Use vals inside ReactApplication (#38088)
Summary: Pull Request resolved: #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
1 parent 3a912a3 commit c3f672c

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactApplication.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ import com.facebook.react.interfaces.ReactHostInterface
1414
/** Interface that represents an instance of a React Native application */
1515
interface ReactApplication {
1616
/** Get the default [ReactNativeHost] for this app. */
17-
fun getReactNativeHost(): ReactNativeHost
17+
val reactNativeHost: ReactNativeHost
1818

1919
/**
2020
* Get the default [ReactHostInterface] for this app. This method will be used by the new
2121
* architecture of react native
2222
*/
23-
fun getReactHostInterface(): ReactHostInterface? {
24-
return null
25-
}
23+
val reactHostInterface: ReactHostInterface?
24+
get() = null
2625
}

packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import com.facebook.soloader.SoLoader
1111

1212
class MainApplication : Application(), ReactApplication {
1313

14-
private val reactNativeHost: ReactNativeHost =
14+
override val reactNativeHost: ReactNativeHost =
1515
object : DefaultReactNativeHost(this) {
1616
override fun getPackages(): List<ReactPackage> {
1717
// Packages that cannot be autolinked yet can be added manually here, for example:
@@ -27,8 +27,6 @@ class MainApplication : Application(), ReactApplication {
2727
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
2828
}
2929

30-
override fun getReactNativeHost(): ReactNativeHost = reactNativeHost
31-
3230
override fun onCreate() {
3331
super.onCreate()
3432
SoLoader.init(this, false)

0 commit comments

Comments
 (0)