1# @ohos.deviceStatus.dragInteraction (Drag Interaction) 2 3 The **dragInteraction** module provides the APIs to enable and disable listening for dragging status changes. 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> 9> - The APIs provided by this module are system APIs. 10 11## Modules to Import 12 13```ts 14import dragInteraction from '@ohos.deviceStatus.dragInteraction' 15``` 16 17## DragState 18 19Enumerates dragging states. 20 21**System capability**: SystemCapability.Msdp.DeviceStatus.Drag 22 23| Name | Value | Description | 24| -------- | ----------------- | ----------------- | 25| MSG_DRAG_STATE_START | 1 | Dragging starts.| 26| MSG_DRAG_STATE_STOP | 2 | Dragging is ended. | 27| MSG_DRAG_STATE_CANCEL | 3 | Dragging is canceled. | 28 29**Example** 30 31```ts 32enum DragState { 33 MSG_DRAG_STATE_START = 1, 34 MSG_DRAG_STATE_STOP = 2, 35 MSG_DRAG_STATE_CANCEL = 3 36} 37``` 38 39## dragInteraction.on('drag') 40 41on(type: 'drag', callback: Callback<DragState>): void; 42 43Enables listening for dragging status changes. 44 45**System capability**: SystemCapability.Msdp.DeviceStatus.Drag 46 47**Parameters** 48 49| Name | Type | Mandatory| Description | 50| -------- | ---------------------------- | ---- | ---------------------------- | 51| type | string | Yes | Event type. This field has a fixed value of **drag**.| 52| callback | Callback<[DragState](#dragstate)> | Yes | Callback used to return the dragging status.| 53 54**Example** 55 56```ts 57try { 58 dragInteraction.on('drag', (data : DragState) => { 59 console.log(`Drag interaction event: ${JSON.stringify(data)}`); 60 }); 61} catch (error) { 62 console.log(`Register failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 63} 64``` 65 66## dragInteraction.off('drag') 67 68off(type: 'drag', callback?: Callback<DragState>): void; 69 70Disables listening for dragging status changes. 71 72**System capability**: SystemCapability.Msdp.DeviceStatus.Drag 73 74**Parameters** 75 76| Name | Type | Mandatory | Description | 77| -------- | ---------------------------- | ---- | ---------------------------- | 78| type | string | Yes | Event type. This field has a fixed value of **drag**.| 79| callback | Callback<[DragState](#dragstate)> | No | Callback to be unregistered. If this parameter is not specified, all callbacks registered by the current application will be unregistered.| 80 81**Example** 82 83```ts 84// Unregister a single callback. 85function single_callback(event : DragState) { 86 console.log(`Drag interaction event: ${JSON.stringify(event)}`); 87 return false; 88} 89try { 90 dragInteraction.on('drag', single_callback); 91 dragInteraction.off("drag", single_callback); 92} catch (error) { 93 console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 94} 95``` 96```ts 97// Unregister all callbacks. 98function all_callback(event : DragState) { 99 console.log(`Drag interaction event: ${JSON.stringify(event)}`); 100 return false; 101} 102try { 103 dragInteraction.on('drag', all_callback); 104 dragInteraction.off("drag"); 105} catch (error) { 106 console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`); 107} 108``` 109