1# @ohos.arkui.dragController (DragController) 2 3The **dragController** module provides APIs for initiating drag actions. When receiving a gesture event, such as a touch or long-press event, an application can initiate a drag action and carry drag information therein. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> The functionality of this module depends on UI context. This means that the APIs of this module cannot be used where the UI context is unclear. For details, see [UIContext](js-apis-arkui-UIContext.md#uicontext). 9> Since API version 10, you can use the [getDragController](js-apis-arkui-UIContext.md#getdragcontroller11) API in **UIContext** to obtain the **DragController** object associated with the current UI context. 10> You can preview how this component looks on a real device, but not in DevEco Studio Previewer. 11 12## Modules to Import 13 14```ts 15import dragController from "@ohos.arkui.dragController"; 16``` 17 18## dragController.executeDrag 19 20executeDrag(custom: CustomBuilder | DragItemInfo, dragInfo: DragInfo, callback: AsyncCallback< {event: DragEvent, extraParams: string}>): void 21 22Initiates a drag action, with the object to be dragged and the drag information passed in. This API uses an asynchronous callback to return the result. 23 24**System capability**: SystemCapability.ArkUI.ArkUI.Full 25 26**Parameters** 27 28| Name | Type | Mandatory| Description | 29| -------- | ------------------------------------------------------------ | ---- | -------------------------------- | 30| custom | [CustomBuilder](arkui-ts/ts-types.md#custombuilder8) \| [DragItemInfo](arkui-ts/ts-universal-events-drag-drop.md#dragiteminfo) | Yes | Object to be dragged.<br>**NOTE**<br>The global builder is not supported. If the [\<Image>](arkui-ts/ts-basic-components-image.md) component is used in the builder, enable synchronous loading, that is, set the [syncLoad](arkui-ts/ts-basic-components-image.md#attributes) attribute of the component to **true**. The builder is used only to generate the image displayed during the current dragging. Changes to the builder, if any, apply to the next dragging, but not to the current dragging.| 31| dragInfo | [DragInfo](#draginfo) | Yes | Drag information. | 32| callback | [AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)<{event: [DragEvent](arkui-ts/ts-universal-events-drag-drop.md#dragevent), extraParams: string}> | Yes | Callback used to return the result.<br>- **event**: drag event information that includes only the drag result.<br>- **extraParams**: extra information about the drag event. | 33 34**Error codes** 35 36| ID| Error Message | 37| -------- | ------------- | 38| 401 | if the parameters checking failed. | 39| 100001 | if some internal handling failed. | 40 41**Example** 42 43```ts 44import dragController from "@ohos.arkui.dragController" 45import UDC from '@ohos.data.unifiedDataChannel'; 46 47@Entry 48@Component 49struct DragControllerPage { 50 @Builder DraggingBuilder() { 51 Column() { 52 Text("DraggingBuilder") 53 } 54 .width(100) 55 .height(100) 56 .backgroundColor(Color.Blue) 57 } 58 59 build() { 60 Column() { 61 Button('touch to execute drag') 62 .onTouch((event?:TouchEvent) => { 63 if(event){ 64 if (event.type == TouchType.Down) { 65 let text = new UDC.Text() 66 let unifiedData = new UDC.UnifiedData(text) 67 68 let dragInfo: dragController.DragInfo = { 69 pointerId: 0, 70 data: unifiedData, 71 extraParams: '' 72 } 73 class tmp{ 74 event:DragEvent|undefined = undefined 75 extraParams:string = '' 76 } 77 let eve:tmp = new tmp() 78 dragController.executeDrag(()=>{this.DraggingBuilder()}, dragInfo, (err, eve) => { 79 if(eve.event){ 80 if (eve.event.getResult() == DragResult.DRAG_SUCCESSFUL) { 81 // ... 82 } else if (eve.event.getResult() == DragResult.DRAG_FAILED) { 83 // ... 84 } 85 } 86 }) 87 } 88 } 89 }) 90 } 91 } 92} 93``` 94 95## dragController.executeDrag 96 97executeDrag(custom: CustomBuilder | DragItemInfo, dragInfo: DragInfo): Promise<{event: DragEvent, extraParams: string}> 98 99Initiates a drag action, with the object to be dragged and the drag information passed in. This API uses a promise to return the result. 100 101**System capability**: SystemCapability.ArkUI.ArkUI.Full 102 103**Parameters** 104 105| Name | Type | Mandatory| Description | 106| -------- | ------------------------------------------------------------ | ---- | -------------------------------- | 107| custom | [CustomBuilder](arkui-ts/ts-types.md#custombuilder8) \| [DragItemInfo](arkui-ts/ts-universal-events-drag-drop.md#dragiteminfo) | Yes | Object to be dragged.| 108| dragInfo | [DragInfo](#draginfo) | Yes | Drag information. | 109 110**Return value** 111 112| Type | Description | 113| ------------------------------------------------------ | ------------------ | 114| Promise<{event: [DragEvent](arkui-ts/ts-universal-events-drag-drop.md#dragevent), extraParams: string}> | Promise used to return the result.<br>- **event**: drag event information that includes only the drag result.<br>- **extraParams**: extra information about the drag event.| 115 116**Error codes** 117 118| ID| Error Message | 119| -------- | ------------- | 120| 401 | if the parameters checking failed. | 121| 100001 | if some internal handling failed. | 122 123**Example** 124 125```ts 126import dragController from "@ohos.arkui.dragController" 127import componentSnapshot from '@ohos.arkui.componentSnapshot'; 128import image from '@ohos.multimedia.image'; 129import UDC from '@ohos.data.unifiedDataChannel'; 130 131@Entry 132@Component 133struct DragControllerPage { 134 @State pixmap: image.PixelMap|null = null 135 136 @Builder DraggingBuilder() { 137 Column() { 138 Text("DraggingBuilder") 139 } 140 .width(100) 141 .height(100) 142 .backgroundColor(Color.Blue) 143 } 144 145 @Builder PixmapBuilder() { 146 Column() { 147 Text("PixmapBuilder") 148 } 149 .width(100) 150 .height(100) 151 .backgroundColor(Color.Blue) 152 } 153 154 build() { 155 Column() { 156 Button('touch to execute drag') 157 .onTouch((event?:TouchEvent) => { 158 if(event){ 159 if (event.type == TouchType.Down) { 160 let text = new UDC.Text() 161 let unifiedData = new UDC.UnifiedData(text) 162 163 let dragInfo: dragController.DragInfo = { 164 pointerId: 0, 165 data: unifiedData, 166 extraParams: '' 167 } 168 let pb:CustomBuilder = ():void=>{this.PixmapBuilder()} 169 componentSnapshot.createFromBuilder(pb).then((pix: image.PixelMap) => { 170 this.pixmap = pix; 171 let dragItemInfo: DragItemInfo = { 172 pixelMap: this.pixmap, 173 builder: ()=>{this.DraggingBuilder()}, 174 extraInfo: "DragItemInfoTest" 175 } 176 177 class tmp{ 178 event:DragResult|undefined = undefined 179 extraParams:string = '' 180 } 181 let eve:tmp = new tmp() 182 dragController.executeDrag(dragItemInfo, dragInfo) 183 .then((eve) => { 184 if (eve.event.getResult() == DragResult.DRAG_SUCCESSFUL) { 185 // ... 186 } else if (eve.event.getResult() == DragResult.DRAG_FAILED) { 187 // ... 188 } 189 }) 190 .catch((err:Error) => { 191 }) 192 }) 193 } 194 } 195 }) 196 } 197 .width('100%') 198 .height('100%') 199 } 200} 201``` 202 203## DragInfo 204 205**System capability**: SystemCapability.ArkUI.ArkUI.Full 206 207Defines the attributes required for initiating a drag action and information carried in the dragging process. 208 209| Name | Type | Mandatory| Description | 210| ----------- | ------------------------------------------------------ | ---- | ---------------------------------------- | 211| pointerId | number | Yes | ID of the touch point on the screen when dragging is started. | 212| data | [unifiedDataChannel.UnifiedData](../apis-arkdata/js-apis-data-unifiedDataChannel.md#unifieddata) | No | Data carried in the dragging process. | 213| extraParams | string | No | Additional information about the drag action. Not supported currently.| 214| touchPoint<sup>11+</sup> | [TouchPoint](arkui-ts/ts-types.md#touchpoint11) | No | Coordinates of the touch point. If this parameter is not set, the touch point is centered. | 215| previewOptions<sup>11+</sup>| [DragPreviewOptions](arkui-ts/ts-universal-attributes-drag-drop.md#dragpreviewoptions11) | No | Custom configuration of the drag preview.| 216 217## DragStatus<sup>11+</sup> 218 219**System capability**: SystemCapability.ArkUI.ArkUI.Full 220 221Describes the dragging start and end states. 222 223| Name | Value | Description | 224| ----------- | ------------------------------------------------------| ---------------------------------------- | 225| STARTED | 0 | Dragging is started. | 226| ENDED | 1 | Dragging ends. | 227 228## DragAndDropInfo<sup>11+</sup> 229 230**System capability**: SystemCapability.ArkUI.ArkUI.Full 231 232Provides the data reported when the state changes during dragging. 233 234| Name | Type | Mandatory| Description | 235| ----------- | ------------------------------------------------------ | ---- | ---------------------------------------- | 236| status | [DragStatus](#dragstatus11) | Yes | Current dragging state (started or ended). | 237| event | [DragEvent](arkui-ts/ts-universal-events-drag-drop.md#dragevent) | No | Drag event corresponding to the current state. | 238| extraParams| string | No | Additional information about the drag action. Not supported currently.| 239 240## DragAction<sup>11+</sup> 241 242Implements a **DragAction** object to subscribe to drag state changes and start the drag service. 243 244**System capability**: SystemCapability.ArkUI.ArkUI.Full 245 246### startDrag<sup>11+</sup> 247 248startDrag(): Promise<void> 249 250Starts the drag service. This API uses a promise to return the result. 251 252**System capability**: SystemCapability.ArkUI.ArkUI.Full 253 254**Error codes** 255 256| ID| Error Message | 257| -------- | ------------- | 258| 100001 | if some internal handling failed. | 259 260**Example** 261```ts 262import dragController from "@ohos.arkui.dragController" 263import UDC from '@ohos.data.unifiedDataChannel'; 264let customBuilders:Array<CustomBuilder | DragItemInfo> = new Array<CustomBuilder | DragItemInfo>(); 265let text = new UDC.Text() 266let unifiedData = new UDC.UnifiedData(text) 267let dragInfo: dragController.DragInfo = { 268 pointerId: 0, 269 data: unifiedData, 270 extraParams: '' 271} 272try{ 273 let dragAction: dragController.DragAction | null = dragController.createDragAction(customBuilders, dragInfo); 274 if(!dragAction){ 275 console.log("listener dragAction is null"); 276 return 277 } 278 dragAction.startDrag().then(()=>{}).catch((err:Error)=>{ 279 console.log("start drag Error:" + err.message); 280 }) 281}catch(err) { 282 console.log("create dragAction Error:" + err.message); 283} 284 285``` 286 287### on('statusChange')<sup>11+</sup> 288 289on(type: 'statusChange', callback: Callback<[DragAndDropInfo](#draganddropinfo11)>): void 290 291Subscribes to drag state changes. 292 293**System capability**: SystemCapability.ArkUI.ArkUI.Full 294 295**Parameters** 296| Name | Type | Mandatory | Description | 297| ------ | ------ | ------- | ---------------- | 298| type | string | Yes | Event type. The value is fixed at **'statusChange'**, which indicates the drag state change event.| 299| callback | Callback<[DragAndDropInfo](#draganddropinfo11)> | Yes | Callback used to return a [DragAndDropInfo](#draganddropinfo11) instance.| 300 301**Example** 302```ts 303import dragController from "@ohos.arkui.dragController" 304import UDC from '@ohos.data.unifiedDataChannel'; 305let customBuilders:Array<CustomBuilder | DragItemInfo> = new Array<CustomBuilder | DragItemInfo>(); 306let text = new UDC.Text() 307let unifiedData = new UDC.UnifiedData(text) 308let dragInfo: dragController.DragInfo = { 309 pointerId: 0, 310 data: unifiedData, 311 extraParams: '' 312} 313try{ 314 let dragAction: dragController.DragAction | null = dragController.createDragAction(customBuilders, dragInfo); 315 if(!dragAction){ 316 console.log("listener dragAction is null"); 317 return 318 } 319 dragAction.on('statusChange', (dragAndDropInfo: dragController.DragAndDropInfo)=>{ 320 console.info("Register to listen on drag status", JSON.stringify(dragAndDropInfo)); 321 }) 322}catch(err) { 323 console.log("create dragAction Error:" + err.message); 324} 325``` 326 327### off('statusChange')<sup>11+</sup> 328 329 off(type: 'statusChange', callback?: Callback<[DragAndDropInfo](#draganddropinfo11)>): void 330 331Unsubscribes from drag state changes. 332 333**System capability**: SystemCapability.ArkUI.ArkUI.Full 334 335**Parameters** 336| Name | Type | Mandatory | Description | 337| ------ | ------ | ------- | ---------------- | 338| type | string | Yes | Event type. The value is fixed at **'statusChange'**, which indicates the drag state change event.| 339| callback | Callback<[DragAndDropInfo](#draganddropinfo11)> | No | Callback used to return a [DragAndDropInfo](#draganddropinfo11) instance. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.| 340 341**Example** 342```ts 343import dragController from "@ohos.arkui.dragController" 344import UDC from '@ohos.data.unifiedDataChannel'; 345let customBuilders:Array<CustomBuilder | DragItemInfo> = new Array<CustomBuilder | DragItemInfo>(); 346let text = new UDC.Text() 347let unifiedData = new UDC.UnifiedData(text) 348let dragInfo: dragController.DragInfo = { 349 pointerId: 0, 350 data: unifiedData, 351 extraParams: '' 352} 353try{ 354 let dragAction: dragController.DragAction | null = dragController.createDragAction(customBuilders, dragInfo); 355 if(!dragAction){ 356 console.log("listener dragAction is null"); 357 return 358 } 359 dragAction.off('statusChange', (dragAndDropInfo: dragController.DragAndDropInfo)=>{ 360 console.info("Cancel listening on drag status", JSON.stringify(dragAndDropInfo)); 361 }) 362}catch(err) { 363 console.log("create dragAction Error:" + err.message); 364} 365``` 366 367## dragController.createDragAction<sup>11+</sup> 368 369createDragAction(customArray: Array<CustomBuilder \| DragItemInfo>, dragInfo: DragInfo): DragAction 370 371Creates a **DragAction** object, by explicitly specifying one or more drag previews, drag data, and information about the dragged object. If the drag initiated by a **DragAction** object is not complete, no new **DragAction** object can be created, and calling this API will throw an exception. 372 373**NOTE**<br>You are advised to control the number of drag previews. If too many previews are passed in, the drag efficiency may be affected. 374 375**System capability**: SystemCapability.ArkUI.ArkUI.Full 376 377**Parameters** 378 379| Name | Type | Mandatory| Description | 380| -------- | ------------------------------------------------------------ | ---- | -------------------------------- | 381| customArray | Array<[CustomBuilder](arkui-ts/ts-types.md#custombuilder8) \| [DragItemInfo](arkui-ts/ts-universal-events-drag-drop.md#dragiteminfo)> | Yes | Object to be dragged.| 382| dragInfo | [DragInfo](#draginfo) | Yes | Drag information. | 383 384**Return value** 385 386| Type | Description | 387| ------------------------------------------------------ | ------------------ | 388| [DragAction](#dragaction11)| **DragAction** object, which is used to subscribe to drag state changes and start the drag service.| 389 390**Error codes** 391 392| ID| Error Message | 393| -------- | ------------- | 394| 401 | Invalid input parameter | 395| 100001 | If some internal handling failed | 396 397**Example** 398 399```ts 400import dragController from "@ohos.arkui.dragController" 401import componentSnapshot from '@ohos.arkui.componentSnapshot'; 402import image from '@ohos.multimedia.image'; 403import UDC from '@ohos.data.unifiedDataChannel'; 404 405@Entry 406@Component 407struct DragControllerPage { 408 @State pixmap: image.PixelMap | null = null 409 private dragAction: dragController.DragAction | null = null; 410 customBuilders:Array<CustomBuilder | DragItemInfo> = new Array<CustomBuilder | DragItemInfo>(); 411 @Builder DraggingBuilder() { 412 Column() { 413 Text("DraggingBuilder") 414 } 415 .width(100) 416 .height(100) 417 .backgroundColor(Color.Blue) 418 } 419 420 build() { 421 Column() { 422 423 Column() { 424 Text ("Test") 425 } 426 .width(100) 427 .height(100) 428 .backgroundColor(Color.Red) 429 430 Button('Drag Multiple Objects').onTouch((event?:TouchEvent) => { 431 if(event){ 432 if (event.type == TouchType.Down) { 433 console.log("muti drag Down by listener"); 434 this.customBuilders.splice(0, this.customBuilders.length); 435 this.customBuilders.push(()=>{this.DraggingBuilder()}); 436 this.customBuilders.push(()=>{this.DraggingBuilder()}); 437 this.customBuilders.push(()=>{this.DraggingBuilder()}); 438 let text = new UDC.Text() 439 let unifiedData = new UDC.UnifiedData(text) 440 let dragInfo: dragController.DragInfo = { 441 pointerId: 0, 442 data: unifiedData, 443 extraParams: '' 444 } 445 try{ 446 this.dragAction = dragController.createDragAction(this.customBuilders, dragInfo) 447 if(!this.dragAction){ 448 console.log("listener dragAction is null"); 449 return 450 } 451 this.dragAction.on('statusChange', (dragAndDropInfo: dragController.DragAndDropInfo)=>{ 452 if (dragAndDropInfo.status == dragController.DragStatus.STARTED) { 453 console.log("drag has start"); 454 } else if (dragAndDropInfo.status == dragController.DragStatus.ENDED){ 455 console.log("drag has end"); 456 if (!this.dragAction) { 457 return 458 } 459 this.dragAction.off('statusChange') 460 } 461 }) 462 this.dragAction.startDrag().then(()=>{}).catch((err:Error)=>{ 463 console.log("start drag Error:" + err.message); 464 }) 465 } catch(err) { 466 console.log("create dragAction Error:" + err.message); 467 } 468 } 469 } 470 }).margin({top:20}) 471 } 472 } 473} 474``` 475## AnimationOptions<sup>11+</sup> 476 477**System capability**: SystemCapability.ArkUI.ArkUI.Full 478 479Defines the attributes required for initiating a drag action and information carried in the dragging process. 480 481| Name | Type | Mandatory| Description | 482| ----------- | ------------------------------------------------------ | ---- | ---------------------------------------- | 483| duration | number | No | Animation duration, in ms.<br>Default value: **1000**<br>**NOTE**<br>- If this parameter is set to a value less than 0, the value **0** is used.<br>- Floating-point values will be rounded down to integers. For example, if the value set is 1.2, **1** will be used.| 484| curve | [Curve](arkui-ts/ts-appendix-enums.md#curve) \| [ICurve](js-apis-curve.md#icurve) | No | Animation curve.<br>Default value: **Curve.EaseInOut**| | 485 486## dragController.getDragPreview<sup>11+</sup> 487 488getDragPreview(): DragPreview 489 490Obtains the **DragPreview** object, which represents the preview displayed during a drag. 491 492**System capability**: SystemCapability.ArkUI.ArkUI.Full 493 494**Return value** 495 496| Type | Description | 497| ------------| ------------------------------------------------| 498| DragPreview | **DragPreview** object. It provides the API for setting the preview style. It does not work in the **OnDrop** and **OnDragEnd** callbacks.| 499 500**Example** 501 502For details, see [animate](#animate11). 503 504## DragPreview<sup>11+</sup> 505 506Implements a **DragPreview** object. This API does not work in the **OnDrop** and **OnDragEnd** callbacks. 507 508**System capability**: SystemCapability.ArkUI.ArkUI.Full 509 510### setForegroundColor<sup>11+</sup> 511 512setForegroundColor(color: ResourceColor): void 513 514Sets the mask color of the drag preview. This API does not work in the **OnDrop** and **OnDragEnd** callbacks. 515 516**System capability**: SystemCapability.ArkUI.ArkUI.Full 517 518**Parameters** 519 520| Name | Type | Mandatory| Description | 521| -------- | -------------------------------- | ---- | ------------------------ | 522| color | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | Yes | Mask color of the drag preview. | 523 524**Example** 525 526For details, see [animate](#animate11). 527 528 ### animate<sup>11+</sup> 529 530animate(options: AnimationOptions, handler: () => void): void 531 532Applies an animation to the background mask color changes. This API does not work in the **OnDrop** and **OnDragEnd** callbacks. 533 534**System capability**: SystemCapability.ArkUI.ArkUI.Full 535 536**Parameters** 537 538| Name | Type | Mandatory| Description | 539| -------- | -------------------------------- | ---- | -----------------------------------| 540| options | [AnimationOptions](#animationoptions11) | Yes | Animation settings. | 541| handler | () => void | Yes | Callback used to change attributes such as the background mask color. | 542 543**Example** 544 5451. In the **EntryAbility.ets** file, obtain the UI context and save it to LocalStorage. 546 ```ts 547import AbilityConstant from '@ohos.app.ability.AbilityConstant'; 548import hilog from '@ohos.hilog'; 549import UIAbility from '@ohos.app.ability.UIAbility'; 550import Want from '@ohos.app.ability.Want'; 551import window from '@ohos.window'; 552import { UIContext } from '@ohos.arkui.UIContext'; 553 554let uiContext: UIContext; 555let localStorage: LocalStorage = new LocalStorage('uiContext'); 556 557export default class EntryAbility extends UIAbility { 558 storage: LocalStorage = localStorage; 559 560 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 561 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); 562 } 563 564 onDestroy(): void { 565 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); 566 } 567 568 onWindowStageCreate(windowStage: window.WindowStage): void { 569 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 570 571 windowStage.loadContent('pages/Index', (err, data) => { 572 if (err.code) { 573 hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); 574 return; 575 } 576 hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); 577 windowStage.getMainWindow((err, data) => { 578 if (err.code) { 579 hilog.error(0x0000, 'Failed to abtain the main window. Cause:' + err.message, ''); 580 return; 581 } 582 let windowClass: window.Window = data; 583 uiContext = windowClass.getUIContext(); 584 this.storage.setOrCreate<UIContext>('uiContext', uiContext); 585 }) 586 }); 587 } 588} 589 ``` 5902. In the **Index.ets** file, call **LocalStorage.getShared()** to obtain the UI context and then use the **DragController** object obtained to perform subsequent operations. 591 ```ts 592 593import UDC from '@ohos.data.unifiedDataChannel'; 594import hilog from '@ohos.hilog'; 595import dragController from "@ohos.arkui.dragController"; 596import image from '@ohos.multimedia.image'; 597import curves from '@ohos.curves'; 598import { BusinessError } from '@ohos.base'; 599import { UIContext } from '@ohos.arkui.UIContext'; 600 601 602let storages = LocalStorage.getShared(); 603 604@Entry(storages) 605@Component 606struct DragControllerPage { 607 @State pixmap: image.PixelMap|null = null 608 609 @Builder DraggingBuilder() { 610 Column() { 611 Text("DraggingBuilder") 612 } 613 .width(100) 614 .height(100) 615 .backgroundColor(Color.Blue) 616 } 617 618 @Builder PixmapBuilder() { 619 Column() { 620 Text("PixmapBuilder") 621 } 622 .width(100) 623 .height(100) 624 .backgroundColor(Color.Blue) 625 } 626 627 build() { 628 Column() { 629 Button('Drag Here').onDragEnter(() => { 630 try { 631 let uiContext: UIContext = storages.get<UIContext>('uiContext') as UIContext; 632 let previewObj: dragController.DragPreview = uiContext.getDragController().getDragPreview(); 633 let foregroundColor: ResourceColor = Color.Green; 634 635 let previewAnimation: dragController.AnimationOptions = { 636 curve: curves.cubicBezierCurve(0.2,0,0,1), 637 } 638 previewObj.animate(previewAnimation, () => { 639 previewObj.setForegroundColor(foregroundColor); 640 }); 641 } catch (error) { 642 let msg = (error as BusinessError).message; 643 let code = (error as BusinessError).code; 644 hilog.error(0x0000, `show error code is ${code}, message is ${msg}`, ''); 645 } 646 }) 647 .onDrop(() => { 648 649 }) 650 Button ('Drag').onTouch ((event?:TouchEvent) => { 651 if(event){ 652 if (event.type == TouchType.Down) { 653 let text = new UDC.Text() 654 let unifiedData = new UDC.UnifiedData(text) 655 let dragInfo: dragController.DragInfo = { 656 pointerId: 0, 657 data: unifiedData, 658 extraParams: '' 659 } 660 class tmp{ 661 event:DragEvent|undefined = undefined 662 extraParams:string = '' 663 } 664 let eve:tmp = new tmp() 665 dragController.executeDrag(() => { 666 this.DraggingBuilder() 667 }, dragInfo, (err , eve) => { 668 hilog.info(0x0000, `ljx ${JSON.stringify(err)}`, '') 669 if (eve && eve.event) { 670 if (eve.event.getResult() == DragResult.DRAG_SUCCESSFUL) { 671 hilog.info(0x0000, 'success', ''); 672 } else if (eve.event.getResult() == DragResult.DRAG_FAILED) { 673 hilog.info(0x0000, 'failed', ''); 674 } 675 } 676 }) 677 } 678 } 679 }).margin({top:100}) 680 } 681 .width('100%') 682 .height('100%') 683 } 684} 685