Skip to content

Commit 5a5bda3

Browse files
committed
Add MainApplication class to initialize React Native and CodePush integration
1 parent 5f75f78 commit 5a5bda3

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.testcodepush
2+
3+
import android.app.Application
4+
import com.facebook.react.PackageList
5+
import com.facebook.react.ReactApplication
6+
import com.facebook.react.ReactHost
7+
import com.facebook.react.ReactNativeHost
8+
import com.facebook.react.ReactPackage
9+
import com.facebook.react.common.annotations.UnstableReactNativeAPI
10+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
11+
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
12+
import com.facebook.react.defaults.DefaultReactNativeHost
13+
import com.facebook.react.soloader.OpenSourceMergedSoMapping
14+
import com.facebook.soloader.SoLoader
15+
import com.microsoft.codepush.react.CodePush
16+
17+
@OptIn(UnstableReactNativeAPI::class)
18+
class MainApplication : Application(), ReactApplication {
19+
20+
override val reactNativeHost: ReactNativeHost =
21+
object : DefaultReactNativeHost(this) {
22+
override fun getPackages(): List<ReactPackage> {
23+
val packages = PackageList(this).packages
24+
// Packages that cannot be autolinked yet can be added manually here, for example:
25+
// packages.add(new MyReactNativePackage());
26+
return packages
27+
}
28+
29+
override fun getJSMainModuleName(): String = "index"
30+
override fun getJSBundleFile(): String = CodePush.getJSBundleFile()
31+
32+
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
33+
34+
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
35+
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
36+
}
37+
38+
override val reactHost: ReactHost get() = getDefaultReactHost(this, reactNativeHost)
39+
40+
override fun onCreate() {
41+
super.onCreate()
42+
SoLoader.init(this, OpenSourceMergedSoMapping)
43+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
44+
// If you opted-in for the New Architecture, we load the native entry point for this app.
45+
load()
46+
}
47+
}
48+
49+
}

0 commit comments

Comments
 (0)