You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native 0.71 Android端通过ReactFragment启用Fabric的问题

ReactFragment 启用 Fabric 配置问题解决

问题出在哪

用ReactActivityDelegate启动RN组件时,框架会自动把Fabric相关的关键配置(fabric: true、concurrentRoot: true)塞进启动参数里,但ReactFragment.Builder不会自动做这件事,得手动加这些参数。

怎么解决

直接在启动参数里补上Fabric相关配置就行,两种方式都可以:

方式一:修改getLaunchOptions方法

private fun getLaunchOptions(message: String): Bundle {
    val bundle = Bundle()
    // 原有业务参数
    val initialProps = Bundle()
    initialProps.putString("message", message)
    // 加上Fabric必须的配置
    initialProps.putBoolean("concurrentRoot", true)
    bundle.putBundle("initialProps", initialProps)
    bundle.putBoolean("fabric", true)
    return bundle
}

方式二:直接在构建Fragment时注入参数

val reactNativeFragment: Fragment = ReactFragment.Builder()
    .setComponentName("ComponentName")
    .setLaunchOptions(Bundle().apply {
        val initialProps = Bundle().apply {
            putString("message", "test message")
            putBoolean("concurrentRoot", true)
        }
        putBundle("initialProps", initialProps)
        putBoolean("fabric", true)
    })
    .build()

supportFragmentManager
    .beginTransaction()
    .add(R.id.react_container, reactNativeFragment)
    .commit()

验证效果

修改完重新启动,日志应该会输出和ReactActivityDelegate类似的内容,能看到fabric:true和concurrentRoot:true,说明Fabric已经启用:

Running "ComponentName" with {"fabric":true,"initialProps":{"concurrentRoot":true,"message":"test message"},"rootTag":xxx}

内容的提问来源于stack exchange,提问作者Manish Patiyal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 13:42:53