最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

android - Can we create ReactNative TurboModules without running CodeGen schema generator? - Stack Overflow

programmeradmin3浏览0评论

For my project I have the ReactNative project and Android project created separately. We create a bundle from RN project and save it at the required location in Android project for creating the build.

Now because of the above reason, I can't run CodeGen to create Spec file for the module. Is it a requirement to be able to create TurboModules or can I create a TurboModule without a schema as well.

I've created the below files to test this functionality:

class DemoTurboModule(reactContext: ReactApplicationContext): ReactContextBaseJavaModule(reactContext), TurboModule {

    companion object{
        const val NAME = "DemoTurboModule"
    }
    override fun getName() = NAME

    @ReactMethod
    fun logMessage(message: String) {
        Log.d("MyTurboModule", message)
    }
}

Package:

class DemoTurboPackage: BaseReactPackage() {

    override fun getModule(name: String, context: ReactApplicationContext): NativeModule? {
        if(name == DemoTurboModule.NAME){
            return DemoTurboModule(context)
        } else {
            return null
        }
    }

    override fun getReactModuleInfoProvider() =  ReactModuleInfoProvider {
        mapOf(
            DemoTurboModule.NAME to ReactModuleInfo(
                DemoTurboModule.NAME,
                DemoTurboModule.NAME,
                false,
                false,
                false,
                true
            )
        )
    }
}
发布评论

评论列表(0)

  1. 暂无评论