
回复
C-API 版本使用XComponent总共分成了两个步骤:
createSurface的时候主要做了以下的操作:
1. 创建并将XComponentSurface记录到Map中:
2. 在XComponentSurface中创建rootView,用于挂载C-API的组件,并在Surface上统一处理Touch事件:
startSurface的时候主要做了以下的操作:
1. 在ArkTS侧创建XComponent,并设置id,type与libraryname属性。其中:
2. 在CPP侧的Init中调用registerNativeXComponent函数,该函数中调用了OH_NativeXComponent_GetXComponentId用于获取ArkTS设置的id,并根据id找到对应的Instance与Surface。同时还要获取nativeXComponent对象,记录ArkTS侧的XComponent。
3. 调用OH_NativeXComponent_AttachNativeRootNode,将XComponentSurface中记录的rootView连接到ArkTS侧的XComponent上: