native-view.md 2.5 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

### 使用教程

shutao-dc's avatar
shutao-dc 已提交
20
#### 获取 UniNativeViewElement
21

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

shutao-dc's avatar
shutao-dc 已提交
24 25 26
#### UniNativeViewElement绑定原生view

**Android 平台:**
27

shutao-dc's avatar
shutao-dc 已提交
28 29 30 31 32 33 34
[UniNativeViewElement](../dom/uninativeviewelement.md) 提供[bindAndroidView](../dom/uninativeviewelement.md#bindandroidview)函数与`native-view`绑定android平台原生view

**IOS 平台:**

[UniNativeViewElement](../dom/uninativeviewelement.md) 提供[bindIOSView](../dom/uninativeviewelement.md#bindiosview)函数与`native-view`绑定ios平台原生view

绑定后view则自动适配[组件全局属性](common.md#组件全局属性)
35

shutao-dc's avatar
shutao-dc 已提交
36
#### 分发自定义事件
37

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

shutao-dc's avatar
shutao-dc 已提交
40
具体示例请参考:[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。
41 42 43

**注意:**

shutao-dc's avatar
shutao-dc 已提交
44 45 46 47
+ 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

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