RnMultibundler/android/app/src/main/java/com/trust/ywx/MainApplication.kt

66 行
2.3 KiB
Kotlin

package com.trust.ywx
import android.app.Application
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.trust.ywx.specs.navigation.NavigationPackage
import com.trust.ywx.utils.FileHelper
import java.io.File
class MainApplication : Application(), ReactApplication {
override val reactNativeHost: ReactNativeHost = object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> = PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
add(NavigationPackage())
}
override fun getJSMainModuleName(): String =
if (getUseDeveloperSupport()) "index" else "commom"
override fun getBundleAssetName(): String? =
if (getUseDeveloperSupport()) "index.android.bundle" else null
override fun getJSBundleFile(): String? = if (getUseDeveloperSupport()) {
null
} else {
FileHelper.getFilePath("common.android.bundle", this@MainApplication, "bundles")
}
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
override val isNewArchEnabled: Boolean = true
override val isHermesEnabled: Boolean = true
}
override val reactHost: ReactHost
get() = getDefaultReactHost(applicationContext, reactNativeHost)
companion object {
var isNew = true
}
override fun onCreate() {
val f = File(FileHelper.getDirPath(this, "bundles"))
val bf = File(FileHelper.getFilePath("bundle.zip", this, "bundles"))
if (!f.exists() || !f.isDirectory) {
f.mkdirs()
}
if (f.list().size <= 1) {
bf.delete()
FileHelper.copyAssetFileToInternalStorage(this, "bundle.zip", bf)
if (bf.exists()) {
FileHelper.unzip(bf, f)
}
}
super.onCreate()
loadReactNative(this)
}
}