未验证 提交 7cc6ab15 编写于 作者: L LiAn 提交者: Gitee

update zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md.

Signed-off-by: NLiAn <lian15@huawei.com>
Signed-off-by: NLiAn <lian15@huawei.com>
上级 bfa1564e
...@@ -83,15 +83,14 @@ ArkUI组件默认支持拖拽。 ...@@ -83,15 +83,14 @@ ArkUI组件默认支持拖拽。
## 示例 ## 示例
```ts ```ts
import udmf from '@ohos.data.UDMF'; import UDC from '@ohos.data.unifiedDataChannel';
import UTD from '@ohos.data.uniformTypeDescriptor';
import promptAction from '@ohos.promptAction'; import promptAction from '@ohos.promptAction';
@Entry @Entry
@Component @Component
struct Index { struct Index {
@State targetImage: string = ''; @State targetImage: string = '';
@State targetText: string = 'Drag Text'; @State targetText: string = 'Drag Text';
@State hyperLinkText: string = 'HyperLink';
@State hyperLinkContent: string = 'HyperLink';
@State imageWidth: number = 100; @State imageWidth: number = 100;
@State imageHeight: number = 100; @State imageHeight: number = 100;
@State imgState: Visibility = Visibility.Visible; @State imgState: Visibility = Visibility.Visible;
...@@ -105,7 +104,7 @@ struct Index { ...@@ -105,7 +104,7 @@ struct Index {
if (!data) { if (!data) {
return false; return false;
} }
let records: Array<udmf.UnifiedRecord> = data.getRecords(); let records: Array<UDC.UnifiedRecord> = data.getRecords();
if (!records || records.length <= 0) { if (!records || records.length <= 0) {
return false; return false;
} }
...@@ -116,7 +115,7 @@ struct Index { ...@@ -116,7 +115,7 @@ struct Index {
getDataFromUdmf(event: DragEvent, callback: (data: DragEvent)=>void) getDataFromUdmf(event: DragEvent, callback: (data: DragEvent)=>void)
{ {
if(this.getDataFromUdmfRetry(event, callback)) { if(this.getDataFromUdmfRetry(event, callback)) {
return; return;
} }
setTimeout(()=>{ setTimeout(()=>{
this.getDataFromUdmfRetry(event, callback); this.getDataFromUdmfRetry(event, callback);
...@@ -139,12 +138,12 @@ struct Index { ...@@ -139,12 +138,12 @@ struct Index {
.margin({left: 15}) .margin({left: 15})
.visibility(this.imgState) .visibility(this.imgState)
.onDragEnd((event)=>{ .onDragEnd((event)=>{
if (event.getResult() === DragResult.DRAG_SUCCESSFUL) { if (event.getResult() === DragResult.DRAG_SUCCESSFUL) {
promptAction.showToast({duration: 100, message: 'Drag Success'}); promptAction.showToast({duration: 100, message: 'Drag Success'});
} else if (event.getResult() === DragResult.DRAG_FAILED) { } else if (event.getResult() === DragResult.DRAG_FAILED) {
promptAction.showToast({duration: 100, message: 'Drag failed'}); promptAction.showToast({duration: 100, message: 'Drag failed'});
} }
}) })
Text('test drag event') Text('test drag event')
.width('100%') .width('100%')
.height(100) .height(100)
...@@ -165,9 +164,9 @@ struct Index { ...@@ -165,9 +164,9 @@ struct Index {
Text('change video source') Text('change video source')
}.draggable(true) }.draggable(true)
.onDragStart((event)=>{ .onDragStart((event)=>{
let video: udmf.Video = new udmf.Video(); let video: UDC.Video = new UDC.Video();
video.videoUri = 'resource://RAWFILE/01.mp4'; video.videoUri = 'resource://RAWFILE/01.mp4';
let data: udmf.UnifiedData = new udmf.UnifiedData(video); let data: UDC.UnifiedData = new UDC.UnifiedData(video);
event.setData(data); event.setData(data);
}) })
Column() { Column() {
...@@ -178,10 +177,10 @@ struct Index { ...@@ -178,10 +177,10 @@ struct Index {
.width('100%') .width('100%')
.height(100) .height(100)
.onDragStart((event)=>{ .onDragStart((event)=>{
let data: udmf.PlainText = new udmf.PlainText(); let data: UDC.PlainText = new UDC.PlainText();
data.abstract = 'this is abstract'; data.abstract = 'this is abstract';
data.textContent = 'this is content this is content'; data.textContent = 'this is content this is content';
event.setData(new udmf.UnifiedData(data)); event.setData(new UDC.UnifiedData(data));
}) })
}.width('45%') }.width('45%')
.height('100%') .height('100%')
...@@ -198,14 +197,14 @@ struct Index { ...@@ -198,14 +197,14 @@ struct Index {
.draggable(true) .draggable(true)
.margin({left: 15}) .margin({left: 15})
.border({color: Color.Black, width: 1}) .border({color: Color.Black, width: 1})
.allowDrop([udmf.UnifiedDataType.IMAGE]) .allowDrop([UTD.UniformDataType.IMAGE])
.onDrop((dragEvent: DragEvent)=> { .onDrop((dragEvent: DragEvent)=> {
this.getDataFromUdmf(dragEvent, (event)=>{ this.getDataFromUdmf(dragEvent, (event)=>{
let records: Array<udmf.UnifiedRecord> = event.getData().getRecords(); let records: Array<UDC.UnifiedRecord> = event.getData().getRecords();
let rect: Rectangle = event.getPreviewRect(); let rect: Rectangle = event.getPreviewRect();
this.imageWidth = Number(rect.width); this.imageWidth = Number(rect.width);
this.imageHeight = Number(rect.height); this.imageHeight = Number(rect.height);
this.targetImage = (<udmf.Image>(records[0])).imageUri; this.targetImage = (<UDC.Image>(records[0])).imageUri;
event.useCustomDropAnimation = false; event.useCustomDropAnimation = false;
animateTo({duration: 1000}, ()=>{ animateTo({duration: 1000}, ()=>{
this.imageWidth = 100; this.imageWidth = 100;
...@@ -221,11 +220,11 @@ struct Index { ...@@ -221,11 +220,11 @@ struct Index {
.height(100) .height(100)
.border({color: Color.Black, width: 1}) .border({color: Color.Black, width: 1})
.margin(15) .margin(15)
.allowDrop([udmf.UnifiedDataType.TEXT]) .allowDrop([UTD.UniformDataType.TEXT])
.onDrop((dragEvent: DragEvent)=>{ .onDrop((dragEvent: DragEvent)=>{
this.getDataFromUdmf(dragEvent, event => { this.getDataFromUdmf(dragEvent, event => {
let records:Array<udmf.UnifiedRecord> = event.getData().getRecords(); let records:Array<UDC.UnifiedRecord> = event.getData().getRecords();
this.targetText = (<udmf.Text>(records[0])).details['value']; this.targetText = (<UDC.Text>(records[0])).details['value'];
}) })
}) })
...@@ -233,17 +232,17 @@ struct Index { ...@@ -233,17 +232,17 @@ struct Index {
.width('100%') .width('100%')
.height(200) .height(200)
.controls(true) .controls(true)
.allowDrop([udmf.UnifiedDataType.VIDEO]) .allowDrop([UTD.UniformDataType.VIDEO])
Column() { Column() {
Text(this.abstractContent).fontSize(20).width('100%') Text(this.abstractContent).fontSize(20).width('100%')
Text(this.textContent).fontSize(15).width('100%') Text(this.textContent).fontSize(15).width('100%')
}.width('100%').height(100).margin(20).border({color: Color.Black, width: 1}) }.width('100%').height(100).margin(20).border({color: Color.Black, width: 1})
.allowDrop([udmf.UnifiedDataType.PLAIN_TEXT]) .allowDrop([UTD.UniformDataType.PLAIN_TEXT])
.onDrop((dragEvent)=>{ .onDrop((dragEvent)=>{
this.getDataFromUdmf(dragEvent, event=>{ this.getDataFromUdmf(dragEvent, event=>{
let records: Array<udmf.UnifiedRecord> = event.getData().getRecords(); let records: Array<UDC.UnifiedRecord> = event.getData().getRecords();
let plainText: udmf.PlainText = <udmf.PlainText>(records[0]); let plainText: UDC.PlainText = <UDC.PlainText>(records[0]);
this.abstractContent = plainText.abstract; this.abstractContent = plainText.abstract;
this.textContent = plainText.textContent; this.textContent = plainText.textContent;
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册