• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Configuring Widget Configuration Files
2
3
4Widget-related configuration includes **FormExtensionAbility** configuration and widget configuration.
5
6
71. Configure FormExtensionAbility information under **extensionAbilities** in the [module.json5 file](../quick-start/module-configuration-file.md). For a FormExtensionAbility, you must specify **metadata**. Specifically, set **name** to **ohos.extension.form** (fixed), and set **resource** to the index of the widget configuration information.
8
9   Example configuration:
10
11
12   ```json
13   {
14     "module": {
15       ...
16       "extensionAbilities": [
17         {
18           "name": "EntryFormAbility",
19           "srcEntry": "./ets/entryformability/EntryFormAbility.ts",
20           "label": "$string:EntryFormAbility_label",
21           "description": "$string:EntryFormAbility_desc",
22           "type": "form",
23           "metadata": [
24             {
25               "name": "ohos.extension.form",
26               "resource": "$profile:form_config"
27             }
28           ]
29         }
30       ]
31     }
32   }
33   ```
34
352. Configure the widget configuration information. In the **metadata** configuration item of FormExtensionAbility, you can specify the resource index of specific configuration information of the widget. For example, if resource is set to **$profile:form_config**, **form_config.json** in the **resources/base/profile/** directory of the development view is used as the profile configuration file of the widget. The following table describes the internal field structure.
36
37   **Table 1** form_config.json file
38
39   | Field| Description| Data Type| Default Value Allowed|
40   | -------- | -------- | -------- | -------- |
41   | name | Class name of the widget. The value is a string with a maximum of 127 bytes.| String| No|
42   | description | Description of the widget. The value can be a string or a resource index to descriptions in multiple languages. The value is a string with a maximum of 255 bytes.| String| Yes (initial value: left empty)|
43   | src | Full path of the UI code corresponding to the widget. For an ArkTS widget, the full path must contain the widget file name extension, for example, **./ets/widget/pages/WidgetCard.ets**. For a JS widget, the full path does not need to contain the widget file name extension, for example, **./js/widget/pages/WidgetCard**.| String| No|
44   | uiSyntax | Type of the widget.<br>- **arkts**: ArkTS widget<br>- **hml**: JS widget| String| Yes (initial value: **hml**)|
45   | window | Window-related configurations.| Object| Yes|
46   | isDefault | Whether the widget is a default one. Each UIAbility has only one default widget.<br>- **true**: The widget is the default one.<br>- **false**: The widget is not the default one.| Boolean| No|
47   | colorMode | Color mode of the widget.<br>- **auto**: auto-adaptive color mode<br>- **dark**: dark color mode<br>- **light**: light color mode| String| Yes (initial value: **auto**)|
48   | supportDimensions | Grid styles supported by the widget.<br>- **1 * 2**: indicates a grid with one row and two columns.<br>- **2 * 2**: indicates a grid with two rows and two columns.<br>- **2 * 4**: indicates a grid with two rows and four columns.<br>- **4 * 4**: indicates a grid with four rows and four columns.| String array| No|
49   | defaultDimension | Default grid style of the widget. The value must be available in the **supportDimensions** array of the widget.| String| No|
50   | updateEnabled | Whether the widget can be updated periodically.<br>- **true**: The widget can be updated at a specified interval (**updateDuration**) or at the scheduled time (**scheduledUpdateTime**). **updateDuration** takes precedence over **scheduledUpdateTime**.<br>- **false**: The widget cannot be updated periodically.| Boolean| No|
51   | scheduledUpdateTime | Scheduled time to update the widget. The value is in 24-hour format and accurate to minute.<br>**NOTE**<br>**updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used.| String| Yes (initial value: The widget cannot be updated periodically.)|
52   | updateDuration | Interval to update the widget. The value is a natural number, in the unit of 30 minutes.<br>If the value is **0**, this field does not take effect.<br>If the value is a positive integer *N*, the interval is calculated by multiplying *N* and 30 minutes.<br>**NOTE**<br>**updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used.| Number| Yes (initial value: **0**)|
53   | formConfigAbility | Link to a specific page of the application. The value is a URI.| String| Yes (initial value: left empty)|
54   | formVisibleNotify | Whether the widget is allowed to use the widget visibility notification.| String| Yes (initial value: left empty)|
55   | metadata | Metadata of the widget. This field contains the array of the **customizeData** field.| Object| Yes (initial value: left empty)|
56
57   Example configuration:
58
59
60   ```json
61   {
62     "forms": [
63       {
64         "name": "widget",
65         "description": "This is a service widget.",
66         "src": "./ets/widget/pages/WidgetCard.ets",
67         "uiSyntax": "arkts",
68         "window": {
69           "designWidth": 720,
70           "autoDesignWidth": true
71         },
72         "colorMode": "auto",
73         "isDefault": true,
74         "updateEnabled": true,
75         "scheduledUpdateTime": "10:30",
76         "updateDuration": 1,
77         "defaultDimension": "2*2",
78         "supportDimensions": [
79           "2*2"
80         ]
81       }
82     ]
83   }
84   ```
85