1e41f4b71Sopenharmony_ci# IsolatedComponent (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci**IsolatedComponent** is designed to support the embedding and display of UIs provided by independent .abc files within the current page, with the displayed content running in a restricted worker thread.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciThe **FolderStack** component is usually used in modular development scenarios where .abc file hot update is required.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci> **NOTE**
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> This component is supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version.
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci> The APIs provided by this module are system APIs.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Constraints
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci**Specifications Constraints**
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci1. This component does not support preview.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci2. .abc files must pass the [VerifyAbc](../../apis-ability-kit/js-apis-bundleManager.md#bundlemanagerverifyabc11) verification to be used in this component.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci3. Construction parameter updates are not supported; only the initial input is effective.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci4. Nesting of **IsolatedComponent** components is not supported.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**Experience Constraints**
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci1. When an **IsolatedComponent** component is created, there is a certain amount of time required for the restricted worker thread to load and render the .abc file layout. During this period, the background color of the **IsolatedComponent** is displayed.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci2. The main thread and the restricted worker thread handle layout rendering asynchronously, which can lead to desynchronization in page changes caused by layout alterations or rotations.
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci3. Event transmission between the main thread and the restricted worker thread is managed asynchronously, and there is no support for event bubbling between threads. As a result, UI interactions between threads may encounter event conflicts.
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**Security Constraints**
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci1. Displaying an independent .abc file through the **IsolatedComponent** component in the host process means that the .abc file content is fully accessible to the host, granting the host the control over the file content. For security-sensitive situations where such open access could be a risk, the use of this feature is disabled.
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci2. Running independent .abc files in a restricted worker thread offers a level of security, as the .abc file content is isolated and does not interfere with the main thread.
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci## Child Components
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ciNot supported
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci## APIs
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ciIsolatedComponent(options: IsolatedOptions)
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ciCreates an **IsolatedComponent** component to display the .abc file executed in a restricted worker thread.
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci**Parameters**
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci| Name               | Type                                                  | Mandatory| Description          |
52e41f4b71Sopenharmony_ci| --------------------- | ---------------------------------------------------------- | ---- | ------------------ |
53e41f4b71Sopenharmony_ci| options | [IsolatedOptions](#isolatedoptions)                | Yes  | Construction parameters.|
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci## IsolatedOptions
56e41f4b71Sopenharmony_ciDescribes the optional construction parameters during **IsolatedComponent** construction.
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci**Parameters**
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci| Name              | Type                                | Mandatory| Description                                                                                                     |
61e41f4b71Sopenharmony_ci| ----                 | ---------------------------------------- | ---- | ---------------                                                                                               |
62e41f4b71Sopenharmony_ci| want | [Want](../../apis-ability-kit/js-apis-app-ability-want.md)                                  | Yes  | .abc file information to load.|
63e41f4b71Sopenharmony_ci| worker | [RestrictedWorker](../../apis-arkts/js-apis-worker.md#restrictedworker11)       | Yes  | Restricted worker thread where the .abc file is running.|
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci## Attributes
66e41f4b71Sopenharmony_ciOnly the [width](ts-universal-attributes-size.md#width), [height](ts-universal-attributes-size.md#height), and [backgroundColor](ts-universal-attributes-background.md#backgroundcolor) universal attributes are supported.
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci## Events
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ciThe [universal events](ts-universal-events-click.md) are not supported.
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ciEvents are asynchronously passed to the restricted worker thread after coordinate conversion.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ciThe following events are supported:
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci### onError
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_cionError(callback:ErrorCallback)
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ciInvoked when an error occurs during the running of the **IsolatedComponent**. You can obtain the error information based on the **code**, **name**, and **message** parameters in the callback and rectify the exception accordingly.
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**Parameters**
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci| Name                      | Type  | Description                                                        |
85e41f4b71Sopenharmony_ci| ---------------------------- | ------ | ------------------------------------------------------------ |
86e41f4b71Sopenharmony_ci| callback                        | [ErrorCallback](../../apis-basic-services-kit/js-apis-base.md#errorcallback) | Error information.   |
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci## Example
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ciThis example shows only the usage of the component.
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci```ts
93e41f4b71Sopenharmony_ci// OhCardWorker.ets
94e41f4b71Sopenharmony_ciimport { worker, ThreadWorkerGlobalScope, MessageEvents, ErrorEvent } from '@kit.ArkTS';
95e41f4b71Sopenharmony_ciconst workerPort: ThreadWorkerGlobalScope = worker.workerPort;
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ciworkerPort.onmessage = (e: MessageEvents) => {}
98e41f4b71Sopenharmony_ciworkerPort.onmessageerror = (e: MessageEvents) => {}
99e41f4b71Sopenharmony_ciworkerPort.onerror = (e: ErrorEvent) => {}
100e41f4b71Sopenharmony_ci```
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci```ts
103e41f4b71Sopenharmony_ci// Index.ets
104e41f4b71Sopenharmony_ciimport { worker } from '@kit.ArkTS';
105e41f4b71Sopenharmony_ciimport { bundleManager } from '@kit.AbilityKit';
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci@Entry
108e41f4b71Sopenharmony_ci@Component
109e41f4b71Sopenharmony_cistruct Index2 {
110e41f4b71Sopenharmony_ci  @State isShow: boolean = false;
111e41f4b71Sopenharmony_ci  worker ?: worker.RestrictedWorker;
112e41f4b71Sopenharmony_ci  resourcePath : string = "";
113e41f4b71Sopenharmony_ci  abcPath : string = "";
114e41f4b71Sopenharmony_ci  entryPoint : string = "";
115e41f4b71Sopenharmony_ci  fileName: string = "Index"
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci  build() {
118e41f4b71Sopenharmony_ci    Row() {
119e41f4b71Sopenharmony_ci      Column() {
120e41f4b71Sopenharmony_ci        // 1. Call verifyAbc to verify /data/storage/el2/haps/entry/files/Index.abc in the application sandbox.
121e41f4b71Sopenharmony_ci        Button("verifyAbc").onClick(()=>{
122e41f4b71Sopenharmony_ci          let abcFilePath = getContext(this).filesDir + "/" + this.fileName + ".abc";
123e41f4b71Sopenharmony_ci          bundle.verifyAbc([abcFilePath], false);
124e41f4b71Sopenharmony_ci        }).height(100).width(100)
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci        // 2. Display the IsolatedComponent.
127e41f4b71Sopenharmony_ci        Button("showIsolatedComponent").onClick(()=>{
128e41f4b71Sopenharmony_ci          if (!this.isShow) {
129e41f4b71Sopenharmony_ci            this.worker = new worker.RestrictedWorker("./OhCardWorker");
130e41f4b71Sopenharmony_ci            // /data/storage/el2/haps/entry/files/{fileName}.hap
131e41f4b71Sopenharmony_ci            this.resourcePath = getContext(this).filesDir + "/" + this.fileName + '.hap';
132e41f4b71Sopenharmony_ci            // /abcs/data/storage/el2/haps/entry/files/{fileName}.hap
133e41f4b71Sopenharmony_ci            this.abcPath = "/abcs" + getContext(this).filesDir + "/" + this.fileName;
134e41f4b71Sopenharmony_ci            this.entryPoint = "com.ohos.test/entry/ets/pages/Index"
135e41f4b71Sopenharmony_ci            this.isShow = true;
136e41f4b71Sopenharmony_ci          }
137e41f4b71Sopenharmony_ci        }).height(100).width(100)
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci        if (this.isShow) {
140e41f4b71Sopenharmony_ci          IsolatedComponent({
141e41f4b71Sopenharmony_ci            want: {
142e41f4b71Sopenharmony_ci              "parameters" : {
143e41f4b71Sopenharmony_ci                "resourcePath" : this.resourcePath,
144e41f4b71Sopenharmony_ci                "abcPath" : this.abcPath,
145e41f4b71Sopenharmony_ci                "entryPoint" : this.entryPoint
146e41f4b71Sopenharmony_ci              }
147e41f4b71Sopenharmony_ci            },
148e41f4b71Sopenharmony_ci            "worker" : this.worker
149e41f4b71Sopenharmony_ci          }).width(300).height(300).onError((err)=>{
150e41f4b71Sopenharmony_ci            console.info("onError : " + JSON.stringify(err));
151e41f4b71Sopenharmony_ci          })
152e41f4b71Sopenharmony_ci        }
153e41f4b71Sopenharmony_ci      }
154e41f4b71Sopenharmony_ci      .width('100%')
155e41f4b71Sopenharmony_ci    }
156e41f4b71Sopenharmony_ci    .height('100%')
157e41f4b71Sopenharmony_ci  }
158e41f4b71Sopenharmony_ci}
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci```
161