@ohos.app.form.LiveFormExtensionAbility (LiveFormExtensionAbility)
The LiveFormExtensionAbility module, inherited from ExtensionAbility, provides interactive widget functions, including creating and destroying interactive widgets.
NOTE
The initial APIs of this module are supported since API version 20. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The APIs of this module can be used only in the stage model.
Exceptions may occur if some APIs are called. For details about the API list, see Appendix.
Modules to Import
import { LiveFormExtensionAbility } from '@kit.FormKit';
LiveFormExtensionAbility
Interactive widget extension class. It provides APIs for the widget provider to receive notifications about widget creation and destruction.
Properties
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Ability.Form
Atomic service API: This API can be used in atomic services since API version 20.
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| context | LiveFormExtensionContext | No | No | Context of the LiveFormExtensionAbility. This context is inherited from ExtensionContext. |
onLiveFormCreate
onLiveFormCreate(liveFormInfo: LiveFormInfo, session: UIExtensionContentSession): void
Called after the UI content of LiveFormExtensionAbility is created.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Ability.Form
Atomic service API: This API can be used in atomic services since API version 20.
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| liveFormInfo | LiveFormInfo | Yes | Interactive widget information, including the widget ID. |
| session | UIExtensionContentSession | Yes | UI information. |
Example
import { UIExtensionContentSession } from '@kit.AbilityKit';
import { LiveFormExtensionAbility, LiveFormInfo } from '@kit.FormKit';
const TAG: string = '[testTag] LiveFormExtAbility';
export default class LiveFormExtAbility extends LiveFormExtensionAbility {
onLiveFormCreate(liveFormInfo: LiveFormInfo, session: UIExtensionContentSession) {
console.info(TAG, `onLiveFormCreate, formId: ${liveFormInfo.formId}`);
}
}
onLiveFormDestroy
onLiveFormDestroy(liveFormInfo: LiveFormInfo): void
Called to clear resources when this LiveFormExtensionAbility is destroyed.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Ability.Form
Atomic service API: This API can be used in atomic services since API version 20.
Parameters
| Name | Type | Mandatory | Description |
|---|---|---|---|
| liveFormInfo | LiveFormInfo | Yes | Interactive widget information, including the widget ID. |
Example
import { LiveFormExtensionAbility, LiveFormInfo } from '@kit.FormKit';
const TAG: string = '[testTag] LiveFormExtAbility';
export default class LiveFormExtAbility extends LiveFormExtensionAbility {
onLiveFormDestroy(liveFormInfo: LiveFormInfo) {
console.info(TAG, `onLiveFormDestroy, liveFormInfo: ${liveFormInfo.formId}`);
}
}
LiveFormInfo
Defines the interactive widget information.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.Ability.Form
Atomic service API: This API can be used in atomic services since API version 20.
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| formId | string | No | No | Widget ID. |
| rect | formInfo.Rect | No | No | Widget location and dimension. |
| borderRadius | number | No | No | Widget corner radius. The value must be greater than 0, in vp. |
Appendix
The following table lists the APIs that cannot be called by this module.
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 js-apis-inner-application-formExtensionContext
openharmony 鸿蒙 js-apis-app-form-formEditExtensionAbility
openharmony 鸿蒙 js-apis-app-form-formProvider
openharmony 鸿蒙 js-apis-app-form-formInfo-sys
openharmony 鸿蒙 js-apis-application-formProvider
openharmony 鸿蒙 js-apis-application-formError