提交 c9bd3f3b 编写于 作者: G Gloria

Update docs against 15616

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 4c8f97ad
# @ohos.app.form.FormExtensionAbility (FormExtensionAbility) # @ohos.app.form.FormExtensionAbility (FormExtensionAbility)
The **FormExtensionAbility** module provides APIs related to FormExtensionAbilities. The **FormExtensionAbility** module provides lifecycle callbacks invoked when a widget is created, destroyed, or updated.
> **NOTE** > **NOTE**
> >
...@@ -19,7 +19,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; ...@@ -19,7 +19,7 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ | | ------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
| context | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | Yes | No | Context of the FormExtensionAbility. This context is inherited from **ExtensionContext**.| | context | [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) | Yes | No | Context of the FormExtensionAbility. This context is inherited from [ExtensionContext](js-apis-inner-application-extensionContext.md).|
## onAddForm ## onAddForm
...@@ -33,7 +33,7 @@ Called to notify the widget provider that a **Form** instance (widget) has been ...@@ -33,7 +33,7 @@ Called to notify the widget provider that a **Form** instance (widget) has been
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | -------------------------------------- | ---- | ------------------------------------------------------------ | | ------ | -------------------------------------- | ---- | ------------------------------------------------------------ |
| want | [Want](js-apis-application-want.md) | Yes | Want information related to the ExtensionAbility, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.| | want | [Want](js-apis-application-want.md) | Yes | Want information related to the FormExtensionAbility, including the widget ID, name, and style. The information must be managed as persistent data to facilitate subsequent widget update and deletion.|
**Return value** **Return value**
...@@ -45,17 +45,19 @@ Called to notify the widget provider that a **Form** instance (widget) has been ...@@ -45,17 +45,19 @@ Called to notify the widget provider that a **Form** instance (widget) has been
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'; import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onAddForm(want) { onAddForm(want) {
console.log('FormExtensionAbility onAddForm, want:' + want.abilityName); console.log('FormExtensionAbility onAddForm, want: ${want.abilityName}');
let dataObj1 = { let dataObj1 = {
temperature:'11c', temperature: '11c',
'time':'11:00' 'time': '11:00'
}; };
let obj1 = formBindingData.createFormBindingData(dataObj1); let obj1 = formBindingData.createFormBindingData(dataObj1);
return obj1; return obj1;
} }
} };
``` ```
## onCastToNormalForm ## onCastToNormalForm
...@@ -75,18 +77,20 @@ Called to notify the widget provider that a temporary widget has been converted ...@@ -75,18 +77,20 @@ Called to notify the widget provider that a temporary widget has been converted
**Example** **Example**
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onCastToNormalForm(formId) { onCastToNormalForm(formId) {
console.log('FormExtensionAbility onCastToNormalForm, formId:' + formId); console.log('FormExtensionAbility onCastToNormalForm, formId: ${formId}');
} }
} };
``` ```
## onUpdateForm ## onUpdateForm
onUpdateForm(formId: string): void onUpdateForm(formId: string): void
Called to notify the widget provider that a widget has been updated. After obtaining the latest data, your application should call **updateForm** of [FormExtensionContext](js-apis-inner-application-formExtensionContext.md) to update the widget data. Called to notify the widget provider that a widget has been updated. After obtaining the latest data, your application should call [updateForm](js-apis-app-form-formProvider.md#updateform) of **formProvider** to update the widget data.
**System capability**: SystemCapability.Ability.Form **System capability**: SystemCapability.Ability.Form
...@@ -99,17 +103,24 @@ Called to notify the widget provider that a widget has been updated. After obtai ...@@ -99,17 +103,24 @@ Called to notify the widget provider that a widget has been updated. After obtai
**Example** **Example**
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onUpdateForm(formId) { onUpdateForm(formId) {
console.log('FormExtensionAbility onUpdateForm, formId:' + formId); console.log('FormExtensionAbility onUpdateForm, formId: ${formId}');
let obj2 = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'}); let obj2 = formBindingData.createFormBindingData({
this.context.updateForm(formId, obj2).then((data)=>{ temperature: '22c',
console.log('FormExtensionAbility context updateForm, data:' + data); time: '22:00'
});
formProvider.updateForm(formId, obj2).then((data) => {
console.log('FormExtensionAbility context updateForm, data: ${data}');
}).catch((error) => { }).catch((error) => {
console.error('Operation updateForm failed. Cause: ' + error);}); console.error('Operation updateForm failed. Cause: ${error}');
} });
} }
};
``` ```
## onChangeFormVisibility ## onChangeFormVisibility
...@@ -129,21 +140,28 @@ Called to notify the widget provider of the change of visibility. ...@@ -129,21 +140,28 @@ Called to notify the widget provider of the change of visibility.
**Example** **Example**
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formBindingData from '@ohos.app.form.formBindingData'; import formBindingData from '@ohos.app.form.formBindingData';
import formProvider from '@ohos.app.form.formProvider';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onChangeFormVisibility(newStatus) { onChangeFormVisibility(newStatus) {
console.log('FormExtensionAbility onChangeFormVisibility, newStatus:' + newStatus); console.log('FormExtensionAbility onChangeFormVisibility, newStatus: ${newStatus}');
let obj2 = formBindingData.createFormBindingData({temperature:'22c', time:'22:00'}); let obj2 = formBindingData.createFormBindingData({
temperature: '22c',
for (let key in newStatus) { time: '22:00'
console.log('FormExtensionAbility onChangeFormVisibility, key:' + key + ', value=' + newStatus[key]); });
this.context.updateForm(key, obj2).then((data)=>{
console.log('FormExtensionAbility context updateForm, data:' + data); for (let key in newStatus) {
}).catch((error) => { console.log('FormExtensionAbility onChangeFormVisibility, key: ${key}, value= ${newStatus[key]}');
console.error('Operation updateForm failed. Cause: ' + error);}); formProvider.updateForm(key, obj2).then((data) => {
console.log('FormExtensionAbility context updateForm, data: ${data}');
}).catch((error) => {
console.error('Operation updateForm failed. Cause: ${error}');
});
} }
} }
} };
``` ```
## onFormEvent ## onFormEvent
...@@ -164,11 +182,13 @@ Called to instruct the widget provider to receive and process the widget event. ...@@ -164,11 +182,13 @@ Called to instruct the widget provider to receive and process the widget event.
**Example** **Example**
```ts ```ts
export default class MyFormExtension extends FormExtensionAbility { import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onFormEvent(formId, message) { onFormEvent(formId, message) {
console.log('FormExtensionAbility onFormEvent, formId:' + formId + ', message:' + message); console.log('FormExtensionAbility onFormEvent, formId: ${formId}, message: ${message}');
} }
} };
``` ```
## onRemoveForm ## onRemoveForm
...@@ -188,11 +208,13 @@ Called to notify the widget provider that a **Form** instance (widget) has been ...@@ -188,11 +208,13 @@ Called to notify the widget provider that a **Form** instance (widget) has been
**Example** **Example**
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility { export default class MyFormExtensionAbility extends FormExtensionAbility {
onRemoveForm(formId) { onRemoveForm(formId) {
console.log('FormExtensionAbility onRemoveForm, formId:' + formId); console.log('FormExtensionAbility onRemoveForm, formId: ${formId}');
} }
} };
``` ```
## onConfigurationUpdate ## onConfigurationUpdate
...@@ -212,11 +234,13 @@ Called when the configuration of the environment where the ability is running is ...@@ -212,11 +234,13 @@ Called when the configuration of the environment where the ability is running is
**Example** **Example**
```ts ```ts
class MyFormExtensionAbility extends FormExtensionAbility { import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onConfigurationUpdate(config) { onConfigurationUpdate(config) {
console.log('onConfigurationUpdate, config:' + JSON.stringify(config)); console.log('onConfigurationUpdate, config: ${JSON.stringify(config)}');
} }
} };
``` ```
## onAcquireFormState ## onAcquireFormState
...@@ -236,13 +260,15 @@ Called when the widget provider receives the status query result of a widget. By ...@@ -236,13 +260,15 @@ Called when the widget provider receives the status query result of a widget. By
**Example** **Example**
```ts ```ts
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
import formInfo from '@ohos.app.form.formInfo'; import formInfo from '@ohos.app.form.formInfo';
class MyFormExtensionAbility extends FormExtensionAbility {
export default class MyFormExtensionAbility extends FormExtensionAbility {
onAcquireFormState(want) { onAcquireFormState(want) {
console.log('FormExtensionAbility onAcquireFormState, want:' + want); console.log('FormExtensionAbility onAcquireFormState, want: ${want}');
return formInfo.FormState.UNKNOWN; return formInfo.FormState.UNKNOWN;
} }
} };
``` ```
## onShareForm ## onShareForm
...@@ -270,14 +296,16 @@ Called by the widget provider to receive shared widget data. ...@@ -270,14 +296,16 @@ Called by the widget provider to receive shared widget data.
**Example** **Example**
```ts ```ts
class MyFormExtensionAbility extends FormExtensionAbility { import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export default class MyFormExtensionAbility extends FormExtensionAbility {
onShareForm(formId) { onShareForm(formId) {
console.log('FormExtensionAbility onShareForm, formId:' + formId); console.log('FormExtensionAbility onShareForm, formId: ${formId}');
let wantParams = { let wantParams = {
'temperature':'20', 'temperature': '20',
'time':'2022-8-8 09:59', 'time': '2022-8-8 09:59',
}; };
return wantParams; return wantParams;
} }
} };
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册