From 7cc6ab15a21f76b00008efd7c4d90dffd777d951 Mon Sep 17 00:00:00 2001 From: LiAn Date: Tue, 22 Aug 2023 09:07:12 +0000 Subject: [PATCH] update zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md. Signed-off-by: LiAn Signed-off-by: LiAn --- .../arkui-ts/ts-universal-events-drag-drop.md | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md index 55f9e702f1..f38c48b0de 100644 --- a/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md +++ b/zh-cn/application-dev/reference/arkui-ts/ts-universal-events-drag-drop.md @@ -83,15 +83,14 @@ ArkUI组件默认支持拖拽。 ## 示例 ```ts -import udmf from '@ohos.data.UDMF'; +import UDC from '@ohos.data.unifiedDataChannel'; +import UTD from '@ohos.data.uniformTypeDescriptor'; import promptAction from '@ohos.promptAction'; @Entry @Component struct Index { @State targetImage: string = ''; @State targetText: string = 'Drag Text'; - @State hyperLinkText: string = 'HyperLink'; - @State hyperLinkContent: string = 'HyperLink'; @State imageWidth: number = 100; @State imageHeight: number = 100; @State imgState: Visibility = Visibility.Visible; @@ -105,7 +104,7 @@ struct Index { if (!data) { return false; } - let records: Array = data.getRecords(); + let records: Array = data.getRecords(); if (!records || records.length <= 0) { return false; } @@ -116,7 +115,7 @@ struct Index { getDataFromUdmf(event: DragEvent, callback: (data: DragEvent)=>void) { if(this.getDataFromUdmfRetry(event, callback)) { - return; + return; } setTimeout(()=>{ this.getDataFromUdmfRetry(event, callback); @@ -139,12 +138,12 @@ struct Index { .margin({left: 15}) .visibility(this.imgState) .onDragEnd((event)=>{ - if (event.getResult() === DragResult.DRAG_SUCCESSFUL) { - promptAction.showToast({duration: 100, message: 'Drag Success'}); - } else if (event.getResult() === DragResult.DRAG_FAILED) { - promptAction.showToast({duration: 100, message: 'Drag failed'}); - } - }) + if (event.getResult() === DragResult.DRAG_SUCCESSFUL) { + promptAction.showToast({duration: 100, message: 'Drag Success'}); + } else if (event.getResult() === DragResult.DRAG_FAILED) { + promptAction.showToast({duration: 100, message: 'Drag failed'}); + } + }) Text('test drag event') .width('100%') .height(100) @@ -165,9 +164,9 @@ struct Index { Text('change video source') }.draggable(true) .onDragStart((event)=>{ - let video: udmf.Video = new udmf.Video(); + let video: UDC.Video = new UDC.Video(); 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); }) Column() { @@ -178,10 +177,10 @@ struct Index { .width('100%') .height(100) .onDragStart((event)=>{ - let data: udmf.PlainText = new udmf.PlainText(); + let data: UDC.PlainText = new UDC.PlainText(); data.abstract = 'this is abstract'; data.textContent = 'this is content this is content'; - event.setData(new udmf.UnifiedData(data)); + event.setData(new UDC.UnifiedData(data)); }) }.width('45%') .height('100%') @@ -198,14 +197,14 @@ struct Index { .draggable(true) .margin({left: 15}) .border({color: Color.Black, width: 1}) - .allowDrop([udmf.UnifiedDataType.IMAGE]) + .allowDrop([UTD.UniformDataType.IMAGE]) .onDrop((dragEvent: DragEvent)=> { this.getDataFromUdmf(dragEvent, (event)=>{ - let records: Array = event.getData().getRecords(); + let records: Array = event.getData().getRecords(); let rect: Rectangle = event.getPreviewRect(); this.imageWidth = Number(rect.width); this.imageHeight = Number(rect.height); - this.targetImage = ((records[0])).imageUri; + this.targetImage = ((records[0])).imageUri; event.useCustomDropAnimation = false; animateTo({duration: 1000}, ()=>{ this.imageWidth = 100; @@ -221,11 +220,11 @@ struct Index { .height(100) .border({color: Color.Black, width: 1}) .margin(15) - .allowDrop([udmf.UnifiedDataType.TEXT]) + .allowDrop([UTD.UniformDataType.TEXT]) .onDrop((dragEvent: DragEvent)=>{ this.getDataFromUdmf(dragEvent, event => { - let records:Array = event.getData().getRecords(); - this.targetText = ((records[0])).details['value']; + let records:Array = event.getData().getRecords(); + this.targetText = ((records[0])).details['value']; }) }) @@ -233,17 +232,17 @@ struct Index { .width('100%') .height(200) .controls(true) - .allowDrop([udmf.UnifiedDataType.VIDEO]) + .allowDrop([UTD.UniformDataType.VIDEO]) Column() { Text(this.abstractContent).fontSize(20).width('100%') Text(this.textContent).fontSize(15).width('100%') }.width('100%').height(100).margin(20).border({color: Color.Black, width: 1}) - .allowDrop([udmf.UnifiedDataType.PLAIN_TEXT]) + .allowDrop([UTD.UniformDataType.PLAIN_TEXT]) .onDrop((dragEvent)=>{ this.getDataFromUdmf(dragEvent, event=>{ - let records: Array = event.getData().getRecords(); - let plainText: udmf.PlainText = (records[0]); + let records: Array = event.getData().getRecords(); + let plainText: UDC.PlainText = (records[0]); this.abstractContent = plainText.abstract; this.textContent = plainText.textContent; }) -- GitLab