1e41f4b71Sopenharmony_ci# ArkTS Widget Working Principles
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## Implementation Principles
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci**Figure 1** ArkTS widget implementation principles
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci![WidgetPrinciple](figures/WidgetPrinciple.png)
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci- Widget host: an application that displays the widget content and controls the widget location. Only the system application can function as a widget host.
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci- Widget provider: an application that provides the widget content to display and controls how widget components are laid out and how they interact with users.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci- Widget Manager: a resident agent that manages widgets in the system. It provides [formProvider](../reference/apis-form-kit/js-apis-app-form-formProvider.md)<!--Del--> and [formHost](../reference/apis-form-kit/js-apis-app-form-formHost-sys.md)<!--DelEnd--> as well as the APIs for widget management, usage, and periodic updates. 
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci- Widget rendering service: a service that manages widget rendering instances. Widget rendering instances are bound to the <!--Del-->[<!--DelEnd-->FormComponent<!--Del-->](../reference/apis-arkui/arkui-ts/ts-basic-components-formcomponent-sys.md)<!--DelEnd--> on the widget host on a one-to-one basis. The widget rendering service runs the widget page code **widgets.abc** for rendering, and sends the rendered data to the corresponding <!--Del-->[<!--DelEnd-->FormComponent<!--Del-->](../reference/apis-arkui/arkui-ts/ts-basic-components-formcomponent-sys.md)<!--DelEnd--> on the widget host.
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci  **Figure 2** Working principles of the ArkTS widget rendering service
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci  ![WidgetRender](figures/WidgetRender.png)
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ciCompared with dynamic widgets, static widgets have the same overall running framework and rendering process. The main difference is that after the widget rendering service renders the widget content, the widget host uses the last frame of rendered data as a static image, and the widget rendering instance releases all running resources of the widget to save memory. As such, frequent updating of static widgets causes continuous creation and destruction of resources, resulting in increased power consumption.<br>
23e41f4b71Sopenharmony_ciUnlike JS widgets, ArkTS widgets support logic code execution. The widget page code **widgets.abc** is executed by the widget rendering service, which is managed by the Widget Manager. Each widget component of a widget host corresponds to a rendering instance in the widget rendering service. Rendering instances of a widget provider run in the same ArkTS virtual machine operating environment, and rendering instances of different widget providers run in different ArkTS virtual machine operating environments. In this way, the resources and state data are isolated between widgets of different widget providers. During development, pay attention to the use of the **globalThis** object. Use one **globalThis** object for widgets from the same widget provider, and different **globalThis** objects for widgets from different widget providers.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci## Advantages of ArkTS Widgets
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ciAs a quick entry to applications, ArkTS widgets outperform JS widgets in the following aspects:
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci- Improved development experience and efficiency, thanks to the unified development paradigm
31e41f4b71Sopenharmony_ci  
32e41f4b71Sopenharmony_ci  ArkTS widgets share the same declarative UI development framework as application pages. This means that the page layouts can be directly reused in widgets, improving development experience and efficiency.
33e41f4b71Sopenharmony_ci  
34e41f4b71Sopenharmony_ci  **Figure 3** Comparison of widget project structures
35e41f4b71Sopenharmony_ci  
36e41f4b71Sopenharmony_ci  ![WidgetProject](figures/WidgetProject.png)
37e41f4b71Sopenharmony_ci  
38e41f4b71Sopenharmony_ci- More widget features
39e41f4b71Sopenharmony_ci  - Animation: ArkTS widgets support the [property animation](../reference/apis-arkui/arkui-ts/ts-animatorproperty.md) and [explicit animation](../reference/apis-arkui/arkui-ts/ts-explicit-animation.md) capabilities, which can be leveraged to deliver a more engaging experience.
40e41f4b71Sopenharmony_ci  - Custom drawing: ArkTS widgets allow you to draw graphics with the [\<Canvas>](../reference/apis-arkui/arkui-ts/ts-components-canvas-canvas.md) component to present information more vividly.
41e41f4b71Sopenharmony_ci  - Logic code execution: The capability to run logic code in widgets means that service logic can be self-closed in widgets, expanding the use cases of widgets.
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci## Constraints on ArkTS Widgets
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ciCompared with JS widgets, ArkTS widgets provide more capabilities, but they are also more prone to malicious behavior. To account for the impact on the widget host – typically the home screen, ArkTS widgets are subject to the following restrictions:
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci- When importing modules, you can import only the modules marked with "supported in ArkTS widgets."
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci- Shared packages cannot be imported.
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci- The native programming language cannot be used for development.
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci- Only partial components, events, animations, data management, state management, and API capabilities of the [declarative paradigm](../ui/arkts-ui-development-overview.md) are supported.
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci- The event processing of the widget is independent of that of the widget host. To prevent gesture conflicts, avoid using swipers in the widget when the widget host supports left and right swipes.
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ciIn addition, ArkTS widgets do not support the following features:
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci- Instant preview
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci- Breakpoint debugging
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci- Hot reload
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci- **setTimeOut**
66