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

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

`native-view`自身没有渲染内容,开发者提供对应平台原生view与`native-view`进行绑定,`native-view`将展示该view的渲染内容。vue组件集成`native-view`,实现可展示原生view渲染内容的vue组件
6 7 8 9 10 11 12 13 14 15 16

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

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

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

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

### 使用场景

shutao-dc's avatar
shutao-dc 已提交
17
vue组件开发规范开发集成原生view渲染内容的通用组件
18 19 20 21 22

### 使用教程

+ 获取 UniNativeViewElement

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

+ 绑定原生view

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

+ 分发自定义事件

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

shutao-dc's avatar
shutao-dc 已提交
33
具体示例请参考:[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。
34 35 36

**注意:**

shutao-dc's avatar
shutao-dc 已提交
37 38 39 40
+ 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
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

<!-- 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 -->