• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Service Widget Overview
2
3
4A service widget (also called widget) is a set of UI components that display important information or operations specific to an application. It provides users with direct access to a desired application service, without the need to open the application first. A widget is usually displayed as part of the UI of another application (which can only be a system application, such as the home screen) and provides basic interactive features such as opening a UI page or sending a message.
5
6
7## Service Widget Architecture
8
9**Figure 1** Service widget architecture
10
11![WidgetArchitecture](figures/WidgetArchitecture.png)
12
13Before you get started, it would be helpful if you have a basic understanding of the following concepts:
14
15- Widget host: an application that displays the widget content and controls the widget location. An example is the home screen in the preceding figure.
16
17  - Application icon: an icon for entry to an application, clicking which starts the application process. The icon content does not support interactions.
18  - Widget: an interactive UI in various sizes. It may provide buttons to implement different features, such as the button to [update the widget content](arkts-ui-widget-event-formextensionability.md) or [switch to an application](arkts-ui-widget-event-router.md).
19
20- Widget provider: an application that provides widget content to be displayed. It controls the display content, display logic, and component click events triggered on a widget.
21
22  - FormExtensionAbility: a widget service logic module, which provides lifecycle callbacks invoked when a widget is created, destroyed, or updated.
23  - Widget page: a widget UI module, which contains display and interaction information such as components, layouts, and events.
24
25Below is the typical procedure of using a widget:
26
27**Figure 2** Typical procedure of using a widget
28
29![WidgetUse](figures/WidgetUse.png)
30
311. Touch and hold an application icon on the home screen to display the shortcut menu.
32
332. Touch **Service widget** to access the preview screen.
34
353. Touch the **Add to home** button. The widget is then added to the home screen.
36
37
38## Widget UI Development Modes
39
40In the stage model, the UI of a widget can be developed in [ArkTS](arkts-ui-widget-working-principles.md) or [JS](js-ui-widget-development.md).
41
42- A widget developed in the ArkTS-based declarative development paradigm is called ArkTS widget.
43
44- A widget developed in the JS-compatible web-like development paradigm is called JS widget.
45
46ArkTS widgets and JS widgets have different implementation principles and features. The following table lists the differences in capabilities.
47
48| Category| JS Widget| ArkTS Widget|
49| -------- | -------- | -------- |
50| Development paradigm| Web-like paradigm| Declarative paradigm|
51| Component capability| Supported| Supported|
52| Layout capability| Supported| Supported|
53| Event capability| Supported| Supported|
54| Custom animation| Not supported| Supported|
55| Custom drawing| Not supported| Supported|
56| Logic code execution (excluding the import capability)| Not supported| Supported|
57
58As can be seen above, ArkTS widgets provide more capabilities and use cases than JS widgets. Therefore, ArkTS widgets are always recommended, except for the case where the widget consists of only static pages.
59
60## Dynamic Widgets and Static Widgets
61ArkTS widgets can be further classified as dynamic or static (distinguished by the **isDynamic** field in the [form_config.json](arkts-ui-widget-configuration.md) file). The differences between these two types are as follows:
62- Dynamic widget: With support for universal events and custom animations, this type of widget is applicable to scenarios involving complex service logic and interactions. Compared with its static counterpart, the dynamic widget is more feature rich and memory hogging.
63- Static widget: This type of widget provides UI components and layout capabilities, but does not support universal events or custom animations. It displays content in a static form and only allows for redirection to a specified UIAbility through the [FormLink](../reference/arkui-ts/ts-container-formlink.md) component. It is applicable for information display (where the UI is relatively fixed), consuming significantly less memory than the dynamic widget.
64
65The following table compares the capabilities of static widget and dynamic widgets.
66| Capability| Static Widget| Dynamic Widget|
67| -------- | -------- | -------- |
68| Component capability| Supported| Supported|
69| Layout capability| Supported| Supported|
70| Event capability| Conditionally supported| Supported|
71| Custom animation| Not supported| Supported|
72| Custom drawing| Supported| Supported|
73| Logic code execution (excluding the import capability)| Supported| Supported|
74
75When using static widgets, avoid the following scenarios:
76- Scenarios where the UI is refreshed frequently
77
78- Scenarios where state variables are passed through [FormLink](../reference/arkui-ts/ts-container-formlink.md) during refresh
79
80- Scenarios that involve complex service logic
81
82- Scenarios that involve animations
83