native-view.md 2.3 KB
Newer Older
1 2
## native-view

shutao-dc's avatar
shutao-dc 已提交
3 4
<!-- UTSCOMJSON.native-view.description -->

shutao-dc's avatar
shutao-dc 已提交
5
`native-view`自身没有渲染内容,开发者提供对应平台原生view与`native-view`进行绑定,`native-view`将展示该view的渲染内容
6 7 8 9 10 11 12 13 14 15
<!-- UTSCOMJSON.native-view.compatibility -->

<!-- UTSCOMJSON.native-view.attribute -->

<!-- UTSCOMJSON.native-view.event -->

<!-- UTSCOMJSON.native-view.component_type -->

### 使用场景

shutao-dc's avatar
shutao-dc 已提交
16
`native-view` 适用于开发[标准模式的uts组件](../plugin/uts-vue-component.md)
17 18 19 20 21

### 使用教程

+ 获取 UniNativeViewElement

shutao-dc's avatar
shutao-dc 已提交
22
`native-view`提供 @init 监听元素初始化,通过事件[UniNativeViewInitEvent](#uninativeviewinitevent)的 detail.element 获取到 [UniNativeViewElement](../dom/uninativeviewelement.md)
23 24 25

+ 绑定原生view

shutao-dc's avatar
shutao-dc 已提交
26
[UniNativeViewElement](../dom/uninativeviewelement.md) 提供了[bindAndroidView](../dom/uninativeviewelement.md#bindandroidview)`native-view`绑定安卓原生view, [bindIOSView](../dom/uninativeviewelement.md#bindiosview)`native-view`绑定IOS原生view, 绑定后view则自动适配[组件全局属性](common.md#组件全局属性)
27 28 29

+ 分发自定义事件

shutao-dc's avatar
shutao-dc 已提交
30
[UniNativeViewElement](../dom/uninativeviewelement.md) 提供了dispatchEvent分发event事件API,注意:事件数据类型暂时只支持[UniNativeViewEvent](#uninativeviewevent)
31

shutao-dc's avatar
shutao-dc 已提交
32
具体示例请参考:[native-button](https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/uni_modules/native-button/components/native-button/native-button.uvue)插件,该插件使用`native-view`封装原生button实现的native-button。
33 34 35

**注意:**

shutao-dc's avatar
shutao-dc 已提交
36 37 38 39
+ android平台`native-view`组件不支持[list-item复用机制](list-item.md#list-item复用机制),list-item其他子组件不受影响正常启动复用业务。
+ android平台`native-view`组件不支持background、border、boxshadow属性
+ android平台`native-view`组件不支持子组件
+ android平台`native-view`组件不支持overflow属性设置visible,仅支持hidden
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

<!-- UTSCOMJSON.native-view.children -->

<!-- UTSCOMJSON.native-view.example -->

<!-- UTSCOMJSON.native-view.reference -->

## UniNativeViewEvent

<!-- CUSTOMTYPEJSON.UniNativeViewEvent.description -->

<!-- CUSTOMTYPEJSON.UniNativeViewEvent.extends -->

<!-- CUSTOMTYPEJSON.UniNativeViewEvent.param -->

<!-- CUSTOMTYPEJSON.UniNativeViewEvent.compatibility -->

<!-- CUSTOMTYPEJSON.UniNativeViewEvent.example -->