Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
unidocs-uni-app-x-zh
提交
316ad797
U
unidocs-uni-app-x-zh
项目概览
DCloud
/
unidocs-uni-app-x-zh
通知
207
Star
4
Fork
46
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
14
列表
看板
标记
里程碑
合并请求
16
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-uni-app-x-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
14
Issue
14
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
316ad797
编写于
11月 06, 2024
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: UniNativeViewEvent
上级
ffed9229
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
81 addition
and
81 deletion
+81
-81
docs/component/common.md
docs/component/common.md
+12
-0
docs/component/native-view.md
docs/component/native-view.md
+69
-81
未找到文件。
docs/component/common.md
浏览文件 @
316ad797
...
...
@@ -298,6 +298,18 @@ UniTouchEvent 的 type 类型包括:touchstart、touchmove、touchend、touchc
<!-- CUSTOMTYPEJSON.UniKeyEvent.example -->
## UniNativeViewEvent
<!-- CUSTOMTYPEJSON.UniNativeViewEvent.description -->
<!-- CUSTOMTYPEJSON.UniNativeViewEvent.extends -->
<!-- CUSTOMTYPEJSON.UniNativeViewEvent.param -->
<!-- CUSTOMTYPEJSON.UniNativeViewEvent.compatibility -->
<!-- CUSTOMTYPEJSON.UniNativeViewEvent.example -->
## 参见
-
[
相关 Bug
](
https://issues.dcloud.net.cn/?mid=component.global-properties-events
)
docs/component/native-view.md
浏览文件 @
316ad797
## native-view
<!-- UTSCOMJSON.native-view.description -->
`native-view`
自身没有渲染内容,开发者可以通过DOM API获取到
`native-view`
对应的原生view,然后提供平台原生view与
`native-view`
进行绑定,
`native-view`
将展示该view的渲染内容。
`<native-view>`
组件是uni-app x下扩展原生组件(如map)的重要方式。事实上官方的map组件就是使用
`<native-view>`
开发的。详见下方的使用场景章节。
<!-- UTSCOMJSON.native-view.compatibility -->
<!-- UTSCOMJSON.native-view.attribute -->
<!-- UTSCOMJSON.native-view.event -->
<!-- UTSCOMJSON.native-view.component_type -->
### 使用场景
`native-view`
适用于开发
[
uts插件-标准模式组件
](
../plugin/uts-component-vue.md
)
### 使用教程
#### 获取 UniNativeViewElement
`native-view`
提供 @init 监听元素初始化,通过事件
[
UniNativeViewInitEvent
](
#uninativeviewinitevent
)
的 detail.element 获取到
[
UniNativeViewElement
](
../dom/uninativeviewelement.md
)
。
#### UniNativeViewElement绑定原生view
**Android 平台:**
[
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
#### 分发自定义事件
[
UniNativeViewElement
](
../dom/uninativeviewelement.md
)
提供了dispatchEvent分发event事件API,注意:事件数据类型暂时只支持
[
UniNativeViewEvent
](
#uninativeviewevent
)
。
具体示例请参考:
[
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。
### 注意事项
## native-view
<!-- UTSCOMJSON.native-view.description -->
`native-view`
自身没有渲染内容,开发者可以通过DOM API获取到
`native-view`
对应的原生view,然后提供平台原生view与
`native-view`
进行绑定,
`native-view`
将展示该view的渲染内容。
`<native-view>`
组件是uni-app x下扩展原生组件(如map)的重要方式。事实上官方的map组件就是使用
`<native-view>`
开发的。详见下方的使用场景章节。
<!-- UTSCOMJSON.native-view.compatibility -->
<!-- UTSCOMJSON.native-view.attribute -->
<!-- UTSCOMJSON.native-view.event -->
<!-- UTSCOMJSON.native-view.component_type -->
### 使用场景
`native-view`
适用于开发
[
uts插件-标准模式组件
](
../plugin/uts-component-vue.md
)
### 使用教程
#### 获取 UniNativeViewElement
`native-view`
提供 @init 监听元素初始化,通过事件
[
UniNativeViewInitEvent
](
#uninativeviewinitevent
)
的 detail.element 获取到
[
UniNativeViewElement
](
../dom/uninativeviewelement.md
)
。
#### UniNativeViewElement绑定原生view
**Android 平台:**
[
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
#### 分发自定义事件
[
UniNativeViewElement
](
../dom/uninativeviewelement.md
)
提供了dispatchEvent分发event事件API,注意:事件数据类型暂时只支持
[
UniNativeViewEvent
](
./common.md#uninativeviewevent
)
。
具体示例请参考:
[
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。
### 注意事项
+
app平台
`native-view`
组件绑定原生view后自动适配
[
组件全局属性
](
common.md#组件全局属性
)
+
app平台
`native-view`
组件不支持自定义属性,使用
[
uts插件-标准模式组件-声明属性props
](
../plugin/uts-component-vue.md##组件声明属性props
)
实现自定义属性目的
+
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
<!-- UTSCOMJSON.native-view.children -->
+
app平台
`native-view`
组件不支持自定义属性,使用
[
uts插件-标准模式组件-声明属性props
](
../plugin/uts-component-vue.md##组件声明属性props
)
实现自定义属性目的
+
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
<!-- UTSCOMJSON.native-view.children -->
<!-- UTSCOMJSON.native-view.example -->
NativeButton原生对象代码如下:
...
...
@@ -109,26 +109,26 @@ export class NativeButton {
element : UniNativeViewElement;
button : UIButton | null;
constructor(element : UniNativeViewElement) {
constructor(element : UniNativeViewElement) {
// 接收组件传递过来的UniNativeViewElement
this.element = element;
super.init()
this.bindView();
}
// element 绑定原生view
bindView() {
// 初始化原生 UIButton
this.button = new UIButton(type=UIButton.ButtonType.system)
// 构建方法选择器
const method = Selector("buttonClickAction")
// button 绑定点击回调方法
button?.addTarget(this, action = method, for = UIControl.Event.touchUpInside)
bindView() {
// 初始化原生 UIButton
this.button = new UIButton(type=UIButton.ButtonType.system)
// 构建方法选择器
const method = Selector("buttonClickAction")
// button 绑定点击回调方法
button?.addTarget(this, action = method, for = UIControl.Event.touchUpInside)
// UniNativeViewElement 绑定原生 view
this.element.bindIOSView(this.button!);
}
updateText(text : string) {
updateText(text : string) {
// 更新 button 显示文字
this.button?.setTitle(text, for = UIControl.State.normal)
}
...
...
@@ -137,35 +137,23 @@ export class NativeButton {
* 按钮点击回调方法
* 在 swift 中,所有target-action (例如按钮的点击事件,NotificationCenter 的通知事件等)对应的 action 函数前面都要使用 @objc 进行标记。
*/
@objc buttonClickAction() {
@objc buttonClickAction() {
//构建自定义 UniNativeViewEvent 对象
let event = new UniNativeViewEvent("customClick")
//触发自定义事件
let event = new UniNativeViewEvent("customClick")
//触发自定义事件
this.element.dispatchEvent(event)
}
destroy() {
destroy() {
// 释放 UTS 实例对象,避免内存泄露
UTSiOS.destroyInstance(this)
}
}
}
```
:::
:::
具体示例请参考:
[
native-button
](
https://gitcode.net/dcloud/hello-uni-app-x/-/blob/alpha/uni_modules/native-button/components/native-button/native-button.uvue
)
插件
<!-- UTSCOMJSON.native-view.reference -->
## UniNativeViewEvent
<!-- CUSTOMTYPEJSON.UniNativeViewEvent.description -->
<!-- CUSTOMTYPEJSON.UniNativeViewEvent.extends -->
<!-- CUSTOMTYPEJSON.UniNativeViewEvent.param -->
<!-- CUSTOMTYPEJSON.UniNativeViewEvent.compatibility -->
<!-- CUSTOMTYPEJSON.UniNativeViewEvent.example -->
<!-- UTSCOMJSON.native-view.reference -->
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录