瀏覽代碼

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

- 修改 MultipleReactActivityDelegate 中的 loadApp 方法,使用动态传递的 mainComponentName
- 在 BuzActivity 中添加处理 React Host 生命周期状态的注释代码
-调整 MainApplication 中的 JS 主模块名和 Bundle 资源名的获取逻辑
- 修改 package.json 中 common bundle 的构建配置,关闭压缩并开启缓存重置
xuqm 1 周之前
父節點
當前提交
205e4e8680

+ 8 - 1
android/app/src/main/java/com/trust/ywx/BuzActivity.kt

@@ -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() {

+ 11 - 8
android/app/src/main/java/com/trust/ywx/MainApplication.kt

@@ -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
     }
 

+ 1 - 1
android/app/src/main/java/com/trust/ywx/multiple/MultipleReactActivityDelegate.kt

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