From c3b22ec78b05d1380eb66ba44a01bb75027fe1d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A1=E5=93=A5?= Date: Sat, 29 Jul 2023 10:05:50 +0000 Subject: [PATCH] update arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DragEvent.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 卡哥 --- .../ets/MainAbility/pages/DragController.ets | 82 +++++++++++++++++++ .../main/ets/MainAbility/pages/DragEvent.ets | 8 +- 2 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DragController.ets diff --git a/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DragController.ets b/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DragController.ets new file mode 100644 index 000000000..85247c93b --- /dev/null +++ b/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DragController.ets @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +import dragController from "@ohos.arkui.dragController" +import UDMF from '@ohos.data.UDMF'; +import componentSnapshot from '@ohos.arkui.componentSnapshot'; +import image from '@ohos.multimedia.image'; + +@Entry +@Component +struct DragController1 { + @State pixmap: image.PixelMap = null + + @Builder DraggingBuilder() { + Column() { + Text("DraggingBuilder") + } + .width(100) + .height(100) + .backgroundColor(Color.Blue) + } + + @Builder PixmapBuilder() { + Column() { + Text("PixmapBuilder") + } + .width(100) + .height(100) + .backgroundColor(Color.Blue) + } + + build() { + Column() { + Button('touch to execute drag') + .onTouch((event) => { + if (event.type == TouchType.Down) { + let text = new UDMF.Text() + let unifiedData = new UDMF.UnifiedData(text) + + let dragInfo: dragController.DragInfo = { + pointerId: 0, + data: unifiedData, + extraParams: '' + } + componentSnapshot.createFromBuilder(this.PixmapBuilder.bind(this)).then((pix: image.PixelMap) => { + this.pixmap = pix; + let dragItemInfo: DragItemInfo = { + pixelMap: this.pixmap, + builder: this.DraggingBuilder.bind(this), + extraInfo: "DragItemInfoTest" + } + dragController.executeDrag(dragItemInfo, dragInfo) + .then(({event, extraParams}) => { + if (event.getResult() == DragRet.DRAG_SUCCESSFUL) { + // ... + } else if (event.getResult() == DragRet.DRAG_FAILED) { + // ... + } + }) + .catch((err) => { + }) + }) + } + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DragEvent.ets b/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DragEvent.ets index 962834cb4..3fbd20881 100644 --- a/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DragEvent.ets +++ b/arkui/ace_ets_component_ui/entry/src/main/ets/MainAbility/pages/DragEvent.ets @@ -57,7 +57,7 @@ struct DragEvent { .visibility(this.imgState) .onDragStart((event)=>{ event.dragBehavior = DragBehavior.COPY - event.setResult(DragRet.DRAG_SUCCESSFUL); + event.setResult(DragResult.DRAG_SUCCESSFUL); }) .onDragEnd((event)=>{ event.dragBehavior = DragBehavior.MOVE @@ -75,7 +75,7 @@ struct DragEvent { promptAction.showToast({duration: 100, message: 'Drag Canceled'}); } else if (event.getResult() === DragResult.DROP_DISABLED) { promptAction.showToast({duration: 100, message: 'Drop Disabled'}); - }else if (event.getResult() === DragRet.DROP_ENABLED) { + }else if (event.getResult() === DragResult.DROP_ENABLED) { promptAction.showToast({duration: 100, message: 'Drop Enabled'}); } this.dragResult = event.getResult().toString() @@ -92,9 +92,9 @@ struct DragEvent { extraParams: '' } dragController.executeDrag(this.DraggingBuilder.bind(this), dragInfo, (err, {event, extraParams}) => { - if (event.getResult() == DragRet.DRAG_SUCCESS) { + if (event.getResult() == DragResult.DRAG_SUCCESSFUL) { // ... - } else if (event.getResult() == DragRet.DRAG_FAILED) { + } else if (event.getResult() == DragResult.DRAG_FAILED) { // ... } }) -- GitLab