1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit ArkUI 19 */ 20 21import { Callback } from './@ohos.base'; 22 23/** 24 * Used to do observer layout and draw event for component. 25 * @syscap SystemCapability.ArkUI.ArkUI.Full 26 * @crossplatform 27 * @since 10 28 */ 29/** 30 * Used to do observer layout and draw event for component. 31 * 32 * @namespace inspector 33 * @syscap SystemCapability.ArkUI.ArkUI.Full 34 * @crossplatform 35 * @atomicservice 36 * @since arkts {'1.1':'12','1.2':'20'} 37 * @arkts 1.1&1.2 38 */ 39declare namespace inspector { 40 41 /** 42 * The ComponentObserver is used to listen for layout and draw events. 43 * @syscap SystemCapability.ArkUI.ArkUI.Full 44 * @crossplatform 45 * @since 10 46 */ 47 /** 48 * The ComponentObserver is used to listen for layout, draw and drawChildren events. 49 * 50 * @interface ComponentObserver 51 * @syscap SystemCapability.ArkUI.ArkUI.Full 52 * @crossplatform 53 * @atomicservice 54 * @since arkts {'1.1':'12','1.2':'20'} 55 * @arkts 1.1&1.2 56 */ 57 interface ComponentObserver { 58 59 /** 60 * Registers a callback with the corresponding query condition by using the handle. 61 * This callback is triggered when the component layout complete. 62 * @param { string } type - type of the listened event. 63 * @param { ()=>void } callback - callback of the listened event. 64 * @syscap SystemCapability.ArkUI.ArkUI.Full 65 * @crossplatform 66 * @since 10 67 */ 68 /** 69 * Registers a callback with the corresponding query condition by using the handle. 70 * This callback is triggered when the component layout complete. 71 * @param { 'layout' } type - type of the listened event. 72 * @param { function } callback - callback of the listened event. 73 * @syscap SystemCapability.ArkUI.ArkUI.Full 74 * @crossplatform 75 * @atomicservice 76 * @since arkts {'1.1':'12','1.2':'20'} 77 * @arkts 1.1&1.2 78 */ 79 on(type: 'layout', callback: () => void): void; 80 81 /** 82 * Deregisters a callback with the corresponding query condition by using the handle. 83 * This callback is not triggered when the component layout complete. 84 * @param { string } type - type of the listened event. 85 * @param { ()=>void } callback - callback of the listened event. 86 * @syscap SystemCapability.ArkUI.ArkUI.Full 87 * @crossplatform 88 * @since 10 89 */ 90 /** 91 * Deregisters a callback with the corresponding query condition by using the handle. 92 * This callback is not triggered when the component layout complete. 93 * @param { 'layout' } type - type of the listened event. 94 * @param { function } callback - callback of the listened event. 95 * @syscap SystemCapability.ArkUI.ArkUI.Full 96 * @crossplatform 97 * @atomicservice 98 * @since arkts {'1.1':'12','1.2':'20'} 99 * @arkts 1.1&1.2 100 */ 101 off(type: 'layout', callback?: () => void): void; 102 103 /** 104 * Registers a callback with the corresponding query condition by using the handle. 105 * This callback is triggered when the component draw complete. 106 * @param { string } type - type of the listened event. 107 * @param { ()=>void } callback - callback of the listened event. 108 * @syscap SystemCapability.ArkUI.ArkUI.Full 109 * @crossplatform 110 * @since 10 111 */ 112 /** 113 * Registers a callback with the corresponding query condition by using the handle. 114 * This callback is triggered when the component draw complete. 115 * @param { 'draw' } type - type of the listened event. 116 * @param { function } callback - callback of the listened event. 117 * @syscap SystemCapability.ArkUI.ArkUI.Full 118 * @crossplatform 119 * @atomicservice 120 * @since arkts {'1.1':'12','1.2':'20'} 121 * @arkts 1.1&1.2 122 */ 123 on(type: 'draw', callback: () => void): void; 124 125 /** 126 * Deregisters a callback with the corresponding query condition by using the handle. 127 * This callback is not triggered when the component draw complete. 128 * @param { string } type - type of the listened event. 129 * @param { ()=>void } callback - callback of the listened event. 130 * @syscap SystemCapability.ArkUI.ArkUI.Full 131 * @crossplatform 132 * @since 10 133 */ 134 /** 135 * Deregisters a callback with the corresponding query condition by using the handle. 136 * This callback is not triggered when the component draw complete. 137 * @param { 'draw' } type - type of the listened event. 138 * @param { function } callback - callback of the listened event. 139 * @syscap SystemCapability.ArkUI.ArkUI.Full 140 * @crossplatform 141 * @atomicservice 142 * @since arkts {'1.1':'12','1.2':'20'} 143 * @arkts 1.1&1.2 144 */ 145 off(type: 'draw', callback?: () => void): void; 146 147 /** 148 * Registers a callback with the corresponding query condition by using the handle. 149 * This callback is triggered when the child of component draw complete. 150 * @param { 'drawChildren' } type - type of the listened event. 151 * @param { Callback<void> } callback - callback of the listened event. 152 * @syscap SystemCapability.ArkUI.ArkUI.Full 153 * @crossplatform 154 * @atomicservice 155 * @since 20 156 */ 157 on(type: 'drawChildren', callback: Callback<void>): void; 158 159 /** 160 * Deregisters a callback with the corresponding query condition by using the handle. 161 * This callback is not triggered when the child of component draw complete. 162 * @param { 'drawChildren' } type - type of the listened event. 163 * @param { Callback<void> } callback - callback of the listened event. 164 * @syscap SystemCapability.ArkUI.ArkUI.Full 165 * @crossplatform 166 * @atomicservice 167 * @since 20 168 */ 169 off(type: 'drawChildren', callback?: Callback<void>): void; 170 } 171 172 /** 173 * Sets the component after layout or draw criteria and returns the corresponding listening handle 174 * @param { string } id - component id. 175 * @returns { ComponentObserver } create listener for observer component event. 176 * @syscap SystemCapability.ArkUI.ArkUI.Full 177 * @crossplatform 178 * @since 10 179 */ 180 /** 181 * Sets the component after layout or draw criteria and returns the corresponding listening handle 182 * @param { string } id - component id. 183 * @returns { ComponentObserver } create listener for observer component event. 184 * @syscap SystemCapability.ArkUI.ArkUI.Full 185 * @crossplatform 186 * @atomicservice 187 * @since arkts {'1.1':'12','1.2':'20'} 188 * @arkts 1.1&1.2 189 * @deprecated since 18 190 * @useinstead ohos.arkui.UIContext.UIInspector#createComponentObserver 191 */ 192 function createComponentObserver(id: string): ComponentObserver; 193 194 /** 195 * Obtains all attributes of the component with the specified ID. 196 * 197 * @param { string } id - ID of the component whose attributes are to be obtained. 198 * @returns { string } 199 * @syscap SystemCapability.ArkUI.ArkUI.Full 200 * @crossplatform 201 * @atomicservice 202 * @since 20 203 * @test 204 * @arkts 1.2 205 */ 206 function getInspectorByKey(id: string): string; 207 208 /** 209 * Get components tree. 210 * 211 * @returns { Object } 212 * @syscap SystemCapability.ArkUI.ArkUI.Full 213 * @crossplatform 214 * @atomicservice 215 * @since 20 216 * @test 217 * @arkts 1.2 218 */ 219 function getInspectorTree(): Object; 220 221 /** 222 * Sends an event to the component with the specified ID. 223 * 224 * @param { string } id - ID of the component for which the event is to be sent. 225 * @param { number } action - Type of the event to be sent. The options are as follows: Click event: 10 LongClick: 11. 226 * @param { string } params - Event parameters. If there is no parameter, pass an empty string "". 227 * @returns { boolean } 228 * @syscap SystemCapability.ArkUI.ArkUI.Full 229 * @crossplatform 230 * @atomicservice 231 * @since 20 232 * @test 233 * @arkts 1.2 234 */ 235 function sendEventByKey(id: string, action: number, params: string): boolean; 236} 237 238export default inspector;