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 21/** 22 * Enumeration of different types of DpiFollowStrategy. 23 * 24 * @enum { number } 25 * @syscap SystemCapability.ArkUI.ArkUI.Full 26 * @systemapi 27 * @since 12 28 */ 29declare enum DpiFollowStrategy { 30 /** 31 * Followed the host DPI. 32 * 33 * @syscap SystemCapability.ArkUI.ArkUI.Full 34 * @systemapi 35 * @since 12 36 */ 37 FOLLOW_HOST_DPI = 0, 38 39 /** 40 * Followed the UIExtensionAbility. 41 * 42 * @syscap SystemCapability.ArkUI.ArkUI.Full 43 * @systemapi 44 * @since 12 45 */ 46 FOLLOW_UI_EXTENSION_ABILITY_DPI = 1, 47} 48 49/** 50 * This interface is used to set the options for UIExtensionComponentAttribute during construction 51 * 52 * @interface UIExtensionOptions 53 * @syscap SystemCapability.ArkUI.ArkUI.Full 54 * @systemapi 55 * @since 11 56 */ 57declare interface UIExtensionOptions { 58 /** 59 * Set whether the current capability is used as a Caller.<br/> 60 * If set to true, as a Caller, the current token of UIExtensionComponent is set to rootToken. 61 * 62 * @type { ?boolean } 63 * @default false 64 * @syscap SystemCapability.ArkUI.ArkUI.Full 65 * @systemapi 66 * @since 11 67 */ 68 isTransferringCaller?: boolean; 69 70 /** 71 * Set placeholder. 72 * If set placeholder ComponentContent, show placeholder node when connection is not established. 73 * 74 * @type { ?ComponentContent } 75 * @syscap SystemCapability.ArkUI.ArkUI.Full 76 * @systemapi 77 * @since 12 78 */ 79 placeholder?: ComponentContent; 80 81 /** 82 * Set Areachange placeholder. 83 * If the Areachange placeholder ComponentContent is set, the placeholder node is displayed until 84 * the UIExtensionComponent size change is complete. 85 * 86 * @type { ?Record<string, ComponentContent> } 87 * @syscap SystemCapability.ArkUI.ArkUI.Full 88 * @systemapi 89 * @since 13 90 */ 91 areaChangePlaceholder?: Record<string, ComponentContent>; 92 93 /** 94 * Set UIExtensionComponent Content Dpi Follow Strategy. 95 * 96 * @type { ?DpiFollowStrategy } 97 * @default DpiFollowStrategy.FOLLOW_UI_EXTENSION_ABILITY_DPI 98 * @syscap SystemCapability.ArkUI.ArkUI.Full 99 * @systemapi 100 * @since 12 101 */ 102 dpiFollowStrategy?: DpiFollowStrategy; 103} 104 105/** 106 * Indicates the information when the provider of the embedded UI is terminated. 107 * 108 * @interface TerminationInfo 109 * @syscap SystemCapability.ArkUI.ArkUI.Full 110 * @systemapi 111 * @since 12 112 */ 113declare interface TerminationInfo { 114 /** 115 * Defines the termination code. 116 * 117 * @type { number } 118 * @syscap SystemCapability.ArkUI.ArkUI.Full 119 * @systemapi 120 * @since 12 121 */ 122 code: number; 123 124 /** 125 * Defines the additional termination information. 126 * 127 * @type { ?import('../api/@ohos.app.ability.Want').default } 128 * @syscap SystemCapability.ArkUI.ArkUI.Full 129 * @systemapi 130 * @since 12 131 */ 132 want?: import('../api/@ohos.app.ability.Want').default; 133} 134 135/** 136 * Get Callback from @ohos.base. 137 * 138 * @typedef { import('../api/@ohos.base').Callback<Record<string, Object>> } 139 * @syscap SystemCapability.ArkUI.ArkUI.Full 140 * @systemapi 141 * @since 14 142 */ 143declare type ReceiveCallback = import('../api/@ohos.base').Callback<Record<string, Object>>; 144 145/** 146 * This interface is used for send data to the UIExtensionAbility.<br/> 147 * It is returned from onRemoteReady callback of UIExtensionComponent<br/> 148 * when UIExtensionAbility connects successfully 149 * 150 * @interface UIExtensionProxy 151 * @syscap SystemCapability.ArkUI.ArkUI.Full 152 * @systemapi 153 * @since 10 154 */ 155declare interface UIExtensionProxy { 156 /** 157 * This function is for sending data to the UIExtensionAbility. 158 * 159 * @param { object } data 160 * @syscap SystemCapability.ArkUI.ArkUI.Full 161 * @systemapi 162 * @since 10 163 */ 164 /** 165 * This function is for sending data to the UIExtensionAbility. 166 * 167 * @param { Record<string, Object> } data 168 * @syscap SystemCapability.ArkUI.ArkUI.Full 169 * @systemapi 170 * @since 14 171 */ 172 send(data: Record<string, Object>): void; 173 174 /** 175 * This function is for sending data to the UIExtensionAbility and waiting the result in blocking mode. 176 * 177 * @param { object } data - data send to the UIExtensionAbility 178 * @returns { object } data - data transferred from the UIExtensionAbility 179 * @throws { BusinessError } 100011 - No callback has been registered to response this request. 180 * @throws { BusinessError } 100012 - Transferring data failed. 181 * @syscap SystemCapability.ArkUI.ArkUI.Full 182 * @systemapi 183 * @since 11 184 */ 185 /** 186 * This function is for sending data to the UIExtensionAbility and waiting the result in blocking mode. 187 * 188 * @param { Record<string, Object> } data - Data send to the UIExtensionAbility. 189 * @returns { Record<string, Object> } data - Data transferred from the UIExtensionAbility. 190 * @throws { BusinessError } 100011 - No callback has been registered to response this request. 191 * @throws { BusinessError } 100012 - Transferring data failed. 192 * @syscap SystemCapability.ArkUI.ArkUI.Full 193 * @systemapi 194 * @since 14 195 */ 196 sendSync(data: Record<string, Object>): Record<string, Object>; 197 198 /** 199 * Register the listener that watches for async data receiver callback being registered by UIExtensionAbility. 200 * 201 * @param { 'asyncReceiverRegister' } type - Indicates the type of event. 202 * @param { function } callback - callback of the listened event. 203 * @syscap SystemCapability.ArkUI.ArkUI.Full 204 * @systemapi 205 * @since 11 206 */ 207 /** 208 * Register the listener that watches for async data receiver callback being registered by UIExtensionAbility. 209 * 210 * @param { 'asyncReceiverRegister' } type - Indicates the type of event. 211 * @param { Callback<UIExtensionProxy> } callback - Callback of the listened event. 212 * @syscap SystemCapability.ArkUI.ArkUI.Full 213 * @systemapi 214 * @since 14 215 */ 216 on(type: 'asyncReceiverRegister', callback: Callback<UIExtensionProxy>): void; 217 218 /** 219 * Register the listener that watches for sync data receiver callback being registered by UIExtensionAbility. 220 * 221 * @param { 'syncReceiverRegister' } type - Indicates the type of event. 222 * @param { function } callback - callback of the listened event. 223 * @syscap SystemCapability.ArkUI.ArkUI.Full 224 * @systemapi 225 * @since 11 226 */ 227 /** 228 * Register the listener that watches for sync data receiver callback being registered by UIExtensionAbility. 229 * 230 * @param { 'syncReceiverRegister' } type - Indicates the type of event. 231 * @param { Callback<UIExtensionProxy> } callback - Callback of the listened event. 232 * @syscap SystemCapability.ArkUI.ArkUI.Full 233 * @systemapi 234 * @since 14 235 */ 236 on(type: 'syncReceiverRegister', callback: Callback<UIExtensionProxy>): void; 237 238 /** 239 * Deregisters the listener that watches for async data receiver callback being registered by UIExtensionAbility. 240 * 241 * @param { 'asyncReceiverRegister' } type - type of the listened event. 242 * @param { function } callback - callback of the listened event. 243 * @syscap SystemCapability.ArkUI.ArkUI.Full 244 * @systemapi 245 * @since 11 246 */ 247 /** 248 * Deregisters the listener that watches for async data receiver callback being registered by UIExtensionAbility. 249 * 250 * @param { 'asyncReceiverRegister' } type - Type of the listened event. 251 * @param { Callback<UIExtensionProxy> } [callback] - Callback of the listened event. 252 * @syscap SystemCapability.ArkUI.ArkUI.Full 253 * @systemapi 254 * @since 14 255 */ 256 off(type: 'asyncReceiverRegister', callback?: Callback<UIExtensionProxy>): void; 257 258 /** 259 * Deregisters the listener that watches for sync data receiver callback being registered by UIExtensionAbility. 260 * 261 * @param { 'syncReceiverRegister' } type - type of the listened event. 262 * @param { function } callback - callback of the listened event. 263 * @syscap SystemCapability.ArkUI.ArkUI.Full 264 * @systemapi 265 * @since 11 266 */ 267 /** 268 * Deregisters the listener that watches for sync data receiver callback being registered by UIExtensionAbility. 269 * 270 * @param { 'syncReceiverRegister' } type - Type of the listened event. 271 * @param { Callback<UIExtensionProxy> } [callback] - Callback of the listened event. 272 * @syscap SystemCapability.ArkUI.ArkUI.Full 273 * @systemapi 274 * @since 14 275 */ 276 off(type: 'syncReceiverRegister', callback?: Callback<UIExtensionProxy>): void; 277} 278 279/** 280 * Provide an interface for the UIExtensionComponent, which is used 281 * <br/>to render UI of a remote UIExtensionAbility 282 * 283 * @interface UIExtensionComponentInterface 284 * @syscap SystemCapability.ArkUI.ArkUI.Full 285 * @systemapi 286 * @since 10 287 */ 288interface UIExtensionComponentInterface { 289 /** 290 * Construct the UIExtensionComponent.<br/> 291 * Called when the UIExtensionComponent is used. 292 * 293 * @param { import('../api/@ohos.app.ability.Want').default } want - indicates the want of UIExtensionAbility 294 * @returns { UIExtensionComponentAttribute } 295 * @syscap SystemCapability.ArkUI.ArkUI.Full 296 * @systemapi 297 * @since 10 298 */ 299 /** 300 * Construct the UIExtensionComponent.<br/> 301 * Called when the UIExtensionComponent is used. 302 * 303 * @param { import('../api/@ohos.app.ability.Want').default } want - indicates the want of UIExtensionAbility 304 * @param { UIExtensionOptions } [options] - Construction configuration of UIExtensionComponentAttribute 305 * @returns { UIExtensionComponentAttribute } 306 * @syscap SystemCapability.ArkUI.ArkUI.Full 307 * @systemapi 308 * @since 11 309 */ 310 ( 311 want: import('../api/@ohos.app.ability.Want').default, 312 options?: UIExtensionOptions 313 ): UIExtensionComponentAttribute; 314} 315 316/** 317 * Define the attribute functions of UIExtensionComponent. 318 * 319 * @extends CommonMethod<UIExtensionComponentAttribute> 320 * @syscap SystemCapability.ArkUI.ArkUI.Full 321 * @systemapi 322 * @since 10 323 */ 324declare class UIExtensionComponentAttribute extends CommonMethod<UIExtensionComponentAttribute> { 325 /** 326 * @param { import('../api/@ohos.base').Callback<UIExtensionProxy> } callback 327 * - callback called when remote UIExtensionAbility object is 328 * <br/>ready for receive data 329 * @returns { UIExtensionComponentAttribute } 330 * @syscap SystemCapability.ArkUI.ArkUI.Full 331 * @systemapi 332 * @since 10 333 */ 334 onRemoteReady( 335 callback: import('../api/@ohos.base').Callback<UIExtensionProxy> 336 ): UIExtensionComponentAttribute; 337 338 /** 339 * @param { import('../api/@ohos.base').Callback<{ [key: string]: Object }> } callback 340 * - called when data received from UIExtensionAbility 341 * @returns { UIExtensionComponentAttribute } 342 * @syscap SystemCapability.ArkUI.ArkUI.Full 343 * @systemapi 344 * @since 10 345 */ 346 /** 347 * @param { ReceiveCallback } callback - Called when data received from UIExtensionAbility 348 * @returns { UIExtensionComponentAttribute } 349 * @syscap SystemCapability.ArkUI.ArkUI.Full 350 * @systemapi 351 * @since 14 352 */ 353 onReceive(callback: ReceiveCallback): UIExtensionComponentAttribute; 354 355 /** 356 * @param { import('../api/@ohos.base').Callback<{code: number;want?: import('../api/@ohos.app.ability.Want').default;}> } callback 357 * - called when the UIExtensionAbility is terminated with result data. 358 * @returns { UIExtensionComponentAttribute } 359 * @syscap SystemCapability.ArkUI.ArkUI.Full 360 * @systemapi 361 * @since 10 362 * @deprecated since 12 363 * @useinstead UIExtensionComponentAttribute#onTerminated 364 */ 365 onResult( 366 callback: import('../api/@ohos.base').Callback<{ 367 code: number; 368 want?: import('../api/@ohos.app.ability.Want').default; 369 }> 370 ): UIExtensionComponentAttribute; 371 372 /** 373 * @param { import('../api/@ohos.base').Callback<number> } callback 374 * - number returned from callback function if disconnected from UIExtensionAbility, 0 means the 375 * <br/>UIExtensionAbility is terminate by itself, otherwise the connect is broken abnormal. 376 * @returns { UIExtensionComponentAttribute } 377 * @syscap SystemCapability.ArkUI.ArkUI.Full 378 * @systemapi 379 * @since 10 380 * @deprecated since 12 381 * @useinstead UIExtensionComponentAttribute#onTerminated or UIExtensionComponentAttribute#onError 382 */ 383 onRelease( 384 callback: import('../api/@ohos.base').Callback<number> 385 ): UIExtensionComponentAttribute; 386 387 /** 388 * @param { import('../api/@ohos.base').ErrorCallback } callback 389 * - called when some error occurred except disconnected from UIExtensionAbility. 390 * @returns { UIExtensionComponentAttribute } 391 * @syscap SystemCapability.ArkUI.ArkUI.Full 392 * @systemapi 393 * @since 10 394 */ 395 onError( 396 callback: import('../api/@ohos.base').ErrorCallback 397 ): UIExtensionComponentAttribute; 398 399 /** 400 * Called when the provider of the embedded UI is terminated. 401 * 402 * @param { Callback<TerminationInfo> } callback 403 * @returns { UIExtensionComponentAttribute } 404 * @syscap SystemCapability.ArkUI.ArkUI.Full 405 * @systemapi 406 * @since 12 407 */ 408 onTerminated(callback: Callback<TerminationInfo>): UIExtensionComponentAttribute; 409} 410 411/** 412 * Defines UIExtensionComponent Component. 413 * 414 * @syscap SystemCapability.ArkUI.ArkUI.Full 415 * @systemapi 416 * @since 10 417 */ 418declare const UIExtensionComponent: UIExtensionComponentInterface; 419 420/** 421 * Defines UIExtensionComponent Component instance. 422 * 423 * @syscap SystemCapability.ArkUI.ArkUI.Full 424 * @systemapi 425 * @since 10 426 */ 427declare const UIExtensionComponentInstance: UIExtensionComponentAttribute; 428