Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
bf96431e
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
bf96431e
编写于
10月 08, 2022
作者:
L
luoying_ace
提交者:
Gitee
10月 08, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md.
Signed-off-by:
N
luoying_ace
<
luoying19@huawei.com
>
上级
324b3f87
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
74 addition
and
58 deletion
+74
-58
zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md
...n-dev/reference/arkui-ts/ts-universal-events-drag-drop.md
+74
-58
未找到文件。
zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md
浏览文件 @
bf96431e
# 拖拽事件
拖拽事件指被长按后拖拽时触发的事件。
拖拽事件指
组件
被长按后拖拽时触发的事件。
> **说明:**
>
...
...
@@ -10,18 +10,18 @@
| 名称 | 支持冒泡 | 功能描述 |
| ---------------------------------------- | ---- | ---------------------------------------- |
| onDragStart(event:
(event?:
DragEvent,
extraParams?:
string)
=
>
[
CustomBuilder
](
ts-types.md#custombuilder8
)
\|
DragItemInfo) | 否 | 第一次拖拽此事件绑定的组件时,触发回调。
<br/>
- event:拖拽事件信息,包括拖拽点坐标。
<br/>
- extraParams:拖拽事件额外信息,详见extraParam类型描述
。
<br/>
返回值:当前跟手效果所拖拽的对象,用于显示拖拽时的提示组件。
<br/>
长按150毫秒(ms)可触发拖拽事件。优先级:长按手势配置时间小于等于150毫秒(ms)时,长按手势优先触发,否则拖拽事件优先触发。 |
| onDragEnter(event:
(event?:
DragEvent,
extraParams?:
string)
=
>
void) | 否 | 拖拽进入组件范围内时,触发回调。
<br/>
- event:拖拽事件信息,包括拖拽点坐标。
<br/>
- extraParams:拖拽事件额外信息,详见extraParam类型描述
。
<br/>
当监听了onDrop事件时,此事件才有效。 |
| onDragMove(event:
(event?:
DragEvent,
extraParams?:
string)
=
>
void) | 否 | 拖拽在组件范围内移动时,触发回调。
<br/>
- event:拖拽事件信息,包括拖拽点坐标。
<br/>
- extraParams:拖拽事件额外信息,详见extraParam类型描述
。
<br/>
当监听了onDrop事件时,此事件才有效。 |
| onDragLeave(event:
(event?:
DragEvent,
extraParams?:
string)
=
>
void) | 否 | 拖拽离开组件范围内时,触发回调。
<br/>
- event:拖拽事件信息,包括拖拽点坐标。
<br/>
- extraParams:拖拽事件额外信息,详见extraParam类型描述
。
<br/>
当监听了onDrop事件时,此事件才有效。 |
| onDrop(event:
(event?:
DragEvent,
extraParams?:
string)
=
>
void) | 否 | 绑定此事件的组件可作为拖拽释放目标,当在本组件范围内停止拖拽行为时,触发回调。
<br/>
- event:拖拽事件信息,包括拖拽点坐标。
<br/>
- extraParams:拖拽事件额外信息,详见extraParam类型描述
。 |
| onDragStart(event:
(event?:
[DragEvent](#DragEvent对象说明),
extraParams?:
string)
=
>
[
CustomBuilder
](
ts-types.md#custombuilder8
)
\|
[
DragItemInfo
](
#DragItemInfo说明
)
| 否 | 第一次拖拽此事件绑定的组件时,触发回调。
<br/>
- event:拖拽事件信息,包括拖拽点坐标。
<br/>
- extraParams:拖拽事件额外信息,详见extraParams说明
。
<br/>
返回值:当前跟手效果所拖拽的对象,用于显示拖拽时的提示组件。
<br/>
长按150毫秒(ms)可触发拖拽事件。优先级:长按手势配置时间小于等于150毫秒(ms)时,长按手势优先触发,否则拖拽事件优先触发。 |
| onDragEnter(event:
(event?:
[DragEvent](#DragEvent对象说明),
extraParams?:
string)
=
>
void) | 否 | 拖拽进入组件范围内时,触发回调。
<br/>
- event:拖拽事件信息,包括拖拽点坐标。
<br/>
- extraParams:拖拽事件额外信息,详见extraParams说明
。
<br/>
当监听了onDrop事件时,此事件才有效。 |
| onDragMove(event:
(event?:
[DragEvent](#DragEvent对象说明),
extraParams?:
string)
=
>
void) | 否 | 拖拽在组件范围内移动时,触发回调。
<br/>
- event:拖拽事件信息,包括拖拽点坐标。
<br/>
- extraParams:拖拽事件额外信息,详见extraParams说明
。
<br/>
当监听了onDrop事件时,此事件才有效。 |
| onDragLeave(event:
(event?:
[DragEvent](#DragEvent对象说明),
extraParams?:
string)
=
>
void) | 否 | 拖拽离开组件范围内时,触发回调。
<br/>
- event:拖拽事件信息,包括拖拽点坐标。
<br/>
- extraParams:拖拽事件额外信息,详见extraParams说明
。
<br/>
当监听了onDrop事件时,此事件才有效。 |
| onDrop(event:
(event?:
[DragEvent](#DragEvent对象说明),
extraParams?:
string)
=
>
void) | 否 | 绑定此事件的组件可作为拖拽释放目标,当在本组件范围内停止拖拽行为时,触发回调。
<br/>
- event:拖拽事件信息,包括拖拽点坐标。
<br/>
- extraParams:拖拽事件额外信息,详见extraParams说明
。 |
## DragItemInfo说明
|
属性名称 | 属性
类型 | 必填 | 描述 |
|
名称 |
类型 | 必填 | 描述 |
| --------- | ---------------------------------------- | ---- | --------------------------------- |
| pixelMap |
[
PixelMap
](
../apis/js-apis-image.md#pixelmap7
)
| 否 | 设置拖拽过程中显示的图片。 |
| builder |
[
CustomBuilder
](
ts-types.md#custombuilder8
)
| 否 |
使用自定义生成器进行绘图
,如果设置了pixelMap,则忽略此值。 |
| builder |
[
CustomBuilder
](
ts-types.md#custombuilder8
)
| 否 |
拖拽过程中显示自定义组件
,如果设置了pixelMap,则忽略此值。 |
| extraInfo | string | 否 | 拖拽项的描述。 |
...
...
@@ -31,9 +31,9 @@
extraParam是Json对象转换的string字符串,可以通过Json.parse转换的Json对象获取如下属性。
|
属性名称 | 属性
类型 | 描述 |
|
名称 |
类型 | 描述 |
| ------------- | ------ | ---------------------------------------- |
| selectedIndex | number | 当拖拽事件设在父容器的子元素时,selectedIndex表示当前被拖拽子元素是父容器第selectedIndex个子元素,selectedIndex从0开始。
<br/>
仅在ListItem组件中生效。 |
| selectedIndex | number | 当拖拽事件设在父容器的子元素时,selectedIndex表示当前被拖拽子元素是父容器第selectedIndex个子元素,selectedIndex从0开始。
<br/>
仅在ListItem组件
的拖拽事件
中生效。 |
| insertIndex | number | 当前拖拽元素在List组件中放下时,insertIndex表示被拖拽元素插入该组件的第insertIndex个位置,insertIndex从0开始。
<br/>
仅在List组件的拖拽事件中生效。 |
## DragEvent对象说明
...
...
@@ -50,81 +50,101 @@
@
Entry
@
Component
struct
DragExample
{
@
State
numbers
:
string
[]
=
[
'
one
'
,
'
two
'
,
'
three
'
,
'
four
'
,
'
five
'
,
'
six
'
]
@
State
text
:
string
=
''
@
State
bool
:
boolean
=
false
@
State
bool1
:
boolean
=
false
@
State
appleVisible
:
Visibility
=
Visibility
.
Visible
@
State
orangeVisible
:
Visibility
=
Visibility
.
Visible
@
State
bananaVisible
:
Visibility
=
Visibility
.
Visible
@
State
select
:
number
=
0
@
State
numbers
:
string
[]
=
[
'
one
'
,
'
two
'
,
'
three
'
,
'
four
'
,
'
five
'
,
'
six
'
];
@
State
text
:
string
=
''
;
@
State
bool
:
boolean
=
false
;
@
State
appleVisible
:
Visibility
=
Visibility
.
Visible
;
@
State
orangeVisible
:
Visibility
=
Visibility
.
Visible
;
@
State
bananaVisible
:
Visibility
=
Visibility
.
Visible
;
// 自定义拖拽过程中显示的内容
@
Builder
pixelMapBuilder
()
{
Column
()
{
Text
(
this
.
text
)
.
width
(
'
50%
'
).
height
(
60
).
fontSize
(
16
).
borderRadius
(
10
)
.
textAlign
(
TextAlign
.
Center
).
backgroundColor
(
Color
.
Yellow
)
.
width
(
'
50%
'
)
.
height
(
60
)
.
fontSize
(
16
)
.
borderRadius
(
10
)
.
textAlign
(
TextAlign
.
Center
)
.
backgroundColor
(
Color
.
Yellow
)
}
}
build
()
{
Column
()
{
Text
(
'
There are three Text elements here
'
)
.
fontSize
(
12
).
fontColor
(
0xCCCCCC
).
width
(
'
90%
'
)
.
textAlign
(
TextAlign
.
Start
).
margin
(
5
)
Flex
({
direction
:
FlexDirection
.
Row
,
alignItems
:
ItemAlign
.
Center
,
justifyContent
:
FlexAlign
.
SpaceAround
})
{
Text
(
'
apple
'
).
width
(
'
25%
'
).
height
(
35
).
fontSize
(
16
)
.
textAlign
(
TextAlign
.
Center
).
backgroundColor
(
0xAFEEEE
)
.
fontSize
(
12
)
.
fontColor
(
0xCCCCCC
)
.
width
(
'
90%
'
)
.
textAlign
(
TextAlign
.
Start
)
.
margin
(
5
)
Row
({
space
:
15
})
{
Text
(
'
apple
'
)
.
width
(
'
25%
'
)
.
height
(
35
)
.
fontSize
(
16
)
.
textAlign
(
TextAlign
.
Center
)
.
backgroundColor
(
0xAFEEEE
)
.
visibility
(
this
.
appleVisible
)
.
onDragStart
(()
=>
{
this
.
bool
=
true
this
.
text
=
'
apple
'
this
.
appleVisible
=
Visibility
.
Hidden
this
.
appleVisible
=
Visibility
.
None
return
this
.
pixelMapBuilder
})
Text
(
'
orange
'
).
width
(
'
25%
'
).
height
(
35
).
fontSize
(
16
)
.
textAlign
(
TextAlign
.
Center
).
backgroundColor
(
0xAFEEEE
)
Text
(
'
orange
'
)
.
width
(
'
25%
'
)
.
height
(
35
)
.
fontSize
(
16
)
.
textAlign
(
TextAlign
.
Center
)
.
backgroundColor
(
0xAFEEEE
)
.
visibility
(
this
.
orangeVisible
)
.
onDragStart
(()
=>
{
this
.
bool
=
true
this
.
text
=
'
orange
'
this
.
orangeVisible
=
Visibility
.
Hidden
this
.
orangeVisible
=
Visibility
.
None
return
this
.
pixelMapBuilder
})
Text
(
'
banana
'
).
width
(
'
25%
'
).
height
(
35
).
fontSize
(
16
)
.
textAlign
(
TextAlign
.
Center
).
backgroundColor
(
0xAFEEEE
)
Text
(
'
banana
'
)
.
width
(
'
25%
'
)
.
height
(
35
)
.
fontSize
(
16
)
.
textAlign
(
TextAlign
.
Center
)
.
backgroundColor
(
0xAFEEEE
)
.
visibility
(
this
.
bananaVisible
)
.
onDragStart
((
event
:
DragEvent
,
extraParams
:
string
)
=>
{
console
.
log
(
'
Text onDragStarts,
'
+
extraParams
)
this
.
bool
=
true
this
.
text
=
'
banana
'
this
.
bananaVisible
=
Visibility
.
Hidden
this
.
bananaVisible
=
Visibility
.
None
return
this
.
pixelMapBuilder
})
}.
border
({
width
:
1
}).
width
(
'
90%
'
).
padding
({
top
:
10
,
bottom
:
10
}).
margin
(
10
)
Text
(
'
This is a List element
'
).
fontSize
(
12
)
.
fontColor
(
0xCCCCCC
).
width
(
'
90%
'
)
.
textAlign
(
TextAlign
.
Start
).
margin
(
15
)
List
({
space
:
20
,
initialIndex
:
0
})
{
}.
padding
({
top
:
10
,
bottom
:
10
}).
margin
(
10
)
Text
(
'
This is a List element
'
)
.
fontSize
(
12
)
.
fontColor
(
0xCCCCCC
)
.
width
(
'
90%
'
)
.
textAlign
(
TextAlign
.
Start
)
.
margin
(
15
)
List
({
space
:
20
})
{
ForEach
(
this
.
numbers
,
(
item
)
=>
{
ListItem
()
{
Text
(
''
+
item
)
.
width
(
'
100%
'
).
height
(
80
).
fontSize
(
16
).
borderRadius
(
10
)
.
textAlign
(
TextAlign
.
Center
).
backgroundColor
(
0xAFEEEE
)
Text
(
item
)
.
width
(
'
100%
'
)
.
height
(
80
)
.
fontSize
(
16
)
.
borderRadius
(
10
)
.
textAlign
(
TextAlign
.
Center
)
.
backgroundColor
(
0xAFEEEE
)
}
.
onDragStart
((
event
:
DragEvent
,
extraParams
:
string
)
=>
{
console
.
log
(
'
ListItem onDragStarts,
'
+
extraParams
)
var
jsonString
=
JSON
.
parse
(
extraParams
)
this
.
bool1
=
true
this
.
text
=
this
.
numbers
[
jsonString
.
selectedIndex
]
this
.
select
=
jsonString
.
selectedIndex
return
this
.
pixelMapBuilder
})
},
item
=>
item
)
}
.
editMode
(
true
)
.
height
(
'
50%
'
).
width
(
'
90%
'
).
border
({
width
:
1
})
.
height
(
'
50%
'
)
.
width
(
'
90%
'
)
.
border
({
width
:
1
})
.
padding
(
15
)
.
divider
({
strokeWidth
:
2
,
color
:
0xFFFFFF
,
startMargin
:
20
,
endMargin
:
20
})
.
onDragEnter
((
event
:
DragEvent
,
extraParams
:
string
)
=>
{
console
.
log
(
'
List onDragEnter,
'
+
extraParams
)
...
...
@@ -138,13 +158,9 @@ struct DragExample {
.
onDrop
((
event
:
DragEvent
,
extraParams
:
string
)
=>
{
var
jsonString
=
JSON
.
parse
(
extraParams
)
if
(
this
.
bool
)
{
this
.
numbers
.
splice
(
jsonString
.
insertIndex
,
0
,
this
.
text
)
this
.
bool
=
false
}
else
if
(
this
.
bool1
)
{
this
.
numbers
.
splice
(
jsonString
.
selectedIndex
,
1
)
this
.
numbers
.
splice
(
jsonString
.
insertIndex
,
0
,
this
.
text
)
this
.
bool
=
false
this
.
bool1
=
false
// 通过splice方法插入元素
this
.
numbers
.
splice
(
jsonString
.
insertIndex
,
0
,
this
.
text
);
this
.
bool
=
false
;
}
})
}.
width
(
'
100%
'
).
height
(
'
100%
'
).
padding
({
top
:
20
}).
margin
({
top
:
20
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录