From 2c58a14abaf7c47ab104460078cab1f5d6ab721e Mon Sep 17 00:00:00 2001 From: wang-xupeng2 Date: Mon, 31 Jul 2023 14:25:10 +0800 Subject: [PATCH] fixed 3da14de from https://gitee.com/wang-xupeng2/xts_acts_9/pulls/9620 add DragController testcase Signed-off-by: wang-xupeng2 --- .../ets/MainAbility/pages/DragController.ets | 82 +++++++++++++++++++ .../resources/base/profile/main_pages.json | 3 +- 2 files changed, 84 insertions(+), 1 deletion(-) 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..ea1144a59 --- /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_SUCCESS) { + // ... + } 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/resources/base/profile/main_pages.json b/arkui/ace_ets_component_ui/entry/src/main/resources/base/profile/main_pages.json index eec49f298..07b25278b 100644 --- a/arkui/ace_ets_component_ui/entry/src/main/resources/base/profile/main_pages.json +++ b/arkui/ace_ets_component_ui/entry/src/main/resources/base/profile/main_pages.json @@ -90,6 +90,7 @@ "MainAbility/pages/Xcomponent", "MainAbility/pages/RouteType1", "MainAbility/pages/RouteType2", - "MainAbility/pages/navition3" + "MainAbility/pages/navition3", + "MainAbility/pages/DragController" ] } \ No newline at end of file -- GitLab