refactor(multiple): 优化多个 React Native 宿主的加载逻辑

- 修改 MultipleReactActivityDelegate 中的 loadApp 方法,使用动态传递的 mainComponentName
- 在 BuzActivity 中添加处理 React Host 生命周期状态的注释代码
-调整 MainApplication 中的 JS 主模块名和 Bundle 资源名的获取逻辑
- 修改 package.json 中 common bundle 的构建配置,关闭压缩并开启缓存重置
这个提交包含在:
xuqm 2025-07-16 18:40:32 +08:00
父节点 054077f19d
当前提交 205e4e8680
共有 3 个文件被更改,包括 20 次插入10 次删除

查看文件

@ -32,7 +32,14 @@ class BuzActivity : ReactActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AppManager.addActivity(this)
Toast.makeText(this, "BuzActivity:" + NavigationHelper.routerName, Toast.LENGTH_SHORT).show()
Toast.makeText(this, "BuzActivity:" + NavigationHelper.routerName, Toast.LENGTH_SHORT)
.show()
// if (reactHost.lifecycleState != LifecycleState.RESUMED) {
// reactHost.onHostResume(this)
// }
// Handler(Looper.getMainLooper()).post {
// reactHost.reload("Requested by CodeUpdater")
// }
}
override fun onDestroy() {

查看文件

@ -23,20 +23,23 @@ class MainApplication : Application(), ReactApplication {
add(NavigationPackage())
}
override fun getJSMainModuleName(): String =
if (getUseDeveloperSupport()) "index" else "commom"
override fun getBundleAssetName(): String? =
if (getUseDeveloperSupport()) "index.android.bundle" else null
//
// 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()) {
// super.getJSBundleFile()
// } else {
// FileHelper.getFilePath("common.android.bundle", this@MainApplication, "bundles")
// }
override fun getJSBundleFile(): String =
override fun getJSBundleFile(): String? = if (getUseDeveloperSupport()) {
null
} else {
FileHelper.getFilePath("common.android.bundle", this@MainApplication, "bundles")
}
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
@ -47,7 +50,7 @@ class MainApplication : Application(), ReactApplication {
override val reactHost: ReactHost
get() = getDefaultReactHost(applicationContext, reactNativeHost)
companion object{
companion object {
var isNew = true
}

查看文件

@ -58,7 +58,7 @@ class MultipleReactActivityDelegate(
),
)
this.loadApp("app")
this.loadApp(mainComponentName)
} else {
this.mReactDelegate =
object : ReactDelegate(