1# ContentSlot 2 3用于渲染并管理Native层使用C-API创建的组件。 4 5支持混合模式开发,当容器是ArkTS组件,子组件在Native侧创建时,推荐使用ContentSlot占位组件。 6 7> **说明:** 8> 9> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 10 11## 接口 12 13ContentSlot(content: Content) 14 15当内容添加到占位符组件时调用。 16 17**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 18 19**系统能力:** SystemCapability.ArkUI.ArkUI.Full 20 21**参数:** 22 23| 参数名 | 类型 | 必填 | 参数描述 | 24| ------- | -------- | ---- | ------------------------------------------------------------ | 25| content | [Content](#content) | 是 | Content作为ContentSlot的管理器,通过Native侧提供的接口,可以注册并触发ContentSlot的上下树事件回调以及管理ContentSlot的子组件。 | 26 27## Content 28 29type Content = Content 30 31定义ComponentContent和NodeContent的基类。 32 33**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 34 35**系统能力:** SystemCapability.ArkUI.ArkUI.Full 36 37| 类型 | 说明 | 38| ---- | ------------------------------------------------------------ | 39| [Content](../js-apis-arkui-Content.md) | 定义ComponentContent和NodeContent的基类。 | 40 41## 示例 42 43下面的示例展示了ContentSlot的基本用法。 44 45```ts 46import { nativeNode } from 'libNativeNode.so' // 开发者自己实现的so 47import { NodeContent } from '@kit.ArkUI' 48 49@Entry 50@Component 51struct Parent { 52 private nodeContent: Content = new NodeContent(); 53 54 aboutToAppear() { 55 // 通过C-API创建节点,并添加到管理器nodeContent上 56 nativeNode.createNativeNode(this.nodeContent); 57 } 58 59 build() { 60 Column() { 61 // 显示nodeContent管理器里存放的Native侧的组件 62 ContentSlot(this.nodeContent) 63 } 64 } 65} 66``` 67 68上述代码中so的实现可参考[Native XComponent](https://gitee.com/openharmony/applications_app_samples/tree/master/code/BasicFeature/Native/NdkXComponent)。 69 70