Skip to content

Commit aaa7ba4

Browse files
cortinicofacebook-github-bot
authored andcommitted
HelloWorld should not use ReactNativeHost (#53399)
Summary: Pull Request resolved: #53399 We currently create application template that are still using `ReactNativeHost`. As this is a legacy arch class, we should remove it from the template ASAP so that users can organically migrate away from it. I will also update https://github.com/react-native-community/template with the same changes I'm applying here. Changelog: [Internal] [Changed] - Reviewed By: mdvacca Differential Revision: D80708461 fbshipit-source-id: e0d4a1f817e6fdddd93405decf77fd115956ec51
1 parent 2689d4d commit aaa7ba4

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

private/helloworld/android/app/src/main/java/com/helloworld/MainApplication.kt

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,22 @@ import com.facebook.react.PackageList
1212
import com.facebook.react.ReactApplication
1313
import com.facebook.react.ReactHost
1414
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
15-
import com.facebook.react.ReactNativeHost
16-
import com.facebook.react.ReactPackage
1715
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
18-
import com.facebook.react.defaults.DefaultReactNativeHost
1916

2017
class MainApplication : Application(), ReactApplication {
2118

22-
override val reactNativeHost: ReactNativeHost =
23-
object : DefaultReactNativeHost(this) {
24-
override fun getPackages(): List<ReactPackage> =
25-
PackageList(this).packages.apply {
26-
// Packages that cannot be autolinked yet can be added manually here, for example:
27-
// add(MyReactNativePackage())
28-
}
29-
30-
override fun getJSMainModuleName(): String = "index"
31-
32-
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
19+
override val reactHost: ReactHost by
20+
lazy(LazyThreadSafetyMode.NONE) {
21+
getDefaultReactHost(
22+
context = applicationContext,
23+
packageList =
24+
PackageList(this).packages.apply {
25+
// Packages that cannot be autolinked yet can be added manually here, for example:
26+
// add(MyReactNativePackage())
27+
},
28+
)
3329
}
3430

35-
override val reactHost: ReactHost
36-
get() = getDefaultReactHost(applicationContext, reactNativeHost)
37-
3831
override fun onCreate() {
3932
super.onCreate()
4033
loadReactNative(this)

0 commit comments

Comments
 (0)