1e41f4b71Sopenharmony_ci# @ohos.arkui.UIContext (UIContext)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciIn the stage model, a window stage or window can use the [loadContent](js-apis-window.md#loadcontent9) API to load pages, create a UI instance, and render page content to the associated window. Naturally, UI instances and windows are associated on a one-by-one basis. Some global UI APIs are executed in the context of certain UI instances. When calling these APIs, you must identify the UI context, and consequently UI instance, by tracing the call chain. If these APIs are called on a non-UI page or in some asynchronous callback, the current UI context may fail to be identified, resulting in API execution errors.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci**@ohos.window** adds the [getUIContext](js-apis-window.md#getuicontext10) API in API version 10 for obtaining the **UIContext** object of a UI instance. The API provided by the **UIContext** object can be directly applied to the corresponding UI instance.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci> **NOTE**
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci> You can preview how this component looks on a real device, but not in DevEco Studio Previewer.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## UIContext
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getUIContext()](js-apis-window.md#getuicontext10) in **@ohos.window** to obtain a **UIContext** instance, and then call the APIs using the obtained instance. Alternatively, you can obtain a **UIContext** instance through the built-in method [getUIContext()](arkui-ts/ts-custom-component-api.md#getuicontext) of the custom component. In this document, the **UIContext** instance is represented by **uiContext**.
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci### getFont
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_cigetFont(): Font
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciObtains a **Font** object.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci**Return value**
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci| Type           | Description         |
30e41f4b71Sopenharmony_ci| ------------- | ----------- |
31e41f4b71Sopenharmony_ci| [Font](#font) | **Font** object. |
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**Example**
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci```ts
36e41f4b71Sopenharmony_ciuiContext.getFont();
37e41f4b71Sopenharmony_ci```
38e41f4b71Sopenharmony_ci### getComponentUtils
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_cigetComponentUtils(): ComponentUtils
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ciObtains the **ComponentUtils** object.
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci**Return value**
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci| Type                               | Description                   |
51e41f4b71Sopenharmony_ci| --------------------------------- | --------------------- |
52e41f4b71Sopenharmony_ci| [ComponentUtils](#componentutils) | **ComponentUtils** object. |
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci**Example**
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci```ts
57e41f4b71Sopenharmony_ciuiContext.getComponentUtils();
58e41f4b71Sopenharmony_ci```
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci### getUIInspector
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_cigetUIInspector(): UIInspector
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ciObtains the **UIInspector** object.
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**Return value**
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci| Type                         | Description                |
73e41f4b71Sopenharmony_ci| --------------------------- | ------------------ |
74e41f4b71Sopenharmony_ci| [UIInspector](#uiinspector) | **UIInspector** object. |
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci**Example**
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci```ts
79e41f4b71Sopenharmony_ciuiContext.getUIInspector();
80e41f4b71Sopenharmony_ci```
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci### getUIObserver<sup>11+</sup>
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_cigetUIObserver(): UIObserver
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ciObtains the **UIObserver** object.
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci**Return value**
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci| Type                         | Description                |
95e41f4b71Sopenharmony_ci| --------------------------- | ------------------ |
96e41f4b71Sopenharmony_ci| [UIObserver](#uiobserver11) | **UIObserver** object. |
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci**Example**
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ci```ts
101e41f4b71Sopenharmony_ciuiContext.getUIObserver();
102e41f4b71Sopenharmony_ci```
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci### getMediaQuery
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_cigetMediaQuery(): MediaQuery
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ciObtains a **MediaQuery** object.
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci**Return value**
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci| Type                       | Description               |
117e41f4b71Sopenharmony_ci| ------------------------- | ----------------- |
118e41f4b71Sopenharmony_ci| [MediaQuery](#mediaquery) | **MediaQuery** object. |
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ci**Example**
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci```ts
123e41f4b71Sopenharmony_ciuiContext.getMediaQuery();
124e41f4b71Sopenharmony_ci```
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci### getRouter
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_cigetRouter(): Router
129e41f4b71Sopenharmony_ci
130e41f4b71Sopenharmony_ciObtains a **Router** object.
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci**Return value**
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci| Type               | Description           |
139e41f4b71Sopenharmony_ci| ----------------- | ------------- |
140e41f4b71Sopenharmony_ci| [Router](#router) | **Router** object. |
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci**Example**
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci```ts
145e41f4b71Sopenharmony_ciuiContext.getRouter();
146e41f4b71Sopenharmony_ci```
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci### getPromptAction
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_cigetPromptAction(): PromptAction
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ciObtains a **PromptAction** object.
153e41f4b71Sopenharmony_ci
154e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci**Return value**
159e41f4b71Sopenharmony_ci
160e41f4b71Sopenharmony_ci| Type                           | Description                 |
161e41f4b71Sopenharmony_ci| ----------------------------- | ------------------- |
162e41f4b71Sopenharmony_ci| [PromptAction](#promptaction) | **PromptAction** object. |
163e41f4b71Sopenharmony_ci
164e41f4b71Sopenharmony_ci**Example**
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci```ts
167e41f4b71Sopenharmony_ciuiContext.getPromptAction();
168e41f4b71Sopenharmony_ci```
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ci### getOverlayManager<sup>12+</sup>
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_cigetOverlayManager(): OverlayManager
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ciObtains the **OverlayManager** object.
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci**Return value**
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci| Type                          | Description                |
183e41f4b71Sopenharmony_ci| ----------------------------- | ------------------- |
184e41f4b71Sopenharmony_ci| [OverlayManager](#overlaymanager12) | **OverlayManager** instance obtained. |
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci**Example**
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci```ts
189e41f4b71Sopenharmony_ciuiContext.getOverlayManager();
190e41f4b71Sopenharmony_ci```
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci### animateTo
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_cianimateTo(value: AnimateParam, event: () => void): void
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ciApplies a transition animation for state changes.
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
199e41f4b71Sopenharmony_ci
200e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci**Parameters**
203e41f4b71Sopenharmony_ci
204e41f4b71Sopenharmony_ci| Name  | Type                                      | Mandatory  | Description                                   |
205e41f4b71Sopenharmony_ci| ----- | ---------------------------------------- | ---- | ------------------------------------- |
206e41f4b71Sopenharmony_ci| value | [AnimateParam](arkui-ts/ts-explicit-animation.md#animateparam)  | Yes   | Animation settings.                          |
207e41f4b71Sopenharmony_ci| event | () => void                               | Yes   | Closure function that displays the animation. The system automatically inserts the transition animation if the state changes in the closure function. |
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_ci**Example**
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ci```ts
212e41f4b71Sopenharmony_ci// xxx.ets
213e41f4b71Sopenharmony_ci@Entry
214e41f4b71Sopenharmony_ci@Component
215e41f4b71Sopenharmony_cistruct AnimateToExample {
216e41f4b71Sopenharmony_ci  @State widthSize: number = 250
217e41f4b71Sopenharmony_ci  @State heightSize: number = 100
218e41f4b71Sopenharmony_ci  @State rotateAngle: number = 0
219e41f4b71Sopenharmony_ci  private flag: boolean = true
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci  build() {
222e41f4b71Sopenharmony_ci    Column() {
223e41f4b71Sopenharmony_ci      Button('change size')
224e41f4b71Sopenharmony_ci        .width(this.widthSize)
225e41f4b71Sopenharmony_ci        .height(this.heightSize)
226e41f4b71Sopenharmony_ci        .margin(30)
227e41f4b71Sopenharmony_ci        .onClick(() => {
228e41f4b71Sopenharmony_ci          if (this.flag) {
229e41f4b71Sopenharmony_ci            uiContext.animateTo({
230e41f4b71Sopenharmony_ci              duration: 2000,
231e41f4b71Sopenharmony_ci              curve: Curve.EaseOut,
232e41f4b71Sopenharmony_ci              iterations: 3,
233e41f4b71Sopenharmony_ci              playMode: PlayMode.Normal,
234e41f4b71Sopenharmony_ci              onFinish: () => {
235e41f4b71Sopenharmony_ci                console.info('play end')
236e41f4b71Sopenharmony_ci              }
237e41f4b71Sopenharmony_ci            }, () => {
238e41f4b71Sopenharmony_ci              this.widthSize = 150
239e41f4b71Sopenharmony_ci              this.heightSize = 60
240e41f4b71Sopenharmony_ci            })
241e41f4b71Sopenharmony_ci          } else {
242e41f4b71Sopenharmony_ci            uiContext.animateTo({}, () => {
243e41f4b71Sopenharmony_ci              this.widthSize = 250
244e41f4b71Sopenharmony_ci              this.heightSize = 100
245e41f4b71Sopenharmony_ci            })
246e41f4b71Sopenharmony_ci          }
247e41f4b71Sopenharmony_ci          this.flag = !this.flag
248e41f4b71Sopenharmony_ci        })
249e41f4b71Sopenharmony_ci      Button('change rotate angle')
250e41f4b71Sopenharmony_ci        .margin(50)
251e41f4b71Sopenharmony_ci        .rotate({ x: 0, y: 0, z: 1, angle: this.rotateAngle })
252e41f4b71Sopenharmony_ci        .onClick(() => {
253e41f4b71Sopenharmony_ci          uiContext.animateTo({
254e41f4b71Sopenharmony_ci            duration: 1200,
255e41f4b71Sopenharmony_ci            curve: Curve.Friction,
256e41f4b71Sopenharmony_ci            delay: 500,
257e41f4b71Sopenharmony_ci            iterations: -1, // The value -1 indicates that the animation is played for an unlimited number of times.
258e41f4b71Sopenharmony_ci            playMode: PlayMode.Alternate,
259e41f4b71Sopenharmony_ci            onFinish: () => {
260e41f4b71Sopenharmony_ci              console.info('play end')
261e41f4b71Sopenharmony_ci            }
262e41f4b71Sopenharmony_ci          }, () => {
263e41f4b71Sopenharmony_ci            this.rotateAngle = 90
264e41f4b71Sopenharmony_ci          })
265e41f4b71Sopenharmony_ci        })
266e41f4b71Sopenharmony_ci    }.width('100%').margin({ top: 5 })
267e41f4b71Sopenharmony_ci  }
268e41f4b71Sopenharmony_ci}
269e41f4b71Sopenharmony_ci```
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci### getSharedLocalStorage<sup>12+</sup>
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_cigetSharedLocalStorage(): LocalStorage | undefined
274e41f4b71Sopenharmony_ci
275e41f4b71Sopenharmony_ciObtains the **LocalStorage** instance shared by this stage.
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
280e41f4b71Sopenharmony_ci
281e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model.
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ci**Return value**
284e41f4b71Sopenharmony_ci
285e41f4b71Sopenharmony_ci| Type                            | Description               |
286e41f4b71Sopenharmony_ci| ------------------------------ | ----------------- |
287e41f4b71Sopenharmony_ci| [LocalStorage](arkui-ts/ts-state-management.md#localstorage9) \| undefined | **LocalStorage** instance if it exists; **undefined** if it does not exist. |
288e41f4b71Sopenharmony_ci
289e41f4b71Sopenharmony_ci**Example**
290e41f4b71Sopenharmony_ci
291e41f4b71Sopenharmony_ci```ts
292e41f4b71Sopenharmony_ci// index.ets
293e41f4b71Sopenharmony_ciimport { router } from '@kit.ArkUI';
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_ci@Entry
296e41f4b71Sopenharmony_ci@Component
297e41f4b71Sopenharmony_cistruct SharedLocalStorage {
298e41f4b71Sopenharmony_ci  localStorage = this.getUIContext().getSharedLocalStorage()
299e41f4b71Sopenharmony_ci
300e41f4b71Sopenharmony_ci  build() {
301e41f4b71Sopenharmony_ci    Row() {
302e41f4b71Sopenharmony_ci      Column() {
303e41f4b71Sopenharmony_ci        Button("Change Local Storage to 47")
304e41f4b71Sopenharmony_ci          .onClick(() => {
305e41f4b71Sopenharmony_ci            this.localStorage?.setOrCreate("propA",47)
306e41f4b71Sopenharmony_ci          })
307e41f4b71Sopenharmony_ci        Button("Get Local Storage")
308e41f4b71Sopenharmony_ci          .onClick(() => {
309e41f4b71Sopenharmony_ci            console.info(`localStorage: ${this.localStorage?.get("propA")}`)
310e41f4b71Sopenharmony_ci          })
311e41f4b71Sopenharmony_ci        Button("To Page")
312e41f4b71Sopenharmony_ci          .onClick(() => {
313e41f4b71Sopenharmony_ci            router.pushUrl({
314e41f4b71Sopenharmony_ci              url: 'pages/GetSharedLocalStorage'
315e41f4b71Sopenharmony_ci            })
316e41f4b71Sopenharmony_ci          })
317e41f4b71Sopenharmony_ci      }
318e41f4b71Sopenharmony_ci      .width('100%')
319e41f4b71Sopenharmony_ci    }
320e41f4b71Sopenharmony_ci    .height('100%')
321e41f4b71Sopenharmony_ci  }
322e41f4b71Sopenharmony_ci}
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ci// GetSharedLocalStorage.ets
325e41f4b71Sopenharmony_ciimport {router} from '@kit.ArkUI';
326e41f4b71Sopenharmony_ci
327e41f4b71Sopenharmony_ci@Entry
328e41f4b71Sopenharmony_ci@Component
329e41f4b71Sopenharmony_cistruct GetSharedLocalStorage {
330e41f4b71Sopenharmony_ci  localStorage = this.getUIContext().getSharedLocalStorage()
331e41f4b71Sopenharmony_ci
332e41f4b71Sopenharmony_ci  build() {
333e41f4b71Sopenharmony_ci    Row() {
334e41f4b71Sopenharmony_ci      Column() {
335e41f4b71Sopenharmony_ci        Button("Change Local Storage to 100")
336e41f4b71Sopenharmony_ci          .onClick(() => {
337e41f4b71Sopenharmony_ci            this.localStorage?.setOrCreate("propA",100)
338e41f4b71Sopenharmony_ci          })
339e41f4b71Sopenharmony_ci        Button("Get Local Storage")
340e41f4b71Sopenharmony_ci          .onClick(() => {
341e41f4b71Sopenharmony_ci            console.info(`localStorage: ${this.localStorage?.get("propA")}`)
342e41f4b71Sopenharmony_ci          })
343e41f4b71Sopenharmony_ci
344e41f4b71Sopenharmony_ci        Button("Back Index")
345e41f4b71Sopenharmony_ci          .onClick(() => {
346e41f4b71Sopenharmony_ci            router.back()
347e41f4b71Sopenharmony_ci          })
348e41f4b71Sopenharmony_ci      }
349e41f4b71Sopenharmony_ci      .width('100%')
350e41f4b71Sopenharmony_ci    }
351e41f4b71Sopenharmony_ci  }
352e41f4b71Sopenharmony_ci}
353e41f4b71Sopenharmony_ci```
354e41f4b71Sopenharmony_ci
355e41f4b71Sopenharmony_ci### getHostContext<sup>12+</sup>
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_cigetHostContext(): Context | undefined
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ciObtains the context of this ability.
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
364e41f4b71Sopenharmony_ci
365e41f4b71Sopenharmony_ci**Model restriction**: This API can be used only in the stage model.
366e41f4b71Sopenharmony_ci
367e41f4b71Sopenharmony_ci**Return value**
368e41f4b71Sopenharmony_ci
369e41f4b71Sopenharmony_ci| Type | Description                            |
370e41f4b71Sopenharmony_ci| ------ | ------------------------------- |
371e41f4b71Sopenharmony_ci| [Context](../../application-models/application-context-stage.md) \| undefined | Context of the ability. The context type depends on the ability type. For example, if this API is called on a page of the UIAbility, the return value type is UIAbilityContext; if this API is called on a page of the ExtensionAbility, the return value type is ExtensionContext. If the ability context does not exist, **undefined** is returned. |
372e41f4b71Sopenharmony_ci
373e41f4b71Sopenharmony_ci**Example**
374e41f4b71Sopenharmony_ci
375e41f4b71Sopenharmony_ci```ts
376e41f4b71Sopenharmony_ci@Entry
377e41f4b71Sopenharmony_ci@Component
378e41f4b71Sopenharmony_cistruct Index {
379e41f4b71Sopenharmony_ci  uiContext = this.getUIContext();
380e41f4b71Sopenharmony_ci
381e41f4b71Sopenharmony_ci  build() {
382e41f4b71Sopenharmony_ci    Row() {
383e41f4b71Sopenharmony_ci      Column() {
384e41f4b71Sopenharmony_ci        Text("cacheDir='"+this.uiContext?.getHostContext()?.cacheDir+"'").fontSize(25)
385e41f4b71Sopenharmony_ci        Text("bundleCodeDir='"+this.uiContext?.getHostContext()?.bundleCodeDir+"'").fontSize(25)
386e41f4b71Sopenharmony_ci      }
387e41f4b71Sopenharmony_ci      .width('100%')
388e41f4b71Sopenharmony_ci    }
389e41f4b71Sopenharmony_ci    .height('100%')
390e41f4b71Sopenharmony_ci  }
391e41f4b71Sopenharmony_ci}
392e41f4b71Sopenharmony_ci```
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ci### getFrameNodeById<sup>12+</sup>
395e41f4b71Sopenharmony_ci
396e41f4b71Sopenharmony_cigetFrameNodeById(id: string): FrameNode | null
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_ciObtains a FrameNode on the component tree based on the component ID.
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_ci**Parameters**
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ci| Name  | Type                                      | Mandatory  | Description                                   |
407e41f4b71Sopenharmony_ci| ----- | ---------------------------------------- | ---- | ------------------------------------- |
408e41f4b71Sopenharmony_ci| id | string | Yes   | [Component ID](arkui-ts/ts-universal-attributes-component-id.md) of the target node.                         |
409e41f4b71Sopenharmony_ci
410e41f4b71Sopenharmony_ci**Return value**
411e41f4b71Sopenharmony_ci
412e41f4b71Sopenharmony_ci| Type                                      | Description           |
413e41f4b71Sopenharmony_ci| ---------------------------------------- | ------------- |
414e41f4b71Sopenharmony_ci| [FrameNode](js-apis-arkui-frameNode.md)  \| null | FrameNode (if available) or null node. |
415e41f4b71Sopenharmony_ci
416e41f4b71Sopenharmony_ci**Example**
417e41f4b71Sopenharmony_ci
418e41f4b71Sopenharmony_ci```ts
419e41f4b71Sopenharmony_ciuiContext.getFrameNodeById("TestNode")
420e41f4b71Sopenharmony_ci```
421e41f4b71Sopenharmony_ci
422e41f4b71Sopenharmony_ci### getFrameNodeByUniqueId<sup>12+</sup>
423e41f4b71Sopenharmony_ci
424e41f4b71Sopenharmony_cigetFrameNodeByUniqueId(id: number): FrameNode | null
425e41f4b71Sopenharmony_ci
426e41f4b71Sopenharmony_ciObtains a FrameNode on the component tree based on the unique component ID.
427e41f4b71Sopenharmony_ci1. If the unique component ID corresponds to a built-in component, the FrameNode corresponding to the component is returned.
428e41f4b71Sopenharmony_ci2. If the unique component ID corresponds to a custom component: if the component has rendered content, the FrameNode of the component is returned. The type is __Common__. If the component does not have rendered content, the FrameNode of the first child component is returned.
429e41f4b71Sopenharmony_ci3. If the unique component ID does not have a corresponding component, **null** is returned.
430e41f4b71Sopenharmony_ci
431e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
432e41f4b71Sopenharmony_ci
433e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
434e41f4b71Sopenharmony_ci
435e41f4b71Sopenharmony_ci**Parameters**
436e41f4b71Sopenharmony_ci
437e41f4b71Sopenharmony_ci| Name  | Type                                      | Mandatory  | Description                                   |
438e41f4b71Sopenharmony_ci| ----- | ---------------------------------------- | ---- | ------------------------------------- |
439e41f4b71Sopenharmony_ci| id | number | Yes   | Unique ID of the target node.                         |
440e41f4b71Sopenharmony_ci
441e41f4b71Sopenharmony_ci**Return value**
442e41f4b71Sopenharmony_ci
443e41f4b71Sopenharmony_ci| Type                                      | Description           |
444e41f4b71Sopenharmony_ci| ---------------------------------------- | ------------- |
445e41f4b71Sopenharmony_ci| [FrameNode](js-apis-arkui-frameNode.md)  \| null | FrameNode (if available) or null node. |
446e41f4b71Sopenharmony_ci
447e41f4b71Sopenharmony_ci**Example**
448e41f4b71Sopenharmony_ci
449e41f4b71Sopenharmony_ci```ts
450e41f4b71Sopenharmony_ciimport { UIContext, FrameNode } from '@kit.ArkUI';
451e41f4b71Sopenharmony_ci
452e41f4b71Sopenharmony_ci@Entry
453e41f4b71Sopenharmony_ci@Component
454e41f4b71Sopenharmony_cistruct MyComponent {
455e41f4b71Sopenharmony_ci  aboutToAppear() {
456e41f4b71Sopenharmony_ci    let uniqueId: number = this.getUniqueId();
457e41f4b71Sopenharmony_ci    let uiContext: UIContext = this.getUIContext();
458e41f4b71Sopenharmony_ci    if (uiContext) {
459e41f4b71Sopenharmony_ci      let node: FrameNode | null = uiContext.getFrameNodeByUniqueId(uniqueId);
460e41f4b71Sopenharmony_ci    }
461e41f4b71Sopenharmony_ci  }
462e41f4b71Sopenharmony_ci
463e41f4b71Sopenharmony_ci  build() {
464e41f4b71Sopenharmony_ci    // ...
465e41f4b71Sopenharmony_ci  }
466e41f4b71Sopenharmony_ci}
467e41f4b71Sopenharmony_ci```
468e41f4b71Sopenharmony_ci
469e41f4b71Sopenharmony_ci### getPageInfoByUniqueId<sup>12+</sup>
470e41f4b71Sopenharmony_ci
471e41f4b71Sopenharmony_cigetPageInfoByUniqueId(id: number): PageInfo
472e41f4b71Sopenharmony_ci
473e41f4b71Sopenharmony_ciObtains the router or navigation destination page information corresponding to the node that matches the specified **uniqueId**.
474e41f4b71Sopenharmony_ci1. If the node that matches the specified **uniqueId** is in a page, the router information (**routerPageInfo**) is returned.
475e41f4b71Sopenharmony_ci2. If the node that matches the specified **uniqueId** is in a **NavDestination** component, the navigation destination page information (**navDestinationInfo**) is returned.
476e41f4b71Sopenharmony_ci3. If the node that matches the specified **uniqueId** does not have the corresponding router or navigation destination page information, **undefined** is returned.
477e41f4b71Sopenharmony_ci4. Modal dialog boxes are not contained within any pages. If the node that matches the specified **uniqueId** is in a modal dialog box, for example, on a modal page constructed by [CustomDialog](./arkui-ts/ts-methods-custom-dialog-box.md), [bindSheet](./arkui-ts/ts-universal-attributes-sheet-transition.md#bindsheet), or [bindContentCover](./arkui-ts/ts-universal-attributes-modal-transition.md#bindcontentcover), **undefined** is returned for **routerPageInfo**.
478e41f4b71Sopenharmony_ci
479e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
480e41f4b71Sopenharmony_ci
481e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
482e41f4b71Sopenharmony_ci
483e41f4b71Sopenharmony_ci**Parameters**
484e41f4b71Sopenharmony_ci
485e41f4b71Sopenharmony_ci| Name  | Type                                      | Mandatory  | Description                                   |
486e41f4b71Sopenharmony_ci| ----- | ---------------------------------------- | ---- | ------------------------------------- |
487e41f4b71Sopenharmony_ci| id | number | Yes   | Unique ID of the target node.                         |
488e41f4b71Sopenharmony_ci
489e41f4b71Sopenharmony_ci**Return value**
490e41f4b71Sopenharmony_ci
491e41f4b71Sopenharmony_ci| Type                                      | Description           |
492e41f4b71Sopenharmony_ci| ---------------------------------------- | ------------- |
493e41f4b71Sopenharmony_ci| [PageInfo](#pageinfo12) | Router or navigation destination page information corresponding to the specified node. |
494e41f4b71Sopenharmony_ci
495e41f4b71Sopenharmony_ci**Example**
496e41f4b71Sopenharmony_ci
497e41f4b71Sopenharmony_ci```ts
498e41f4b71Sopenharmony_ciimport { UIContext, PageInfo } from '@kit.ArkUI';
499e41f4b71Sopenharmony_ci
500e41f4b71Sopenharmony_ci@Entry
501e41f4b71Sopenharmony_ci@Component
502e41f4b71Sopenharmony_cistruct PageInfoExample {
503e41f4b71Sopenharmony_ci  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack();
504e41f4b71Sopenharmony_ci
505e41f4b71Sopenharmony_ci  build() {
506e41f4b71Sopenharmony_ci    Column() {
507e41f4b71Sopenharmony_ci      Navigation(this.pageInfos) {
508e41f4b71Sopenharmony_ci        NavDestination() {
509e41f4b71Sopenharmony_ci          MyComponent()
510e41f4b71Sopenharmony_ci        }
511e41f4b71Sopenharmony_ci      }.id('navigation')
512e41f4b71Sopenharmony_ci    }
513e41f4b71Sopenharmony_ci  }
514e41f4b71Sopenharmony_ci}
515e41f4b71Sopenharmony_ci
516e41f4b71Sopenharmony_ci@Component
517e41f4b71Sopenharmony_cistruct MyComponent {
518e41f4b71Sopenharmony_ci  @State content: string = '';
519e41f4b71Sopenharmony_ci
520e41f4b71Sopenharmony_ci  build() {
521e41f4b71Sopenharmony_ci    Column() {
522e41f4b71Sopenharmony_ci      Text('PageInfoExample')
523e41f4b71Sopenharmony_ci      Button('click').onClick(() => {
524e41f4b71Sopenharmony_ci        const uiContext: UIContext = this.getUIContext();
525e41f4b71Sopenharmony_ci        const uniqueId: number = this.getUniqueId();
526e41f4b71Sopenharmony_ci        const pageInfo: PageInfo = uiContext.getPageInfoByUniqueId(uniqueId);
527e41f4b71Sopenharmony_ci        console.info('pageInfo: ' + JSON.stringify(pageInfo));
528e41f4b71Sopenharmony_ci        console.info('navigationInfo: ' + JSON.stringify(uiContext.getNavigationInfoByUniqueId(uniqueId)));
529e41f4b71Sopenharmony_ci      })
530e41f4b71Sopenharmony_ci      TextArea({
531e41f4b71Sopenharmony_ci        text: this.content
532e41f4b71Sopenharmony_ci      })
533e41f4b71Sopenharmony_ci      .width('100%')
534e41f4b71Sopenharmony_ci      .height(100)
535e41f4b71Sopenharmony_ci    }
536e41f4b71Sopenharmony_ci    .width('100%')
537e41f4b71Sopenharmony_ci    .alignItems(HorizontalAlign.Center)
538e41f4b71Sopenharmony_ci  }
539e41f4b71Sopenharmony_ci}
540e41f4b71Sopenharmony_ci```
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ci### getNavigationInfoByUniqueId<sup>12+</sup>
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_cigetNavigationInfoByUniqueId(id: number): observer.NavigationInfo | undefined
545e41f4b71Sopenharmony_ci
546e41f4b71Sopenharmony_ciObtains the navigation information corresponding to the node that matches the specified **uniqueId**.
547e41f4b71Sopenharmony_ci1. If the node that matches the specified **uniqueId** is in a **Navigation** component, the navigation information is returned.
548e41f4b71Sopenharmony_ci2. If the node that matches the specified **uniqueId** does not have the corresponding navigation information, **undefined** is returned.
549e41f4b71Sopenharmony_ci
550e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
551e41f4b71Sopenharmony_ci
552e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
553e41f4b71Sopenharmony_ci
554e41f4b71Sopenharmony_ci**Parameters**
555e41f4b71Sopenharmony_ci
556e41f4b71Sopenharmony_ci| Name  | Type                                      | Mandatory  | Description                                   |
557e41f4b71Sopenharmony_ci| ----- | ---------------------------------------- | ---- | ------------------------------------- |
558e41f4b71Sopenharmony_ci| id | number | Yes   | Unique ID of the target node.                         |
559e41f4b71Sopenharmony_ci
560e41f4b71Sopenharmony_ci**Return value**
561e41f4b71Sopenharmony_ci
562e41f4b71Sopenharmony_ci| Type                                      | Description           |
563e41f4b71Sopenharmony_ci| ---------------------------------------- | ------------- |
564e41f4b71Sopenharmony_ci| observer.[NavigationInfo](js-apis-arkui-observer.md#navigationinfo12) \| undefined | Navigation information corresponding to the specified node. |
565e41f4b71Sopenharmony_ci
566e41f4b71Sopenharmony_ci**Example**
567e41f4b71Sopenharmony_ci
568e41f4b71Sopenharmony_ciSee the example of [getPageInfoByUniqueId](#getpageinfobyuniqueid12).
569e41f4b71Sopenharmony_ci
570e41f4b71Sopenharmony_ci### showAlertDialog
571e41f4b71Sopenharmony_ci
572e41f4b71Sopenharmony_cishowAlertDialog(options: AlertDialogParamWithConfirm | AlertDialogParamWithButtons | AlertDialogParamWithOptions): void
573e41f4b71Sopenharmony_ci
574e41f4b71Sopenharmony_ciShows an alert dialog box.
575e41f4b71Sopenharmony_ci
576e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
577e41f4b71Sopenharmony_ci
578e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
579e41f4b71Sopenharmony_ci
580e41f4b71Sopenharmony_ci**Parameters**
581e41f4b71Sopenharmony_ci
582e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description                 |
583e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------------------- |
584e41f4b71Sopenharmony_ci| options | [AlertDialogParamWithConfirm](arkui-ts/ts-methods-alert-dialog-box.md#alertdialogparamwithconfirm) \| [AlertDialogParamWithButtons](arkui-ts/ts-methods-alert-dialog-box.md#alertdialogparamwithbuttons) \| [AlertDialogParamWithOptions](arkui-ts/ts-methods-alert-dialog-box.md#alertdialogparamwithoptions10)  | Yes   | Shows an **\<AlertDialog>** component in the given settings. |
585e41f4b71Sopenharmony_ci
586e41f4b71Sopenharmony_ci
587e41f4b71Sopenharmony_ci**Example**
588e41f4b71Sopenharmony_ci
589e41f4b71Sopenharmony_ci```ts
590e41f4b71Sopenharmony_ciuiContext.showAlertDialog(
591e41f4b71Sopenharmony_ci  {
592e41f4b71Sopenharmony_ci    title: 'title',
593e41f4b71Sopenharmony_ci    message: 'text',
594e41f4b71Sopenharmony_ci    autoCancel: true,
595e41f4b71Sopenharmony_ci    alignment: DialogAlignment.Bottom,
596e41f4b71Sopenharmony_ci    offset: { dx: 0, dy: -20 },
597e41f4b71Sopenharmony_ci    gridCount: 3,
598e41f4b71Sopenharmony_ci    confirm: {
599e41f4b71Sopenharmony_ci      value: 'button',
600e41f4b71Sopenharmony_ci      action: () => {
601e41f4b71Sopenharmony_ci        console.info('Button-clicking callback')
602e41f4b71Sopenharmony_ci      }
603e41f4b71Sopenharmony_ci    },
604e41f4b71Sopenharmony_ci    cancel: () => {
605e41f4b71Sopenharmony_ci      console.info('Closed callbacks')
606e41f4b71Sopenharmony_ci    }
607e41f4b71Sopenharmony_ci  }
608e41f4b71Sopenharmony_ci)
609e41f4b71Sopenharmony_ci```
610e41f4b71Sopenharmony_ci
611e41f4b71Sopenharmony_ci### showActionSheet
612e41f4b71Sopenharmony_ci
613e41f4b71Sopenharmony_cishowActionSheet(value: ActionSheetOptions): void
614e41f4b71Sopenharmony_ci
615e41f4b71Sopenharmony_ciShows an action sheet in the given settings.
616e41f4b71Sopenharmony_ci
617e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
618e41f4b71Sopenharmony_ci
619e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
620e41f4b71Sopenharmony_ci
621e41f4b71Sopenharmony_ci**Parameters** 
622e41f4b71Sopenharmony_ci
623e41f4b71Sopenharmony_ci| Name | Type                                                        | Mandatory | Description                |
624e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ | ---- | -------------------- |
625e41f4b71Sopenharmony_ci| value  | [ActionSheetOptions](arkui-ts/ts-methods-action-sheet.md#actionsheetoptions)  | Yes  | Parameters of the action sheet. |
626e41f4b71Sopenharmony_ci
627e41f4b71Sopenharmony_ci**Example**
628e41f4b71Sopenharmony_ci
629e41f4b71Sopenharmony_ci```ts
630e41f4b71Sopenharmony_ciuiContext.showActionSheet({
631e41f4b71Sopenharmony_ci  title: 'ActionSheet title',
632e41f4b71Sopenharmony_ci  message: 'message',
633e41f4b71Sopenharmony_ci  autoCancel: true,
634e41f4b71Sopenharmony_ci  confirm: {
635e41f4b71Sopenharmony_ci    value: 'Confirm button',
636e41f4b71Sopenharmony_ci    action: () => {
637e41f4b71Sopenharmony_ci      console.info('Get Alert Dialog handled')
638e41f4b71Sopenharmony_ci    }
639e41f4b71Sopenharmony_ci  },
640e41f4b71Sopenharmony_ci  cancel: () => {
641e41f4b71Sopenharmony_ci    console.info('actionSheet canceled')
642e41f4b71Sopenharmony_ci  },
643e41f4b71Sopenharmony_ci  alignment: DialogAlignment.Bottom,
644e41f4b71Sopenharmony_ci  offset: { dx: 0, dy: -10 },
645e41f4b71Sopenharmony_ci  sheets: [
646e41f4b71Sopenharmony_ci    {
647e41f4b71Sopenharmony_ci      title: 'apples',
648e41f4b71Sopenharmony_ci      action: () => {
649e41f4b71Sopenharmony_ci        console.info('apples')
650e41f4b71Sopenharmony_ci      }
651e41f4b71Sopenharmony_ci    },
652e41f4b71Sopenharmony_ci    {
653e41f4b71Sopenharmony_ci      title: 'bananas',
654e41f4b71Sopenharmony_ci      action: () => {
655e41f4b71Sopenharmony_ci        console.info('bananas')
656e41f4b71Sopenharmony_ci      }
657e41f4b71Sopenharmony_ci    },
658e41f4b71Sopenharmony_ci    {
659e41f4b71Sopenharmony_ci      title: 'pears',
660e41f4b71Sopenharmony_ci      action: () => {
661e41f4b71Sopenharmony_ci        console.info('pears')
662e41f4b71Sopenharmony_ci      }
663e41f4b71Sopenharmony_ci    }
664e41f4b71Sopenharmony_ci  ]
665e41f4b71Sopenharmony_ci})
666e41f4b71Sopenharmony_ci```
667e41f4b71Sopenharmony_ci
668e41f4b71Sopenharmony_ci### showDatePickerDialog
669e41f4b71Sopenharmony_ci
670e41f4b71Sopenharmony_cishowDatePickerDialog(options: DatePickerDialogOptions): void
671e41f4b71Sopenharmony_ci
672e41f4b71Sopenharmony_ciShows a date picker dialog box in the given settings.
673e41f4b71Sopenharmony_ci
674e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
675e41f4b71Sopenharmony_ci
676e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
677e41f4b71Sopenharmony_ci
678e41f4b71Sopenharmony_ci**Parameters** 
679e41f4b71Sopenharmony_ci
680e41f4b71Sopenharmony_ci| Name | Type                                                        | Mandatory | Description                          |
681e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | ---- | ------------------------------ |
682e41f4b71Sopenharmony_ci| options | [DatePickerDialogOptions](arkui-ts/ts-methods-datepicker-dialog.md#datepickerdialogoptions)  | Yes  | Parameters of the date picker dialog box. |
683e41f4b71Sopenharmony_ci
684e41f4b71Sopenharmony_ci**Example**
685e41f4b71Sopenharmony_ci
686e41f4b71Sopenharmony_ci```ts
687e41f4b71Sopenharmony_cilet selectedDate: Date = new Date("2010-1-1")
688e41f4b71Sopenharmony_ciuiContext.showDatePickerDialog({
689e41f4b71Sopenharmony_ci  start: new Date("2000-1-1"),
690e41f4b71Sopenharmony_ci  end: new Date("2100-12-31"),
691e41f4b71Sopenharmony_ci  selected: selectedDate,
692e41f4b71Sopenharmony_ci  onAccept: (value: DatePickerResult) => {
693e41f4b71Sopenharmony_ci    // Use the setFullYear method to set the date when the OK button is touched. In this way, when the date picker dialog box is displayed again, the selected date is the date last confirmed.
694e41f4b71Sopenharmony_ci    selectedDate.setFullYear(Number(value.year), Number(value.month), Number(value.day))
695e41f4b71Sopenharmony_ci    console.info("DatePickerDialog:onAccept()" + JSON.stringify(value))
696e41f4b71Sopenharmony_ci  },
697e41f4b71Sopenharmony_ci  onCancel: () => {
698e41f4b71Sopenharmony_ci    console.info("DatePickerDialog:onCancel()")
699e41f4b71Sopenharmony_ci  },
700e41f4b71Sopenharmony_ci  onChange: (value: DatePickerResult) => {
701e41f4b71Sopenharmony_ci    console.info("DatePickerDialog:onChange()" + JSON.stringify(value))
702e41f4b71Sopenharmony_ci  }
703e41f4b71Sopenharmony_ci})
704e41f4b71Sopenharmony_ci```
705e41f4b71Sopenharmony_ci
706e41f4b71Sopenharmony_ci### showTimePickerDialog
707e41f4b71Sopenharmony_ci
708e41f4b71Sopenharmony_cishowTimePickerDialog(options: TimePickerDialogOptions): void
709e41f4b71Sopenharmony_ci
710e41f4b71Sopenharmony_ciShows a time picker dialog box in the given settings.
711e41f4b71Sopenharmony_ci
712e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
713e41f4b71Sopenharmony_ci
714e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
715e41f4b71Sopenharmony_ci
716e41f4b71Sopenharmony_ci**Parameters** 
717e41f4b71Sopenharmony_ci
718e41f4b71Sopenharmony_ci| Name | Type                                                        | Mandatory | Description                          |
719e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | ---- | ------------------------------ |
720e41f4b71Sopenharmony_ci| options | [TimePickerDialogOptions](arkui-ts/ts-methods-timepicker-dialog.md#timepickerdialogoptions)  | Yes  | Parameters of the time picker dialog box. |
721e41f4b71Sopenharmony_ci
722e41f4b71Sopenharmony_ci**Example**
723e41f4b71Sopenharmony_ci
724e41f4b71Sopenharmony_ci```ts
725e41f4b71Sopenharmony_ci// xxx.ets
726e41f4b71Sopenharmony_ci
727e41f4b71Sopenharmony_ciclass SelectTime{
728e41f4b71Sopenharmony_ci  selectTime: Date = new Date('2020-12-25T08:30:00')
729e41f4b71Sopenharmony_ci  hours(h:number,m:number){
730e41f4b71Sopenharmony_ci    this.selectTime.setHours(h,m)
731e41f4b71Sopenharmony_ci  }
732e41f4b71Sopenharmony_ci}
733e41f4b71Sopenharmony_ci
734e41f4b71Sopenharmony_ci@Entry
735e41f4b71Sopenharmony_ci@Component
736e41f4b71Sopenharmony_cistruct TimePickerDialogExample {
737e41f4b71Sopenharmony_ci  @State selectTime: Date = new Date('2023-12-25T08:30:00');
738e41f4b71Sopenharmony_ci
739e41f4b71Sopenharmony_ci  build() {
740e41f4b71Sopenharmony_ci    Column() {
741e41f4b71Sopenharmony_ci      Button('showTimePickerDialog')
742e41f4b71Sopenharmony_ci        .margin(30)
743e41f4b71Sopenharmony_ci        .onClick(() => {
744e41f4b71Sopenharmony_ci          this.getUIContext().showTimePickerDialog({
745e41f4b71Sopenharmony_ci            selected: this.selectTime,
746e41f4b71Sopenharmony_ci            onAccept: (value: TimePickerResult) => {
747e41f4b71Sopenharmony_ci              // Set selectTime to the time when the OK button is clicked. In this way, when the dialog box is displayed again, the selected time is the time when the operation was confirmed last time.
748e41f4b71Sopenharmony_ci              let time = new SelectTime()
749e41f4b71Sopenharmony_ci              if(value.hour&&value.minute){
750e41f4b71Sopenharmony_ci                time.hours(value.hour, value.minute)
751e41f4b71Sopenharmony_ci              }
752e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onAccept()" + JSON.stringify(value))
753e41f4b71Sopenharmony_ci            },
754e41f4b71Sopenharmony_ci            onCancel: () => {
755e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onCancel()")
756e41f4b71Sopenharmony_ci            },
757e41f4b71Sopenharmony_ci            onChange: (value: TimePickerResult) => {
758e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onChange()" + JSON.stringify(value))
759e41f4b71Sopenharmony_ci            }
760e41f4b71Sopenharmony_ci          })
761e41f4b71Sopenharmony_ci        })
762e41f4b71Sopenharmony_ci    }.width('100%').margin({ top: 5 })
763e41f4b71Sopenharmony_ci  }
764e41f4b71Sopenharmony_ci}
765e41f4b71Sopenharmony_ci```
766e41f4b71Sopenharmony_ci
767e41f4b71Sopenharmony_ci### showTextPickerDialog
768e41f4b71Sopenharmony_ci
769e41f4b71Sopenharmony_cishowTextPickerDialog(options: TextPickerDialogOptions): void
770e41f4b71Sopenharmony_ci
771e41f4b71Sopenharmony_ciShows a text picker dialog box in the given settings.
772e41f4b71Sopenharmony_ci
773e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
774e41f4b71Sopenharmony_ci
775e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
776e41f4b71Sopenharmony_ci
777e41f4b71Sopenharmony_ci**Parameters** 
778e41f4b71Sopenharmony_ci
779e41f4b71Sopenharmony_ci| Name | Type                                                        | Mandatory | Description                          |
780e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | ---- | ------------------------------ |
781e41f4b71Sopenharmony_ci| options | [TextPickerDialogOptions](arkui-ts/ts-methods-textpicker-dialog.md#textpickerdialogoptions)  | Yes  | Parameters of the text picker dialog box. |
782e41f4b71Sopenharmony_ci
783e41f4b71Sopenharmony_ci**Example**
784e41f4b71Sopenharmony_ci
785e41f4b71Sopenharmony_ci```ts
786e41f4b71Sopenharmony_ci// xxx.ets
787e41f4b71Sopenharmony_ci
788e41f4b71Sopenharmony_ciclass SelectedValue{
789e41f4b71Sopenharmony_ci  select: number = 2
790e41f4b71Sopenharmony_ci  set(val:number){
791e41f4b71Sopenharmony_ci    this.select = val
792e41f4b71Sopenharmony_ci  }
793e41f4b71Sopenharmony_ci}
794e41f4b71Sopenharmony_ciclass SelectedArray{
795e41f4b71Sopenharmony_ci  select: number[] = []
796e41f4b71Sopenharmony_ci  set(val:number[]){
797e41f4b71Sopenharmony_ci    this.select = val
798e41f4b71Sopenharmony_ci  }
799e41f4b71Sopenharmony_ci}
800e41f4b71Sopenharmony_ci@Entry
801e41f4b71Sopenharmony_ci@Component
802e41f4b71Sopenharmony_cistruct TextPickerDialogExample {
803e41f4b71Sopenharmony_ci  @State selectTime: Date = new Date('2023-12-25T08:30:00');
804e41f4b71Sopenharmony_ci  private fruits: string[] = ['apple1', 'orange2', 'peach3', 'grape4', 'banana5']
805e41f4b71Sopenharmony_ci  private select : number  = 0;
806e41f4b71Sopenharmony_ci  build() {
807e41f4b71Sopenharmony_ci    Column() {
808e41f4b71Sopenharmony_ci      Button('showTextPickerDialog')
809e41f4b71Sopenharmony_ci        .margin(30)
810e41f4b71Sopenharmony_ci        .onClick(() => {
811e41f4b71Sopenharmony_ci          this.getUIContext().showTextPickerDialog({
812e41f4b71Sopenharmony_ci            range: this.fruits,
813e41f4b71Sopenharmony_ci            selected: this.select,
814e41f4b71Sopenharmony_ci            onAccept: (value: TextPickerResult) => {
815e41f4b71Sopenharmony_ci              // Set select to the index of the item selected when the OK button is touched. In this way, when the text picker dialog box is displayed again, the selected item is the one last confirmed.
816e41f4b71Sopenharmony_ci              let selectedVal = new SelectedValue()
817e41f4b71Sopenharmony_ci              let selectedArr = new SelectedArray()
818e41f4b71Sopenharmony_ci              if(value.index){
819e41f4b71Sopenharmony_ci                  value.index instanceof Array?selectedArr.set(value.index) : selectedVal.set(value.index)
820e41f4b71Sopenharmony_ci              }
821e41f4b71Sopenharmony_ci              console.info("TextPickerDialog:onAccept()" + JSON.stringify(value))
822e41f4b71Sopenharmony_ci            },
823e41f4b71Sopenharmony_ci            onCancel: () => {
824e41f4b71Sopenharmony_ci              console.info("TextPickerDialog:onCancel()")
825e41f4b71Sopenharmony_ci            },
826e41f4b71Sopenharmony_ci            onChange: (value: TextPickerResult) => {
827e41f4b71Sopenharmony_ci              console.info("TextPickerDialog:onChange()" + JSON.stringify(value))
828e41f4b71Sopenharmony_ci            }
829e41f4b71Sopenharmony_ci          })
830e41f4b71Sopenharmony_ci        })
831e41f4b71Sopenharmony_ci    }.width('100%').margin({ top: 5 })
832e41f4b71Sopenharmony_ci  }
833e41f4b71Sopenharmony_ci}
834e41f4b71Sopenharmony_ci```
835e41f4b71Sopenharmony_ci
836e41f4b71Sopenharmony_ci### createAnimator
837e41f4b71Sopenharmony_ci
838e41f4b71Sopenharmony_cicreateAnimator(options: AnimatorOptions): AnimatorResult
839e41f4b71Sopenharmony_ci
840e41f4b71Sopenharmony_ciCreates an **Animator** object.
841e41f4b71Sopenharmony_ci
842e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
843e41f4b71Sopenharmony_ci
844e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
845e41f4b71Sopenharmony_ci
846e41f4b71Sopenharmony_ci**Parameters**
847e41f4b71Sopenharmony_ci
848e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description     |
849e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------- |
850e41f4b71Sopenharmony_ci| options | [AnimatorOptions](js-apis-animator.md#animatoroptions) | Yes   | Animator options. |
851e41f4b71Sopenharmony_ci
852e41f4b71Sopenharmony_ci**Return value**
853e41f4b71Sopenharmony_ci
854e41f4b71Sopenharmony_ci| Type                                      | Description           |
855e41f4b71Sopenharmony_ci| ---------------------------------------- | ------------- |
856e41f4b71Sopenharmony_ci| [AnimatorResult](js-apis-animator.md#animatorresult) | Animator result. |
857e41f4b71Sopenharmony_ci
858e41f4b71Sopenharmony_ci
859e41f4b71Sopenharmony_ci**Error codes**
860e41f4b71Sopenharmony_ci
861e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
862e41f4b71Sopenharmony_ci
863e41f4b71Sopenharmony_ci| ID | Error Message |
864e41f4b71Sopenharmony_ci| ------- | -------- |
865e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
866e41f4b71Sopenharmony_ci
867e41f4b71Sopenharmony_ci**Example**
868e41f4b71Sopenharmony_ci
869e41f4b71Sopenharmony_ci```ts
870e41f4b71Sopenharmony_ciimport { AnimatorOptions, window } from '@kit.ArkUI';
871e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
872e41f4b71Sopenharmony_ci
873e41f4b71Sopenharmony_ci// used in UIAbility
874e41f4b71Sopenharmony_cionWindowStageCreate(windowStage: window.WindowStage) {
875e41f4b71Sopenharmony_ci  // Main window is created, set main page for this ability
876e41f4b71Sopenharmony_ci  hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
877e41f4b71Sopenharmony_ci  windowStage.loadContent('pages/Index', (err, data) => {
878e41f4b71Sopenharmony_ci    if (err.code) {
879e41f4b71Sopenharmony_ci      hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
880e41f4b71Sopenharmony_ci      return;
881e41f4b71Sopenharmony_ci    }
882e41f4b71Sopenharmony_ci    hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
883e41f4b71Sopenharmony_ci    let uiContext = windowStage.getMainWindowSync().getUIContext();
884e41f4b71Sopenharmony_ci    let options:AnimatorOptions = {
885e41f4b71Sopenharmony_ci      duration: 1500,
886e41f4b71Sopenharmony_ci      easing: "friction",
887e41f4b71Sopenharmony_ci      delay: 0,
888e41f4b71Sopenharmony_ci      fill: "forwards",
889e41f4b71Sopenharmony_ci      direction: "normal",
890e41f4b71Sopenharmony_ci      iterations: 3,
891e41f4b71Sopenharmony_ci      begin: 200.0,
892e41f4b71Sopenharmony_ci      end: 400.0
893e41f4b71Sopenharmony_ci    };
894e41f4b71Sopenharmony_ci    uiContext.createAnimator(options);
895e41f4b71Sopenharmony_ci  });
896e41f4b71Sopenharmony_ci}
897e41f4b71Sopenharmony_ci```
898e41f4b71Sopenharmony_ci
899e41f4b71Sopenharmony_ci### runScopedTask
900e41f4b71Sopenharmony_ci
901e41f4b71Sopenharmony_cirunScopedTask(callback: () => void): void
902e41f4b71Sopenharmony_ci
903e41f4b71Sopenharmony_ciExecutes the specified callback in this UI context.
904e41f4b71Sopenharmony_ci
905e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
906e41f4b71Sopenharmony_ci
907e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
908e41f4b71Sopenharmony_ci
909e41f4b71Sopenharmony_ci**Parameters**
910e41f4b71Sopenharmony_ci
911e41f4b71Sopenharmony_ci| Name     | Type        | Mandatory  | Description  |
912e41f4b71Sopenharmony_ci| -------- | ---------- | ---- | ---- |
913e41f4b71Sopenharmony_ci| callback | () => void | Yes   | Callback used to return the result. |
914e41f4b71Sopenharmony_ci
915e41f4b71Sopenharmony_ci**Example**
916e41f4b71Sopenharmony_ci
917e41f4b71Sopenharmony_ci```ts
918e41f4b71Sopenharmony_ciuiContext.runScopedTask(
919e41f4b71Sopenharmony_ci  () => {
920e41f4b71Sopenharmony_ci    console.info('Succeeded in runScopedTask');
921e41f4b71Sopenharmony_ci  }
922e41f4b71Sopenharmony_ci);
923e41f4b71Sopenharmony_ci```
924e41f4b71Sopenharmony_ci
925e41f4b71Sopenharmony_ci### setKeyboardAvoidMode<sup>11+</sup>
926e41f4b71Sopenharmony_ci
927e41f4b71Sopenharmony_cisetKeyboardAvoidMode(value: KeyboardAvoidMode): void
928e41f4b71Sopenharmony_ci
929e41f4b71Sopenharmony_ciSets the avoidance mode for the virtual keyboard.
930e41f4b71Sopenharmony_ci
931e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
932e41f4b71Sopenharmony_ci
933e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
934e41f4b71Sopenharmony_ci
935e41f4b71Sopenharmony_ci**Parameters**
936e41f4b71Sopenharmony_ci
937e41f4b71Sopenharmony_ci| Name     | Type        | Mandatory  | Description  |
938e41f4b71Sopenharmony_ci| -------- | ---------- | ---- | ---- |
939e41f4b71Sopenharmony_ci| value | [KeyboardAvoidMode](#keyboardavoidmode11)| Yes   | Avoidance mode for the virtual keyboard.<br>Default value: **KeyboardAvoidMode.OFFSET** |
940e41f4b71Sopenharmony_ci
941e41f4b71Sopenharmony_ci**Example**
942e41f4b71Sopenharmony_ci
943e41f4b71Sopenharmony_ci```ts
944e41f4b71Sopenharmony_ciimport { KeyboardAvoidMode, UIContext } from '@kit.ArkUI';
945e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
946e41f4b71Sopenharmony_ci
947e41f4b71Sopenharmony_cionWindowStageCreate(windowStage: window.WindowStage) {
948e41f4b71Sopenharmony_ci    // Main window is created, set main page for this ability
949e41f4b71Sopenharmony_ci    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
950e41f4b71Sopenharmony_ci
951e41f4b71Sopenharmony_ci    windowStage.loadContent('pages/Index', (err, data) => {
952e41f4b71Sopenharmony_ci      let uiContext :UIContext = windowStage.getMainWindowSync().getUIContext();
953e41f4b71Sopenharmony_ci      uiContext.setKeyboardAvoidMode(KeyboardAvoidMode.RESIZE);
954e41f4b71Sopenharmony_ci      if (err.code) {
955e41f4b71Sopenharmony_ci        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
956e41f4b71Sopenharmony_ci        return;
957e41f4b71Sopenharmony_ci      }
958e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
959e41f4b71Sopenharmony_ci    });
960e41f4b71Sopenharmony_ci  }
961e41f4b71Sopenharmony_ci```
962e41f4b71Sopenharmony_ci
963e41f4b71Sopenharmony_ci### getKeyboardAvoidMode<sup>11+</sup>
964e41f4b71Sopenharmony_ci
965e41f4b71Sopenharmony_cigetKeyboardAvoidMode(): KeyboardAvoidMode
966e41f4b71Sopenharmony_ci
967e41f4b71Sopenharmony_ciObtains the avoidance mode for the virtual keyboard.
968e41f4b71Sopenharmony_ci
969e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
970e41f4b71Sopenharmony_ci
971e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
972e41f4b71Sopenharmony_ci
973e41f4b71Sopenharmony_ci**Return value**
974e41f4b71Sopenharmony_ci
975e41f4b71Sopenharmony_ci| Type        | Description  |
976e41f4b71Sopenharmony_ci| ---------- | ---- |
977e41f4b71Sopenharmony_ci| [KeyboardAvoidMode](#keyboardavoidmode11)| Avoidance mode for the virtual keyboard.|
978e41f4b71Sopenharmony_ci
979e41f4b71Sopenharmony_ci**Example**
980e41f4b71Sopenharmony_ci
981e41f4b71Sopenharmony_ci```ts
982e41f4b71Sopenharmony_ciimport { KeyboardAvoidMode, UIContext } from '@kit.ArkUI';
983e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
984e41f4b71Sopenharmony_ci
985e41f4b71Sopenharmony_cionWindowStageCreate(windowStage: window.WindowStage) {
986e41f4b71Sopenharmony_ci    // Main window is created, set main page for this ability
987e41f4b71Sopenharmony_ci    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
988e41f4b71Sopenharmony_ci
989e41f4b71Sopenharmony_ci    windowStage.loadContent('pages/Index', (err, data) => {
990e41f4b71Sopenharmony_ci      let uiContext :UIContext = windowStage.getMainWindowSync().getUIContext();
991e41f4b71Sopenharmony_ci      let KeyboardAvoidMode = uiContext.getKeyboardAvoidMode();
992e41f4b71Sopenharmony_ci      hilog.info(0x0000, "KeyboardAvoidMode:", JSON.stringify(KeyboardAvoidMode));
993e41f4b71Sopenharmony_ci      if (err.code) {
994e41f4b71Sopenharmony_ci        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
995e41f4b71Sopenharmony_ci        return;
996e41f4b71Sopenharmony_ci      }
997e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
998e41f4b71Sopenharmony_ci    });
999e41f4b71Sopenharmony_ci  }
1000e41f4b71Sopenharmony_ci
1001e41f4b71Sopenharmony_ci```
1002e41f4b71Sopenharmony_ci
1003e41f4b71Sopenharmony_ci### getAtomicServiceBar<sup>11+</sup>
1004e41f4b71Sopenharmony_ci
1005e41f4b71Sopenharmony_cigetAtomicServiceBar(): Nullable\<AtomicServiceBar>
1006e41f4b71Sopenharmony_ci
1007e41f4b71Sopenharmony_ciObtains an **AtomicServiceBar** object, which can be used to set the properties of the atomic service menu bar.
1008e41f4b71Sopenharmony_ci
1009e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
1010e41f4b71Sopenharmony_ci
1011e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1012e41f4b71Sopenharmony_ci
1013e41f4b71Sopenharmony_ci**Return value**
1014e41f4b71Sopenharmony_ci
1015e41f4b71Sopenharmony_ci| Type                                             | Description                                                        |
1016e41f4b71Sopenharmony_ci| ------------------------------------------------- | ------------------------------------------------------------ |
1017e41f4b71Sopenharmony_ci| Nullable<[AtomicServiceBar](#atomicservicebar11)> | Returns the **AtomicServerBar** type if the service is an atomic service; returns **undefined** type otherwise. |
1018e41f4b71Sopenharmony_ci
1019e41f4b71Sopenharmony_ci**Example**
1020e41f4b71Sopenharmony_ci
1021e41f4b71Sopenharmony_ci```ts
1022e41f4b71Sopenharmony_ciimport { UIContext, AtomicServiceBar, window } from '@kit.ArkUI';
1023e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
1024e41f4b71Sopenharmony_cionWindowStageCreate(windowStage: window.WindowStage) {
1025e41f4b71Sopenharmony_ci  // Main window is created, set main page for this ability
1026e41f4b71Sopenharmony_ci  hilog.info(0x0000, 'testTag', 'Ability onWindowStageCreate');
1027e41f4b71Sopenharmony_ci  windowStage.loadContent('pages/Index', (err, data) => {
1028e41f4b71Sopenharmony_ci    let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext();
1029e41f4b71Sopenharmony_ci    let atomicServiceBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar();
1030e41f4b71Sopenharmony_ci    if (atomicServiceBar != undefined) {
1031e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Get AtomServiceBar Successfully.');
1032e41f4b71Sopenharmony_ci    } else {
1033e41f4b71Sopenharmony_ci      hilog.error(0x0000, 'testTag', 'Get AtomicServiceBar failed.');
1034e41f4b71Sopenharmony_ci    }
1035e41f4b71Sopenharmony_ci  });
1036e41f4b71Sopenharmony_ci}
1037e41f4b71Sopenharmony_ci```
1038e41f4b71Sopenharmony_ci### getDragController<sup>11+</sup>
1039e41f4b71Sopenharmony_ci
1040e41f4b71Sopenharmony_cigetDragController(): DragController
1041e41f4b71Sopenharmony_ci
1042e41f4b71Sopenharmony_ciObtains the **DragController** object, which can be used to create and initiate dragging.
1043e41f4b71Sopenharmony_ci
1044e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1045e41f4b71Sopenharmony_ci
1046e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1047e41f4b71Sopenharmony_ci
1048e41f4b71Sopenharmony_ci**Return value**
1049e41f4b71Sopenharmony_ci
1050e41f4b71Sopenharmony_ci|Type|Description|
1051e41f4b71Sopenharmony_ci|----|----|
1052e41f4b71Sopenharmony_ci|[DragController](js-apis-arkui-dragController.md)| **DragController** object.|
1053e41f4b71Sopenharmony_ci
1054e41f4b71Sopenharmony_ci**Example**
1055e41f4b71Sopenharmony_ci
1056e41f4b71Sopenharmony_ci```ts
1057e41f4b71Sopenharmony_ciuiContext.getDragController();
1058e41f4b71Sopenharmony_ci```
1059e41f4b71Sopenharmony_ci
1060e41f4b71Sopenharmony_ci### getDragPreview<sup>11+</sup>
1061e41f4b71Sopenharmony_ci
1062e41f4b71Sopenharmony_cigetDragPreview(): dragController.DragPreview
1063e41f4b71Sopenharmony_ci
1064e41f4b71Sopenharmony_ciObtains the **DragPreview** object, which represents the preview displayed during a drag.
1065e41f4b71Sopenharmony_ci
1066e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1067e41f4b71Sopenharmony_ci
1068e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1069e41f4b71Sopenharmony_ci
1070e41f4b71Sopenharmony_ci**Return value** 
1071e41f4b71Sopenharmony_ci
1072e41f4b71Sopenharmony_ci| Type                                                        | Description                                                        |
1073e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------------ |
1074e41f4b71Sopenharmony_ci| [dragController.DragPreview](js-apis-arkui-dragController.md#dragpreview11) | **DragPreview** object. It provides the API for setting the preview style. It does not work in the **OnDrop** and **OnDragEnd** callbacks. |
1075e41f4b71Sopenharmony_ci
1076e41f4b71Sopenharmony_ci**Error codes**: For details about universal error codes, see [Universal Error Codes](../errorcode-universal.md).
1077e41f4b71Sopenharmony_ci
1078e41f4b71Sopenharmony_ci**Example**
1079e41f4b71Sopenharmony_ci
1080e41f4b71Sopenharmony_ciFor details, see [animate](js-apis-arkui-dragController.md#animate11).
1081e41f4b71Sopenharmony_ci
1082e41f4b71Sopenharmony_ci### keyframeAnimateTo<sup>11+</sup>
1083e41f4b71Sopenharmony_ci
1084e41f4b71Sopenharmony_cikeyframeAnimateTo(param: KeyframeAnimateParam, keyframes: Array&lt;KeyframeState&gt;): void
1085e41f4b71Sopenharmony_ci
1086e41f4b71Sopenharmony_ciGenerates a key frame animation. For details about how to use this API, see [keyframeAnimateTo](arkui-ts/ts-keyframeAnimateTo.md).
1087e41f4b71Sopenharmony_ci
1088e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1089e41f4b71Sopenharmony_ci
1090e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1091e41f4b71Sopenharmony_ci
1092e41f4b71Sopenharmony_ci**Parameters**
1093e41f4b71Sopenharmony_ci
1094e41f4b71Sopenharmony_ci| Name | Type                                             | Mandatory | Description                     |
1095e41f4b71Sopenharmony_ci| ------------ | ---------------------------------------------------- | ------- | ---------------------------- |
1096e41f4b71Sopenharmony_ci| param        | [KeyframeAnimateParam](arkui-ts/ts-keyframeAnimateTo.md#keyframeanimateparam)  | Yes     | Overall animation parameter of the keyframe animation.    |
1097e41f4b71Sopenharmony_ci| keyframes    | Array&lt;[KeyframeState](arkui-ts/ts-keyframeAnimateTo.md#keyframestate)&gt;  | Yes     | States of all keyframes.           |
1098e41f4b71Sopenharmony_ci
1099e41f4b71Sopenharmony_ci### getFocusController<sup>12+</sup>
1100e41f4b71Sopenharmony_ci
1101e41f4b71Sopenharmony_cigetFocusController(): FocusController
1102e41f4b71Sopenharmony_ci
1103e41f4b71Sopenharmony_ciObtains a [FocusController](js-apis-arkui-UIContext.md#focuscontroller12) object, which can be used to control the focus.
1104e41f4b71Sopenharmony_ci
1105e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1106e41f4b71Sopenharmony_ci
1107e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1108e41f4b71Sopenharmony_ci
1109e41f4b71Sopenharmony_ci**Return value**
1110e41f4b71Sopenharmony_ci
1111e41f4b71Sopenharmony_ci|Type|Description|
1112e41f4b71Sopenharmony_ci|----|----|
1113e41f4b71Sopenharmony_ci|[FocusController](js-apis-arkui-UIContext.md#focuscontroller12)| **FocusController** object.|
1114e41f4b71Sopenharmony_ci
1115e41f4b71Sopenharmony_ci**Example**
1116e41f4b71Sopenharmony_ci
1117e41f4b71Sopenharmony_ci```ts
1118e41f4b71Sopenharmony_ciuiContext.getFocusController();
1119e41f4b71Sopenharmony_ci```
1120e41f4b71Sopenharmony_ci
1121e41f4b71Sopenharmony_ci### getFilteredInspectorTree<sup>12+</sup>
1122e41f4b71Sopenharmony_ci
1123e41f4b71Sopenharmony_cigetFilteredInspectorTree(filters?: Array\<string\>): string
1124e41f4b71Sopenharmony_ci
1125e41f4b71Sopenharmony_ciObtains the component tree and component attributes.
1126e41f4b71Sopenharmony_ci
1127e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1128e41f4b71Sopenharmony_ci
1129e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1130e41f4b71Sopenharmony_ci
1131e41f4b71Sopenharmony_ci**Parameters**
1132e41f4b71Sopenharmony_ci
1133e41f4b71Sopenharmony_ci| Name | Type           | Mandatory | Description                                                        |
1134e41f4b71Sopenharmony_ci| ------- | --------------- | ---- | ------------------------------------------------------------ |
1135e41f4b71Sopenharmony_ci| filters | Array\<string\> | No  | List of component attributes used for filtering. Currently, only the following attributes are supported: "id", "src", "content", "editable", "scrollable", "selectable", "focusable", "focused". |
1136e41f4b71Sopenharmony_ci
1137e41f4b71Sopenharmony_ci**Return value** 
1138e41f4b71Sopenharmony_ci
1139e41f4b71Sopenharmony_ci| Type  | Description                              |
1140e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
1141e41f4b71Sopenharmony_ci| string | JSON string of the component tree and component attributes. |
1142e41f4b71Sopenharmony_ci
1143e41f4b71Sopenharmony_ci
1144e41f4b71Sopenharmony_ci**Error codes**
1145e41f4b71Sopenharmony_ci
1146e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1147e41f4b71Sopenharmony_ci
1148e41f4b71Sopenharmony_ci| ID | Error Message |
1149e41f4b71Sopenharmony_ci| ------- | -------- |
1150e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
1151e41f4b71Sopenharmony_ci
1152e41f4b71Sopenharmony_ci**Example**
1153e41f4b71Sopenharmony_ci
1154e41f4b71Sopenharmony_ci```ts
1155e41f4b71Sopenharmony_ciuiContext.getFilteredInspectorTree(['id', 'src', 'content']);
1156e41f4b71Sopenharmony_ci```
1157e41f4b71Sopenharmony_ci
1158e41f4b71Sopenharmony_ci### getFilteredInspectorTreeById<sup>12+</sup>
1159e41f4b71Sopenharmony_ci
1160e41f4b71Sopenharmony_cigetFilteredInspectorTreeById(id: string, depth: number, filters?: Array\<string\>): string
1161e41f4b71Sopenharmony_ci
1162e41f4b71Sopenharmony_ciObtains the attributes of the specified component and its child components.
1163e41f4b71Sopenharmony_ci
1164e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1165e41f4b71Sopenharmony_ci
1166e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1167e41f4b71Sopenharmony_ci
1168e41f4b71Sopenharmony_ci**Parameters**
1169e41f4b71Sopenharmony_ci
1170e41f4b71Sopenharmony_ci| Name | Type           | Mandatory | Description                                                        |
1171e41f4b71Sopenharmony_ci| ------- | --------------- | ---- | ------------------------------------------------------------ |
1172e41f4b71Sopenharmony_ci| id      | string          | Yes  | [ID](arkui-ts/ts-universal-attributes-component-id.md) of the target component. |
1173e41f4b71Sopenharmony_ci| depth   | number          | Yes  | Number of layers of child components. If the value is **0**, the attributes of the specified component and all its child components are obtained. If the value is **1**, only the attributes of the specified component are obtained. If the value is **2**, the attributes of the specified component and its level-1 child components are obtained. The rest can be deduced by analogy. |
1174e41f4b71Sopenharmony_ci| filters | Array\<string\> | No  | List of component attributes used for filtering. Currently, only the following attributes are supported: "id", "src", "content", "editable", "scrollable", "selectable", "focusable", "focused". |
1175e41f4b71Sopenharmony_ci
1176e41f4b71Sopenharmony_ci**Return value** 
1177e41f4b71Sopenharmony_ci
1178e41f4b71Sopenharmony_ci| Type  | Description                                        |
1179e41f4b71Sopenharmony_ci| ------ | -------------------------------------------- |
1180e41f4b71Sopenharmony_ci| string | JSON string of the attributes of the specified component and its child components. |
1181e41f4b71Sopenharmony_ci
1182e41f4b71Sopenharmony_ci
1183e41f4b71Sopenharmony_ci**Error codes**
1184e41f4b71Sopenharmony_ci
1185e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1186e41f4b71Sopenharmony_ci
1187e41f4b71Sopenharmony_ci| ID | Error Message |
1188e41f4b71Sopenharmony_ci| ------- | -------- |
1189e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
1190e41f4b71Sopenharmony_ci
1191e41f4b71Sopenharmony_ci**Example**
1192e41f4b71Sopenharmony_ci
1193e41f4b71Sopenharmony_ci```ts
1194e41f4b71Sopenharmony_ciuiContext.getFilteredInspectorTreeById('testId', 0, ['id', 'src', 'content']);
1195e41f4b71Sopenharmony_ci```
1196e41f4b71Sopenharmony_ci
1197e41f4b71Sopenharmony_ci### getCursorController<sup>12+</sup>
1198e41f4b71Sopenharmony_ci
1199e41f4b71Sopenharmony_cigetCursorController(): CursorController
1200e41f4b71Sopenharmony_ci
1201e41f4b71Sopenharmony_ciObtains a [CursorController](js-apis-arkui-UIContext.md#cursorcontroller12) object, which can be used to control the focus.
1202e41f4b71Sopenharmony_ci
1203e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1204e41f4b71Sopenharmony_ci
1205e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1206e41f4b71Sopenharmony_ci
1207e41f4b71Sopenharmony_ci**Return value**
1208e41f4b71Sopenharmony_ci
1209e41f4b71Sopenharmony_ci|Type|Description|
1210e41f4b71Sopenharmony_ci|----|----|
1211e41f4b71Sopenharmony_ci|[CursorController](js-apis-arkui-UIContext.md#cursorcontroller12)| **CursorController** object.|
1212e41f4b71Sopenharmony_ci
1213e41f4b71Sopenharmony_ci**Example**
1214e41f4b71Sopenharmony_ci
1215e41f4b71Sopenharmony_ci```ts
1216e41f4b71Sopenharmony_ciuiContext.CursorController();
1217e41f4b71Sopenharmony_ci```
1218e41f4b71Sopenharmony_ci
1219e41f4b71Sopenharmony_ci### getContextMenuController<sup>12+</sup>
1220e41f4b71Sopenharmony_ci
1221e41f4b71Sopenharmony_cigetContextMenuController(): ContextMenuController
1222e41f4b71Sopenharmony_ci
1223e41f4b71Sopenharmony_ciObtains a [ContextMenuController](#contextmenucontroller12) object, which can be used to control menus.
1224e41f4b71Sopenharmony_ci
1225e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1226e41f4b71Sopenharmony_ci
1227e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1228e41f4b71Sopenharmony_ci
1229e41f4b71Sopenharmony_ci**Return value**
1230e41f4b71Sopenharmony_ci
1231e41f4b71Sopenharmony_ci|Type|Description|
1232e41f4b71Sopenharmony_ci|----|----|
1233e41f4b71Sopenharmony_ci|[ContextMenuController](#contextmenucontroller12)| **ContextMenuController** object.|
1234e41f4b71Sopenharmony_ci
1235e41f4b71Sopenharmony_ci**Example**
1236e41f4b71Sopenharmony_ci
1237e41f4b71Sopenharmony_ci```ts
1238e41f4b71Sopenharmony_ciuiContext.getContextMenuController();
1239e41f4b71Sopenharmony_ci```
1240e41f4b71Sopenharmony_ci
1241e41f4b71Sopenharmony_ci### getMeasureUtils<sup>12+</sup>
1242e41f4b71Sopenharmony_ci
1243e41f4b71Sopenharmony_cigetMeasureUtils(): MeasureUtils
1244e41f4b71Sopenharmony_ci
1245e41f4b71Sopenharmony_ciObtains a **MeasureUtils** object for text calculation.
1246e41f4b71Sopenharmony_ci
1247e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1248e41f4b71Sopenharmony_ci
1249e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1250e41f4b71Sopenharmony_ci
1251e41f4b71Sopenharmony_ci**Return value** 
1252e41f4b71Sopenharmony_ci
1253e41f4b71Sopenharmony_ci| Type  | Description                                        |
1254e41f4b71Sopenharmony_ci| ------ | -------------------------------------------- |
1255e41f4b71Sopenharmony_ci| [MeasureUtils](js-apis-arkui-UIContext.md#measureutils12) | Text metrics, such as text height and width. |
1256e41f4b71Sopenharmony_ci
1257e41f4b71Sopenharmony_ci**Example**
1258e41f4b71Sopenharmony_ci
1259e41f4b71Sopenharmony_ci```ts
1260e41f4b71Sopenharmony_ciuiContext.getMeasureUtils();
1261e41f4b71Sopenharmony_ci```
1262e41f4b71Sopenharmony_ci
1263e41f4b71Sopenharmony_ci### getComponentSnapshot<sup>12+</sup>
1264e41f4b71Sopenharmony_ci
1265e41f4b71Sopenharmony_cigetComponentSnapshot(): ComponentSnapshot
1266e41f4b71Sopenharmony_ci
1267e41f4b71Sopenharmony_ciObtains a **ComponentSnapshot** object, which can be used to obtain a component snapshot.
1268e41f4b71Sopenharmony_ci
1269e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1270e41f4b71Sopenharmony_ci
1271e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1272e41f4b71Sopenharmony_ci
1273e41f4b71Sopenharmony_ci**Return value**
1274e41f4b71Sopenharmony_ci
1275e41f4b71Sopenharmony_ci| Type                                                        | Description                       |
1276e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | --------------------------- |
1277e41f4b71Sopenharmony_ci| [ComponentSnapshot](js-apis-arkui-UIContext.md#componentsnapshot12) | **ComponentSnapshot** object. |
1278e41f4b71Sopenharmony_ci
1279e41f4b71Sopenharmony_ci**Example**
1280e41f4b71Sopenharmony_ci
1281e41f4b71Sopenharmony_ci```ts
1282e41f4b71Sopenharmony_ciuiContext.getComponentSnapshot();
1283e41f4b71Sopenharmony_ci```
1284e41f4b71Sopenharmony_ci
1285e41f4b71Sopenharmony_ci### vp2px<sup>12+</sup>
1286e41f4b71Sopenharmony_ci
1287e41f4b71Sopenharmony_civp2px(value : number) : number
1288e41f4b71Sopenharmony_ci
1289e41f4b71Sopenharmony_ciConverts a value in units of vp to a value in units of px.
1290e41f4b71Sopenharmony_ci
1291e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1292e41f4b71Sopenharmony_ci
1293e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1294e41f4b71Sopenharmony_ci
1295e41f4b71Sopenharmony_ci**Parameters**
1296e41f4b71Sopenharmony_ci
1297e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                                  |
1298e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------------------- |
1299e41f4b71Sopenharmony_ci| value | number | Yes  | Value to convert. |
1300e41f4b71Sopenharmony_ci
1301e41f4b71Sopenharmony_ci**Return value**
1302e41f4b71Sopenharmony_ci
1303e41f4b71Sopenharmony_ci| Type  | Description          |
1304e41f4b71Sopenharmony_ci| ------ | -------------- |
1305e41f4b71Sopenharmony_ci| number | Value after conversion. |
1306e41f4b71Sopenharmony_ci
1307e41f4b71Sopenharmony_ci**Example**
1308e41f4b71Sopenharmony_ci
1309e41f4b71Sopenharmony_ci```tx
1310e41f4b71Sopenharmony_ciuiContext.vp2px(200);
1311e41f4b71Sopenharmony_ci```
1312e41f4b71Sopenharmony_ci
1313e41f4b71Sopenharmony_ci### px2vp<sup>12+</sup>
1314e41f4b71Sopenharmony_ci
1315e41f4b71Sopenharmony_cipx2vp(value : number) : number
1316e41f4b71Sopenharmony_ci
1317e41f4b71Sopenharmony_ciConverts a value in units of px to a value in units of vp.
1318e41f4b71Sopenharmony_ci
1319e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1320e41f4b71Sopenharmony_ci
1321e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1322e41f4b71Sopenharmony_ci
1323e41f4b71Sopenharmony_ci**Parameters**
1324e41f4b71Sopenharmony_ci
1325e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                                  |
1326e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------------------- |
1327e41f4b71Sopenharmony_ci| value | number | Yes  | Value to convert. |
1328e41f4b71Sopenharmony_ci
1329e41f4b71Sopenharmony_ci**Return value**
1330e41f4b71Sopenharmony_ci
1331e41f4b71Sopenharmony_ci| Type  | Description          |
1332e41f4b71Sopenharmony_ci| ------ | -------------- |
1333e41f4b71Sopenharmony_ci| number | Value after conversion. |
1334e41f4b71Sopenharmony_ci
1335e41f4b71Sopenharmony_ci**Example**
1336e41f4b71Sopenharmony_ci
1337e41f4b71Sopenharmony_ci```tx
1338e41f4b71Sopenharmony_ciuiContext.px2vp(200);
1339e41f4b71Sopenharmony_ci```
1340e41f4b71Sopenharmony_ci
1341e41f4b71Sopenharmony_ci### fp2px<sup>12+</sup>
1342e41f4b71Sopenharmony_ci
1343e41f4b71Sopenharmony_cifp2px(value : number) : number
1344e41f4b71Sopenharmony_ci
1345e41f4b71Sopenharmony_ciConverts a value in units of fp to a value in units of px.
1346e41f4b71Sopenharmony_ci
1347e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1348e41f4b71Sopenharmony_ci
1349e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1350e41f4b71Sopenharmony_ci
1351e41f4b71Sopenharmony_ci**Parameters**
1352e41f4b71Sopenharmony_ci
1353e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                                  |
1354e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------------------- |
1355e41f4b71Sopenharmony_ci| value | number | Yes  | Value to convert. |
1356e41f4b71Sopenharmony_ci
1357e41f4b71Sopenharmony_ci**Return value**
1358e41f4b71Sopenharmony_ci
1359e41f4b71Sopenharmony_ci| Type  | Description          |
1360e41f4b71Sopenharmony_ci| ------ | -------------- |
1361e41f4b71Sopenharmony_ci| number | Value after conversion. |
1362e41f4b71Sopenharmony_ci
1363e41f4b71Sopenharmony_ci**Example**
1364e41f4b71Sopenharmony_ci
1365e41f4b71Sopenharmony_ci```tx
1366e41f4b71Sopenharmony_ciuiContext.fp2px(200);
1367e41f4b71Sopenharmony_ci```
1368e41f4b71Sopenharmony_ci
1369e41f4b71Sopenharmony_ci### px2fp<sup>12+</sup>
1370e41f4b71Sopenharmony_ci
1371e41f4b71Sopenharmony_cipx2fp(value : number) : number
1372e41f4b71Sopenharmony_ci
1373e41f4b71Sopenharmony_ciConverts a value in units of px to a value in units of fp.
1374e41f4b71Sopenharmony_ci
1375e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1376e41f4b71Sopenharmony_ci
1377e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1378e41f4b71Sopenharmony_ci
1379e41f4b71Sopenharmony_ci**Parameters**
1380e41f4b71Sopenharmony_ci
1381e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                                  |
1382e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------------------------- |
1383e41f4b71Sopenharmony_ci| value | number | Yes  | Value to convert. |
1384e41f4b71Sopenharmony_ci
1385e41f4b71Sopenharmony_ci**Return value**
1386e41f4b71Sopenharmony_ci
1387e41f4b71Sopenharmony_ci| Type  | Description          |
1388e41f4b71Sopenharmony_ci| ------ | -------------- |
1389e41f4b71Sopenharmony_ci| number | Value after conversion. |
1390e41f4b71Sopenharmony_ci
1391e41f4b71Sopenharmony_ci**Example**
1392e41f4b71Sopenharmony_ci
1393e41f4b71Sopenharmony_ci```tx
1394e41f4b71Sopenharmony_ciuiContext.px2fp(200);
1395e41f4b71Sopenharmony_ci```
1396e41f4b71Sopenharmony_ci
1397e41f4b71Sopenharmony_ci### lpx2px<sup>12+</sup>
1398e41f4b71Sopenharmony_ci
1399e41f4b71Sopenharmony_cilpx2px(value : number) : number
1400e41f4b71Sopenharmony_ci
1401e41f4b71Sopenharmony_ciConverts a value in units of lpx to a value in units of px.
1402e41f4b71Sopenharmony_ci
1403e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1404e41f4b71Sopenharmony_ci
1405e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1406e41f4b71Sopenharmony_ci
1407e41f4b71Sopenharmony_ci**Parameters**
1408e41f4b71Sopenharmony_ci
1409e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                                   |
1410e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------------------------- |
1411e41f4b71Sopenharmony_ci| value | number | Yes  | Value to convert. |
1412e41f4b71Sopenharmony_ci
1413e41f4b71Sopenharmony_ci**Return value**
1414e41f4b71Sopenharmony_ci
1415e41f4b71Sopenharmony_ci| Type  | Description          |
1416e41f4b71Sopenharmony_ci| ------ | -------------- |
1417e41f4b71Sopenharmony_ci| number | Value after conversion. |
1418e41f4b71Sopenharmony_ci
1419e41f4b71Sopenharmony_ci**Example**
1420e41f4b71Sopenharmony_ci
1421e41f4b71Sopenharmony_ci```tx
1422e41f4b71Sopenharmony_ciuiContext.lpx2px(200);
1423e41f4b71Sopenharmony_ci```
1424e41f4b71Sopenharmony_ci
1425e41f4b71Sopenharmony_ci### px2lpx<sup>12+</sup>
1426e41f4b71Sopenharmony_ci
1427e41f4b71Sopenharmony_cipx2lpx(value : number) : number
1428e41f4b71Sopenharmony_ci
1429e41f4b71Sopenharmony_ciConverts a value in units of px to a value in units of lpx.
1430e41f4b71Sopenharmony_ci
1431e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1432e41f4b71Sopenharmony_ci
1433e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1434e41f4b71Sopenharmony_ci
1435e41f4b71Sopenharmony_ci**Parameters**
1436e41f4b71Sopenharmony_ci
1437e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                                   |
1438e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------------------------- |
1439e41f4b71Sopenharmony_ci| value | number | Yes  | Value to convert. |
1440e41f4b71Sopenharmony_ci
1441e41f4b71Sopenharmony_ci**Return value**
1442e41f4b71Sopenharmony_ci
1443e41f4b71Sopenharmony_ci| Type  | Description          |
1444e41f4b71Sopenharmony_ci| ------ | -------------- |
1445e41f4b71Sopenharmony_ci| number | Value after conversion. |
1446e41f4b71Sopenharmony_ci
1447e41f4b71Sopenharmony_ci**Example**
1448e41f4b71Sopenharmony_ci
1449e41f4b71Sopenharmony_ci```tx
1450e41f4b71Sopenharmony_ciuiContext.px2lpx(200);
1451e41f4b71Sopenharmony_ci```
1452e41f4b71Sopenharmony_ci
1453e41f4b71Sopenharmony_ci### getWindowName<sup>12+</sup>
1454e41f4b71Sopenharmony_ci
1455e41f4b71Sopenharmony_cigetWindowName(): string | undefined
1456e41f4b71Sopenharmony_ci
1457e41f4b71Sopenharmony_ciObtains the name of the window where this instance is located.
1458e41f4b71Sopenharmony_ci
1459e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1460e41f4b71Sopenharmony_ci
1461e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1462e41f4b71Sopenharmony_ci
1463e41f4b71Sopenharmony_ci**Return value** 
1464e41f4b71Sopenharmony_ci
1465e41f4b71Sopenharmony_ci| Type  | Description                                        |
1466e41f4b71Sopenharmony_ci| ------ | -------------------------------------------- |
1467e41f4b71Sopenharmony_ci| string \| undefined | Name of the window where the current instance is located. If the window does not exist, **undefined** is returned. |
1468e41f4b71Sopenharmony_ci
1469e41f4b71Sopenharmony_ci**Example**
1470e41f4b71Sopenharmony_ci
1471e41f4b71Sopenharmony_ci```ts
1472e41f4b71Sopenharmony_ciimport { window } from '@kit.ArkUI';
1473e41f4b71Sopenharmony_ci
1474e41f4b71Sopenharmony_ci@Entry
1475e41f4b71Sopenharmony_ci@Component
1476e41f4b71Sopenharmony_cistruct Index {
1477e41f4b71Sopenharmony_ci  @State message: string = 'Hello World'
1478e41f4b71Sopenharmony_ci
1479e41f4b71Sopenharmony_ci  aboutToAppear() {
1480e41f4b71Sopenharmony_ci    const windowName = this.getUIContext().getWindowName();
1481e41f4b71Sopenharmony_ci    console.info('WindowName ' + windowName);
1482e41f4b71Sopenharmony_ci    const currWindow = window.findWindow(windowName);
1483e41f4b71Sopenharmony_ci    const windowProperties = currWindow.getWindowProperties();
1484e41f4b71Sopenharmony_ci    console.info(`Window width ${windowProperties.windowRect.width}, height ${windowProperties.windowRect.height}`);
1485e41f4b71Sopenharmony_ci  }
1486e41f4b71Sopenharmony_ci
1487e41f4b71Sopenharmony_ci  build() {
1488e41f4b71Sopenharmony_ci    Row() {
1489e41f4b71Sopenharmony_ci      Column() {
1490e41f4b71Sopenharmony_ci        Text(this.message)
1491e41f4b71Sopenharmony_ci          .fontSize(50)
1492e41f4b71Sopenharmony_ci          .fontWeight(FontWeight.Bold)
1493e41f4b71Sopenharmony_ci      }
1494e41f4b71Sopenharmony_ci      .width('100%')
1495e41f4b71Sopenharmony_ci    }
1496e41f4b71Sopenharmony_ci    .height('100%')
1497e41f4b71Sopenharmony_ci  }
1498e41f4b71Sopenharmony_ci}
1499e41f4b71Sopenharmony_ci```
1500e41f4b71Sopenharmony_ci
1501e41f4b71Sopenharmony_ci### postFrameCallback<sup>12+</sup>
1502e41f4b71Sopenharmony_ci
1503e41f4b71Sopenharmony_cipostFrameCallback(frameCallback: FrameCallback): void
1504e41f4b71Sopenharmony_ci
1505e41f4b71Sopenharmony_ciRegisters a callback that is executed when the next frame is rendered.
1506e41f4b71Sopenharmony_ci
1507e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1508e41f4b71Sopenharmony_ci
1509e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1510e41f4b71Sopenharmony_ci
1511e41f4b71Sopenharmony_ci**Parameters**
1512e41f4b71Sopenharmony_ci
1513e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                                   |
1514e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------------------------- |
1515e41f4b71Sopenharmony_ci| frameCallback | [FrameCallback](#framecallback12) | Yes  | Callback to be executed for the next frame. |
1516e41f4b71Sopenharmony_ci
1517e41f4b71Sopenharmony_ci**Example**
1518e41f4b71Sopenharmony_ci
1519e41f4b71Sopenharmony_ci```ts
1520e41f4b71Sopenharmony_ciimport {FrameCallback } from '@kit.ArkUI';
1521e41f4b71Sopenharmony_ci
1522e41f4b71Sopenharmony_ciclass MyFrameCallback extends FrameCallback {
1523e41f4b71Sopenharmony_ci  private tag: string;
1524e41f4b71Sopenharmony_ci
1525e41f4b71Sopenharmony_ci  constructor(tag: string) {
1526e41f4b71Sopenharmony_ci    super()
1527e41f4b71Sopenharmony_ci    this.tag = tag;
1528e41f4b71Sopenharmony_ci  }
1529e41f4b71Sopenharmony_ci
1530e41f4b71Sopenharmony_ci  onFrame(frameTimeNanos: number) {
1531e41f4b71Sopenharmony_ci    console.info('MyFrameCallback ' + this.tag + ' ' + frameTimeNanos.toString());
1532e41f4b71Sopenharmony_ci  }
1533e41f4b71Sopenharmony_ci}
1534e41f4b71Sopenharmony_ci
1535e41f4b71Sopenharmony_ci@Entry
1536e41f4b71Sopenharmony_ci@Component
1537e41f4b71Sopenharmony_cistruct Index {
1538e41f4b71Sopenharmony_ci  build() {
1539e41f4b71Sopenharmony_ci    Row() {
1540e41f4b71Sopenharmony_ci      Button('Invoke postFrameCallback')
1541e41f4b71Sopenharmony_ci        .onClick(() => {
1542e41f4b71Sopenharmony_ci          this.getUIContext().postFrameCallback(new MyFrameCallback("normTask"));
1543e41f4b71Sopenharmony_ci        })
1544e41f4b71Sopenharmony_ci    }
1545e41f4b71Sopenharmony_ci  }
1546e41f4b71Sopenharmony_ci}
1547e41f4b71Sopenharmony_ci```
1548e41f4b71Sopenharmony_ci
1549e41f4b71Sopenharmony_ci### postDelayedFrameCallback<sup>12+</sup>
1550e41f4b71Sopenharmony_ci
1551e41f4b71Sopenharmony_cipostDelayedFrameCallback(frameCallback: FrameCallback, delayTime: number): void
1552e41f4b71Sopenharmony_ci
1553e41f4b71Sopenharmony_ciRegisters a callback to be executed on the next frame after a delay.
1554e41f4b71Sopenharmony_ci
1555e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1556e41f4b71Sopenharmony_ci
1557e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1558e41f4b71Sopenharmony_ci
1559e41f4b71Sopenharmony_ci**Parameters**
1560e41f4b71Sopenharmony_ci
1561e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                                   |
1562e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------------------------- |
1563e41f4b71Sopenharmony_ci| frameCallback | [FrameCallback](#framecallback12) | Yes  | Callback to be executed for the next frame. |
1564e41f4b71Sopenharmony_ci| delayTime | number | Yes  | Delay time, in milliseconds. If a **null**, **undefined**, or value less than 0 is passed in, it will be treated as **0**. |
1565e41f4b71Sopenharmony_ci
1566e41f4b71Sopenharmony_ci**Example**
1567e41f4b71Sopenharmony_ci
1568e41f4b71Sopenharmony_ci```ts
1569e41f4b71Sopenharmony_ciimport {FrameCallback } from '@kit.ArkUI';
1570e41f4b71Sopenharmony_ci
1571e41f4b71Sopenharmony_ciclass MyFrameCallback extends FrameCallback {
1572e41f4b71Sopenharmony_ci  private tag: string;
1573e41f4b71Sopenharmony_ci
1574e41f4b71Sopenharmony_ci  constructor(tag: string) {
1575e41f4b71Sopenharmony_ci    super()
1576e41f4b71Sopenharmony_ci    this.tag = tag;
1577e41f4b71Sopenharmony_ci  }
1578e41f4b71Sopenharmony_ci
1579e41f4b71Sopenharmony_ci  onFrame(frameTimeNanos: number) {
1580e41f4b71Sopenharmony_ci    console.info('MyFrameCallback ' + this.tag + ' ' + frameTimeNanos.toString());
1581e41f4b71Sopenharmony_ci  }
1582e41f4b71Sopenharmony_ci}
1583e41f4b71Sopenharmony_ci
1584e41f4b71Sopenharmony_ci@Entry
1585e41f4b71Sopenharmony_ci@Component
1586e41f4b71Sopenharmony_cistruct Index {
1587e41f4b71Sopenharmony_ci  build() {
1588e41f4b71Sopenharmony_ci    Row() {
1589e41f4b71Sopenharmony_ci      Button('Invoke postDelayedFrameCallback')
1590e41f4b71Sopenharmony_ci        .onClick(() => {
1591e41f4b71Sopenharmony_ci          this.getUIContext().postDelayedFrameCallback(new MyFrameCallback("delayTask"), 5);
1592e41f4b71Sopenharmony_ci        })
1593e41f4b71Sopenharmony_ci    }
1594e41f4b71Sopenharmony_ci  }
1595e41f4b71Sopenharmony_ci}
1596e41f4b71Sopenharmony_ci```
1597e41f4b71Sopenharmony_ci
1598e41f4b71Sopenharmony_ci### requireDynamicSyncScene<sup>12+</sup>
1599e41f4b71Sopenharmony_ci
1600e41f4b71Sopenharmony_cirequireDynamicSyncScene(id: string): Array&lt;DynamicSyncScene&gt;
1601e41f4b71Sopenharmony_ci
1602e41f4b71Sopenharmony_ciRequests the dynamic sync scene of a component for customizing related frame rate configuration.
1603e41f4b71Sopenharmony_ci
1604e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1605e41f4b71Sopenharmony_ci
1606e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1607e41f4b71Sopenharmony_ci
1608e41f4b71Sopenharmony_ci**Parameters**
1609e41f4b71Sopenharmony_ci
1610e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                                   |
1611e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------------------------- |
1612e41f4b71Sopenharmony_ci| id | string | Yes   | [Component ID](arkui-ts/ts-universal-attributes-component-id.md) of the target node. |
1613e41f4b71Sopenharmony_ci
1614e41f4b71Sopenharmony_ci**Return value** 
1615e41f4b71Sopenharmony_ci
1616e41f4b71Sopenharmony_ci| Type  | Description                                        |
1617e41f4b71Sopenharmony_ci| ------ | -------------------------------------------- |
1618e41f4b71Sopenharmony_ci| Array&lt;DynamicSyncScene&gt; | **DynamicSyncScene** object array. |
1619e41f4b71Sopenharmony_ci
1620e41f4b71Sopenharmony_ci**Example**
1621e41f4b71Sopenharmony_ci```ts
1622e41f4b71Sopenharmony_ciuiContext.DynamicSyncScene("dynamicSyncScene")
1623e41f4b71Sopenharmony_ci```
1624e41f4b71Sopenharmony_ci
1625e41f4b71Sopenharmony_ci### openBindSheet<sup>12+</sup>
1626e41f4b71Sopenharmony_ci
1627e41f4b71Sopenharmony_ciopenBindSheet\<T extends Object>(bindSheetContent: ComponentContent\<T>, sheetOptions?: SheetOptions, targetId?: number): Promise&lt;void&gt;
1628e41f4b71Sopenharmony_ci
1629e41f4b71Sopenharmony_ciCreates a sheet whose content is as defined in **bindSheetContent** and displays the sheet. This API uses a promise to return the result.  
1630e41f4b71Sopenharmony_ci
1631e41f4b71Sopenharmony_ci> **NOTE**
1632e41f4b71Sopenharmony_ci>
1633e41f4b71Sopenharmony_ci> Since [updateBindSheet](#updatebindsheet12) and [closeBindSheet](#closebindsheet12) depend on **bindSheetContent**, you need to maintain the passed **bindSheetContent** yourself.
1634e41f4b71Sopenharmony_ci
1635e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1636e41f4b71Sopenharmony_ci
1637e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1638e41f4b71Sopenharmony_ci
1639e41f4b71Sopenharmony_ci**Parameters**
1640e41f4b71Sopenharmony_ci
1641e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description     |
1642e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------- |
1643e41f4b71Sopenharmony_ci| bindSheetContent | [ComponentContent\<T>](./js-apis-arkui-ComponentContent.md) | Yes | Content to display on the sheet. |
1644e41f4b71Sopenharmony_ci| sheetOptions | [SheetOptions](arkui-ts/ts-universal-attributes-sheet-transition.md#sheetoptions) | No   |   Style of the sheet.<br>**NOTE**<br>1. **SheetOptions.uiContext** cannot be set. Its value is fixed to the **UIContext** object of the current instance.<br>2. If **targetId** is not passed in, **SheetOptions.preferType** cannot be set to **POPUP**; if **POPUP** is set, it will be replaced with **CENTER**.<br>3. If **targetId** is not passed in, **SheetOptions.mode** cannot be set to **EMBEDDED**; the default mode is **OVERLAY**.<br>4. For the default values of other attributes, see [SheetOptions](arkui-ts/ts-universal-attributes-sheet-transition.md#sheetoptions). |
1645e41f4b71Sopenharmony_ci| targetId | number | No   |   ID of the component to be bound. If this parameter is not set, no component is bound. |
1646e41f4b71Sopenharmony_ci
1647e41f4b71Sopenharmony_ci**Return value**
1648e41f4b71Sopenharmony_ci
1649e41f4b71Sopenharmony_ci| Type                                      | Description     |
1650e41f4b71Sopenharmony_ci| ---------------------------------------- | ------- |
1651e41f4b71Sopenharmony_ci|   Promise&lt;void&gt;           |    Promise used to return the result. |
1652e41f4b71Sopenharmony_ci
1653e41f4b71Sopenharmony_ci**Error codes**
1654e41f4b71Sopenharmony_ci
1655e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Sheet Error Codes](errorcode-bindSheet.md).
1656e41f4b71Sopenharmony_ci
1657e41f4b71Sopenharmony_ci| ID | Error Message                              |
1658e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
1659e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
1660e41f4b71Sopenharmony_ci| 120001 | The bindSheetContent is incorrect. |
1661e41f4b71Sopenharmony_ci| 120002 | The bindSheetContent already exists. |
1662e41f4b71Sopenharmony_ci| 120004 | The targetld does not exist. |
1663e41f4b71Sopenharmony_ci| 120005 | The node of targetId is not in the component tree. |
1664e41f4b71Sopenharmony_ci| 120006 | The node of targetId is not a child of the page node or NavDestination node. |
1665e41f4b71Sopenharmony_ci
1666e41f4b71Sopenharmony_ci**Example**
1667e41f4b71Sopenharmony_ci
1668e41f4b71Sopenharmony_ci```ts
1669e41f4b71Sopenharmony_ciimport { FrameNode, ComponentContent } from "@kit.ArkUI";
1670e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1671e41f4b71Sopenharmony_ci
1672e41f4b71Sopenharmony_ciclass Params {
1673e41f4b71Sopenharmony_ci  text: string = ""
1674e41f4b71Sopenharmony_ci
1675e41f4b71Sopenharmony_ci  constructor(text: string) {
1676e41f4b71Sopenharmony_ci    this.text = text;
1677e41f4b71Sopenharmony_ci  }
1678e41f4b71Sopenharmony_ci}
1679e41f4b71Sopenharmony_ci
1680e41f4b71Sopenharmony_cilet contentNode: ComponentContent<Params>;
1681e41f4b71Sopenharmony_cilet gUIContext: UIContext;
1682e41f4b71Sopenharmony_ci
1683e41f4b71Sopenharmony_ci@Builder
1684e41f4b71Sopenharmony_cifunction buildText(params: Params) {
1685e41f4b71Sopenharmony_ci  Column() {
1686e41f4b71Sopenharmony_ci    Text(params.text)
1687e41f4b71Sopenharmony_ci    Button('Update BindSheet')
1688e41f4b71Sopenharmony_ci      .fontSize(20)
1689e41f4b71Sopenharmony_ci      .onClick(() => {
1690e41f4b71Sopenharmony_ci        gUIContext.updateBindSheet(contentNode, {
1691e41f4b71Sopenharmony_ci          backgroundColor: Color.Pink,
1692e41f4b71Sopenharmony_ci        }, true)
1693e41f4b71Sopenharmony_ci          .then(() => {
1694e41f4b71Sopenharmony_ci            console.info('updateBindSheet success');
1695e41f4b71Sopenharmony_ci          })
1696e41f4b71Sopenharmony_ci          .catch((err: BusinessError) => {
1697e41f4b71Sopenharmony_ci            console.info('updateBindSheet error: ' + err.code + ' ' + err.message);
1698e41f4b71Sopenharmony_ci          })
1699e41f4b71Sopenharmony_ci      })
1700e41f4b71Sopenharmony_ci
1701e41f4b71Sopenharmony_ci    Button('Close BindSheet')
1702e41f4b71Sopenharmony_ci      .fontSize(20)
1703e41f4b71Sopenharmony_ci      .onClick(() => {
1704e41f4b71Sopenharmony_ci        gUIContext.closeBindSheet(contentNode)
1705e41f4b71Sopenharmony_ci          .then(() => {
1706e41f4b71Sopenharmony_ci            console.info('closeBindSheet success');
1707e41f4b71Sopenharmony_ci          })
1708e41f4b71Sopenharmony_ci          .catch((err: BusinessError) => {
1709e41f4b71Sopenharmony_ci            console.info('closeBindSheet error: ' + err.code + ' ' + err.message);
1710e41f4b71Sopenharmony_ci          })
1711e41f4b71Sopenharmony_ci      })
1712e41f4b71Sopenharmony_ci  }
1713e41f4b71Sopenharmony_ci}
1714e41f4b71Sopenharmony_ci
1715e41f4b71Sopenharmony_ci@Entry
1716e41f4b71Sopenharmony_ci@Component
1717e41f4b71Sopenharmony_cistruct UIContextBindSheet {
1718e41f4b71Sopenharmony_ci  @State message: string = 'BindSheet';
1719e41f4b71Sopenharmony_ci
1720e41f4b71Sopenharmony_ci  aboutToAppear() {
1721e41f4b71Sopenharmony_ci    gUIContext = this.getUIContext();
1722e41f4b71Sopenharmony_ci    contentNode = new ComponentContent(this.getUIContext(), wrapBuilder(buildText), new Params(this.message));
1723e41f4b71Sopenharmony_ci  }
1724e41f4b71Sopenharmony_ci
1725e41f4b71Sopenharmony_ci  build() {
1726e41f4b71Sopenharmony_ci    RelativeContainer() {
1727e41f4b71Sopenharmony_ci      Column() {
1728e41f4b71Sopenharmony_ci        Button('Open BindSheet')
1729e41f4b71Sopenharmony_ci          .fontSize(20)
1730e41f4b71Sopenharmony_ci          .onClick(() => {
1731e41f4b71Sopenharmony_ci            let uiContext = this.getUIContext();
1732e41f4b71Sopenharmony_ci            let uniqueId = this.getUniqueId();
1733e41f4b71Sopenharmony_ci            let frameNode: FrameNode | null = uiContext.getFrameNodeByUniqueId(uniqueId);
1734e41f4b71Sopenharmony_ci            let targetId = frameNode?.getFirstChild()?.getUniqueId();
1735e41f4b71Sopenharmony_ci            uiContext.openBindSheet(contentNode, {
1736e41f4b71Sopenharmony_ci              height: SheetSize.MEDIUM,
1737e41f4b71Sopenharmony_ci              backgroundColor: Color.Green,
1738e41f4b71Sopenharmony_ci              title: { title: "Title", subtitle: "subtitle" }
1739e41f4b71Sopenharmony_ci            }, targetId)
1740e41f4b71Sopenharmony_ci              .then(() => {
1741e41f4b71Sopenharmony_ci                console.info('openBindSheet success');
1742e41f4b71Sopenharmony_ci              })
1743e41f4b71Sopenharmony_ci              .catch((err: BusinessError) => {
1744e41f4b71Sopenharmony_ci                console.info('openBindSheet error: ' + err.code + ' ' + err.message);
1745e41f4b71Sopenharmony_ci              })
1746e41f4b71Sopenharmony_ci          })
1747e41f4b71Sopenharmony_ci      }
1748e41f4b71Sopenharmony_ci    }
1749e41f4b71Sopenharmony_ci    .height('100%')
1750e41f4b71Sopenharmony_ci    .width('100%')
1751e41f4b71Sopenharmony_ci  }
1752e41f4b71Sopenharmony_ci}
1753e41f4b71Sopenharmony_ci```
1754e41f4b71Sopenharmony_ci
1755e41f4b71Sopenharmony_ci### updateBindSheet<sup>12+</sup>
1756e41f4b71Sopenharmony_ci
1757e41f4b71Sopenharmony_ciupdateBindSheet\<T extends Object>(bindSheetContent: ComponentContent\<T>, sheetOptions: SheetOptions, partialUpdate?: boolean ): Promise&lt;void&gt;
1758e41f4b71Sopenharmony_ci
1759e41f4b71Sopenharmony_ciUpdates the sheet corresponding to **bindSheetContent**. This API uses a promise to return the result.
1760e41f4b71Sopenharmony_ci
1761e41f4b71Sopenharmony_ci> **NOTE**
1762e41f4b71Sopenharmony_ci>
1763e41f4b71Sopenharmony_ci> **SheetOptions.UIContext**, **SheetOptions.mode**, and callback functions cannot be updated.
1764e41f4b71Sopenharmony_ci>
1765e41f4b71Sopenharmony_ci
1766e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1767e41f4b71Sopenharmony_ci
1768e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1769e41f4b71Sopenharmony_ci
1770e41f4b71Sopenharmony_ci**Parameters**
1771e41f4b71Sopenharmony_ci
1772e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description     |
1773e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------- |
1774e41f4b71Sopenharmony_ci| bindSheetContent | [ComponentContent\<T>](./js-apis-arkui-ComponentContent.md) | Yes | Content to display on the sheet. |
1775e41f4b71Sopenharmony_ci| sheetOptions | [SheetOptions](arkui-ts/ts-universal-attributes-sheet-transition.md#sheetoptions) | Yes   |   Style of the sheet.<br>**NOTE**<br>**SheetOptions.UIContext** and **SheetOptions.mode** cannot be updated. |
1776e41f4b71Sopenharmony_ci| partialUpdate | boolean | No   |   Whether to update the sheet in incremental mode.<br>Default value: **false**<br>**NOTE**<br>1. **true**: incremental update, where the specified attributes in **SheetOptions** are updated, and other attributes stay at their current value.<br>2. **false**: full update, where all attributes except those specified in **SheetOptions** are restored to default values. |
1777e41f4b71Sopenharmony_ci
1778e41f4b71Sopenharmony_ci**Return value**
1779e41f4b71Sopenharmony_ci
1780e41f4b71Sopenharmony_ci| Type                                      | Description     |
1781e41f4b71Sopenharmony_ci| ---------------------------------------- | ------- |
1782e41f4b71Sopenharmony_ci|   Promise&lt;void&gt;           |    Promise used to return the result. |
1783e41f4b71Sopenharmony_ci
1784e41f4b71Sopenharmony_ci**Error codes**
1785e41f4b71Sopenharmony_ci
1786e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Sheet Error Codes](errorcode-bindSheet.md).
1787e41f4b71Sopenharmony_ci
1788e41f4b71Sopenharmony_ci| ID | Error Message                              |
1789e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
1790e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
1791e41f4b71Sopenharmony_ci| 120001 | The bindSheetContent is incorrect. |
1792e41f4b71Sopenharmony_ci| 120003 | The bindSheetContent cannot be found. |
1793e41f4b71Sopenharmony_ci
1794e41f4b71Sopenharmony_ci**Example**
1795e41f4b71Sopenharmony_ci
1796e41f4b71Sopenharmony_ci```ts
1797e41f4b71Sopenharmony_ciimport { FrameNode, ComponentContent } from "@kit.ArkUI";
1798e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1799e41f4b71Sopenharmony_ci
1800e41f4b71Sopenharmony_ciclass Params {
1801e41f4b71Sopenharmony_ci  text: string = ""
1802e41f4b71Sopenharmony_ci
1803e41f4b71Sopenharmony_ci  constructor(text: string) {
1804e41f4b71Sopenharmony_ci    this.text = text;
1805e41f4b71Sopenharmony_ci  }
1806e41f4b71Sopenharmony_ci}
1807e41f4b71Sopenharmony_ci
1808e41f4b71Sopenharmony_cilet contentNode: ComponentContent<Params>;
1809e41f4b71Sopenharmony_cilet gUIContext: UIContext;
1810e41f4b71Sopenharmony_ci
1811e41f4b71Sopenharmony_ci@Builder
1812e41f4b71Sopenharmony_cifunction buildText(params: Params) {
1813e41f4b71Sopenharmony_ci  Column() {
1814e41f4b71Sopenharmony_ci    Text(params.text)
1815e41f4b71Sopenharmony_ci    Button('Update BindSheet')
1816e41f4b71Sopenharmony_ci      .fontSize(20)
1817e41f4b71Sopenharmony_ci      .onClick(() => {
1818e41f4b71Sopenharmony_ci        gUIContext.updateBindSheet(contentNode, {
1819e41f4b71Sopenharmony_ci          backgroundColor: Color.Pink,
1820e41f4b71Sopenharmony_ci        }, true)
1821e41f4b71Sopenharmony_ci          .then(() => {
1822e41f4b71Sopenharmony_ci            console.info('updateBindSheet success');
1823e41f4b71Sopenharmony_ci          })
1824e41f4b71Sopenharmony_ci          .catch((err: BusinessError) => {
1825e41f4b71Sopenharmony_ci            console.info('updateBindSheet error: ' + err.code + ' ' + err.message);
1826e41f4b71Sopenharmony_ci          })
1827e41f4b71Sopenharmony_ci      })
1828e41f4b71Sopenharmony_ci
1829e41f4b71Sopenharmony_ci    Button('Close BindSheet')
1830e41f4b71Sopenharmony_ci      .fontSize(20)
1831e41f4b71Sopenharmony_ci      .onClick(() => {
1832e41f4b71Sopenharmony_ci        gUIContext.closeBindSheet(contentNode)
1833e41f4b71Sopenharmony_ci          .then(() => {
1834e41f4b71Sopenharmony_ci            console.info('closeBindSheet success');
1835e41f4b71Sopenharmony_ci          })
1836e41f4b71Sopenharmony_ci          .catch((err: BusinessError) => {
1837e41f4b71Sopenharmony_ci            console.info('closeBindSheet error: ' + err.code + ' ' + err.message);
1838e41f4b71Sopenharmony_ci          })
1839e41f4b71Sopenharmony_ci      })
1840e41f4b71Sopenharmony_ci  }
1841e41f4b71Sopenharmony_ci}
1842e41f4b71Sopenharmony_ci
1843e41f4b71Sopenharmony_ci@Entry
1844e41f4b71Sopenharmony_ci@Component
1845e41f4b71Sopenharmony_cistruct UIContextBindSheet {
1846e41f4b71Sopenharmony_ci  @State message: string = 'BindSheet';
1847e41f4b71Sopenharmony_ci
1848e41f4b71Sopenharmony_ci  aboutToAppear() {
1849e41f4b71Sopenharmony_ci    gUIContext = this.getUIContext();
1850e41f4b71Sopenharmony_ci    contentNode = new ComponentContent(this.getUIContext(), wrapBuilder(buildText), new Params(this.message));
1851e41f4b71Sopenharmony_ci  }
1852e41f4b71Sopenharmony_ci
1853e41f4b71Sopenharmony_ci  build() {
1854e41f4b71Sopenharmony_ci    RelativeContainer() {
1855e41f4b71Sopenharmony_ci      Column() {
1856e41f4b71Sopenharmony_ci        Button('Open BindSheet')
1857e41f4b71Sopenharmony_ci          .fontSize(20)
1858e41f4b71Sopenharmony_ci          .onClick(() => {
1859e41f4b71Sopenharmony_ci            let uiContext = this.getUIContext();
1860e41f4b71Sopenharmony_ci            let uniqueId = this.getUniqueId();
1861e41f4b71Sopenharmony_ci            let frameNode: FrameNode | null = uiContext.getFrameNodeByUniqueId(uniqueId);
1862e41f4b71Sopenharmony_ci            let targetId = frameNode?.getFirstChild()?.getUniqueId();
1863e41f4b71Sopenharmony_ci            uiContext.openBindSheet(contentNode, {
1864e41f4b71Sopenharmony_ci              height: SheetSize.MEDIUM,
1865e41f4b71Sopenharmony_ci              backgroundColor: Color.Green,
1866e41f4b71Sopenharmony_ci              title: { title: "Title", subtitle: "subtitle" }
1867e41f4b71Sopenharmony_ci            }, targetId)
1868e41f4b71Sopenharmony_ci              .then(() => {
1869e41f4b71Sopenharmony_ci                console.info('openBindSheet success');
1870e41f4b71Sopenharmony_ci              })
1871e41f4b71Sopenharmony_ci              .catch((err: BusinessError) => {
1872e41f4b71Sopenharmony_ci                console.info('openBindSheet error: ' + err.code + ' ' + err.message);
1873e41f4b71Sopenharmony_ci              })
1874e41f4b71Sopenharmony_ci          })
1875e41f4b71Sopenharmony_ci      }
1876e41f4b71Sopenharmony_ci    }
1877e41f4b71Sopenharmony_ci    .height('100%')
1878e41f4b71Sopenharmony_ci    .width('100%')
1879e41f4b71Sopenharmony_ci  }
1880e41f4b71Sopenharmony_ci}
1881e41f4b71Sopenharmony_ci```
1882e41f4b71Sopenharmony_ci
1883e41f4b71Sopenharmony_ci### closeBindSheet<sup>12+</sup>
1884e41f4b71Sopenharmony_ci
1885e41f4b71Sopenharmony_cicloseBindSheet\<T extends Object>(bindSheetContent: ComponentContent\<T>): Promise&lt;void&gt;
1886e41f4b71Sopenharmony_ci
1887e41f4b71Sopenharmony_ciCloses the sheet corresponding to **bindSheetContent**. This API uses a promise to return the result.
1888e41f4b71Sopenharmony_ci
1889e41f4b71Sopenharmony_ci> **NOTE**
1890e41f4b71Sopenharmony_ci>
1891e41f4b71Sopenharmony_ci> Closing a sheet using this API will not invoke the **shouldDismiss** callback.
1892e41f4b71Sopenharmony_ci>
1893e41f4b71Sopenharmony_ci
1894e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
1895e41f4b71Sopenharmony_ci
1896e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
1897e41f4b71Sopenharmony_ci
1898e41f4b71Sopenharmony_ci**Parameters**
1899e41f4b71Sopenharmony_ci
1900e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description     |
1901e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------- |
1902e41f4b71Sopenharmony_ci| bindSheetContent | [ComponentContent\<T>](./js-apis-arkui-ComponentContent.md) | Yes | Content to display on the sheet. |
1903e41f4b71Sopenharmony_ci
1904e41f4b71Sopenharmony_ci**Return value**
1905e41f4b71Sopenharmony_ci
1906e41f4b71Sopenharmony_ci| Type                                      | Description     |
1907e41f4b71Sopenharmony_ci| ---------------------------------------- | ------- |
1908e41f4b71Sopenharmony_ci|   Promise&lt;void&gt;           |    Promise used to return the result. |
1909e41f4b71Sopenharmony_ci
1910e41f4b71Sopenharmony_ci**Error codes**
1911e41f4b71Sopenharmony_ci
1912e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Sheet Error Codes](errorcode-bindSheet.md).
1913e41f4b71Sopenharmony_ci
1914e41f4b71Sopenharmony_ci| ID | Error Message                              |
1915e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
1916e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
1917e41f4b71Sopenharmony_ci| 120001 | The bindSheetContent is incorrect. |
1918e41f4b71Sopenharmony_ci| 120003 | The bindSheetContent cannot be found. |
1919e41f4b71Sopenharmony_ci
1920e41f4b71Sopenharmony_ci**Example**
1921e41f4b71Sopenharmony_ci
1922e41f4b71Sopenharmony_ci```ts
1923e41f4b71Sopenharmony_ciimport { FrameNode, ComponentContent } from "@kit.ArkUI";
1924e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
1925e41f4b71Sopenharmony_ci
1926e41f4b71Sopenharmony_ciclass Params {
1927e41f4b71Sopenharmony_ci  text: string = ""
1928e41f4b71Sopenharmony_ci
1929e41f4b71Sopenharmony_ci  constructor(text: string) {
1930e41f4b71Sopenharmony_ci    this.text = text;
1931e41f4b71Sopenharmony_ci  }
1932e41f4b71Sopenharmony_ci}
1933e41f4b71Sopenharmony_ci
1934e41f4b71Sopenharmony_cilet contentNode: ComponentContent<Params>;
1935e41f4b71Sopenharmony_cilet gUIContext: UIContext;
1936e41f4b71Sopenharmony_ci
1937e41f4b71Sopenharmony_ci@Builder
1938e41f4b71Sopenharmony_cifunction buildText(params: Params) {
1939e41f4b71Sopenharmony_ci  Column() {
1940e41f4b71Sopenharmony_ci    Text(params.text)
1941e41f4b71Sopenharmony_ci    Button('Update BindSheet')
1942e41f4b71Sopenharmony_ci      .fontSize(20)
1943e41f4b71Sopenharmony_ci      .onClick(() => {
1944e41f4b71Sopenharmony_ci        gUIContext.updateBindSheet(contentNode, {
1945e41f4b71Sopenharmony_ci          backgroundColor: Color.Pink,
1946e41f4b71Sopenharmony_ci        }, true)
1947e41f4b71Sopenharmony_ci          .then(() => {
1948e41f4b71Sopenharmony_ci            console.info('updateBindSheet success');
1949e41f4b71Sopenharmony_ci          })
1950e41f4b71Sopenharmony_ci          .catch((err: BusinessError) => {
1951e41f4b71Sopenharmony_ci            console.info('updateBindSheet error: ' + err.code + ' ' + err.message);
1952e41f4b71Sopenharmony_ci          })
1953e41f4b71Sopenharmony_ci      })
1954e41f4b71Sopenharmony_ci
1955e41f4b71Sopenharmony_ci    Button('Close BindSheet')
1956e41f4b71Sopenharmony_ci      .fontSize(20)
1957e41f4b71Sopenharmony_ci      .onClick(() => {
1958e41f4b71Sopenharmony_ci        gUIContext.closeBindSheet(contentNode)
1959e41f4b71Sopenharmony_ci          .then(() => {
1960e41f4b71Sopenharmony_ci            console.info('closeBindSheet success');
1961e41f4b71Sopenharmony_ci          })
1962e41f4b71Sopenharmony_ci          .catch((err: BusinessError) => {
1963e41f4b71Sopenharmony_ci            console.info('closeBindSheet error: ' + err.code + ' ' + err.message);
1964e41f4b71Sopenharmony_ci          })
1965e41f4b71Sopenharmony_ci      })
1966e41f4b71Sopenharmony_ci  }
1967e41f4b71Sopenharmony_ci}
1968e41f4b71Sopenharmony_ci
1969e41f4b71Sopenharmony_ci@Entry
1970e41f4b71Sopenharmony_ci@Component
1971e41f4b71Sopenharmony_cistruct UIContextBindSheet {
1972e41f4b71Sopenharmony_ci  @State message: string = 'BindSheet';
1973e41f4b71Sopenharmony_ci
1974e41f4b71Sopenharmony_ci  aboutToAppear() {
1975e41f4b71Sopenharmony_ci    gUIContext = this.getUIContext();
1976e41f4b71Sopenharmony_ci    contentNode = new ComponentContent(this.getUIContext(), wrapBuilder(buildText), new Params(this.message));
1977e41f4b71Sopenharmony_ci  }
1978e41f4b71Sopenharmony_ci
1979e41f4b71Sopenharmony_ci  build() {
1980e41f4b71Sopenharmony_ci    RelativeContainer() {
1981e41f4b71Sopenharmony_ci      Column() {
1982e41f4b71Sopenharmony_ci        Button('Open BindSheet')
1983e41f4b71Sopenharmony_ci          .fontSize(20)
1984e41f4b71Sopenharmony_ci          .onClick(() => {
1985e41f4b71Sopenharmony_ci            let uiContext = this.getUIContext();
1986e41f4b71Sopenharmony_ci            let uniqueId = this.getUniqueId();
1987e41f4b71Sopenharmony_ci            let frameNode: FrameNode | null = uiContext.getFrameNodeByUniqueId(uniqueId);
1988e41f4b71Sopenharmony_ci            let targetId = frameNode?.getFirstChild()?.getUniqueId();
1989e41f4b71Sopenharmony_ci            uiContext.openBindSheet(contentNode, {
1990e41f4b71Sopenharmony_ci              height: SheetSize.MEDIUM,
1991e41f4b71Sopenharmony_ci              backgroundColor: Color.Green,
1992e41f4b71Sopenharmony_ci              title: { title: "Title", subtitle: "subtitle" }
1993e41f4b71Sopenharmony_ci            }, targetId)
1994e41f4b71Sopenharmony_ci              .then(() => {
1995e41f4b71Sopenharmony_ci                console.info('openBindSheet success');
1996e41f4b71Sopenharmony_ci              })
1997e41f4b71Sopenharmony_ci              .catch((err: BusinessError) => {
1998e41f4b71Sopenharmony_ci                console.info('openBindSheet error: ' + err.code + ' ' + err.message);
1999e41f4b71Sopenharmony_ci              })
2000e41f4b71Sopenharmony_ci          })
2001e41f4b71Sopenharmony_ci      }
2002e41f4b71Sopenharmony_ci    }
2003e41f4b71Sopenharmony_ci    .height('100%')
2004e41f4b71Sopenharmony_ci    .width('100%')
2005e41f4b71Sopenharmony_ci  }
2006e41f4b71Sopenharmony_ci}
2007e41f4b71Sopenharmony_ci```
2008e41f4b71Sopenharmony_ci
2009e41f4b71Sopenharmony_ci## Font
2010e41f4b71Sopenharmony_ci
2011e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getFont()](#getfont) in **UIContext** to obtain a **Font** instance, and then call the APIs using the obtained instance.
2012e41f4b71Sopenharmony_ci
2013e41f4b71Sopenharmony_ci### registerFont
2014e41f4b71Sopenharmony_ci
2015e41f4b71Sopenharmony_ciregisterFont(options: font.FontOptions): void
2016e41f4b71Sopenharmony_ci
2017e41f4b71Sopenharmony_ciRegisters a custom font with the font manager.
2018e41f4b71Sopenharmony_ci
2019e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2020e41f4b71Sopenharmony_ci
2021e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2022e41f4b71Sopenharmony_ci
2023e41f4b71Sopenharmony_ci**Parameters**
2024e41f4b71Sopenharmony_ci
2025e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description         |
2026e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ----------- |
2027e41f4b71Sopenharmony_ci| options | [font.FontOptions](js-apis-font.md#fontoptions) | Yes   | Information about the custom font to register. |
2028e41f4b71Sopenharmony_ci
2029e41f4b71Sopenharmony_ci**Example**
2030e41f4b71Sopenharmony_ci
2031e41f4b71Sopenharmony_ci```ts
2032e41f4b71Sopenharmony_ciimport { Font } from '@kit.ArkUI';
2033e41f4b71Sopenharmony_ci
2034e41f4b71Sopenharmony_cilet font:Font = uiContext.getFont();
2035e41f4b71Sopenharmony_cifont.registerFont({
2036e41f4b71Sopenharmony_ci  familyName: 'medium',
2037e41f4b71Sopenharmony_ci  familySrc: '/font/medium.ttf'
2038e41f4b71Sopenharmony_ci});
2039e41f4b71Sopenharmony_ci```
2040e41f4b71Sopenharmony_ci### getSystemFontList
2041e41f4b71Sopenharmony_ci
2042e41f4b71Sopenharmony_cigetSystemFontList(): Array\<string> 
2043e41f4b71Sopenharmony_ci
2044e41f4b71Sopenharmony_ciObtains the list of supported fonts.
2045e41f4b71Sopenharmony_ci
2046e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2047e41f4b71Sopenharmony_ci
2048e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2049e41f4b71Sopenharmony_ci
2050e41f4b71Sopenharmony_ci**Return value**
2051e41f4b71Sopenharmony_ci
2052e41f4b71Sopenharmony_ci| Type            | Description       |
2053e41f4b71Sopenharmony_ci| -------------- | --------- |
2054e41f4b71Sopenharmony_ci| Array\<string> | List of supported fonts. |
2055e41f4b71Sopenharmony_ci
2056e41f4b71Sopenharmony_ci**Example** 
2057e41f4b71Sopenharmony_ci
2058e41f4b71Sopenharmony_ci```ts
2059e41f4b71Sopenharmony_ciimport { Font } from '@kit.ArkUI';
2060e41f4b71Sopenharmony_ci
2061e41f4b71Sopenharmony_cilet font:Font|undefined = uiContext.getFont();
2062e41f4b71Sopenharmony_ciif(font){
2063e41f4b71Sopenharmony_ci  font.getSystemFontList()
2064e41f4b71Sopenharmony_ci}
2065e41f4b71Sopenharmony_ci```
2066e41f4b71Sopenharmony_ci
2067e41f4b71Sopenharmony_ci### getFontByName
2068e41f4b71Sopenharmony_ci
2069e41f4b71Sopenharmony_cigetFontByName(fontName: string): font.FontInfo
2070e41f4b71Sopenharmony_ci
2071e41f4b71Sopenharmony_ciObtains information about a system font based on the font name.
2072e41f4b71Sopenharmony_ci
2073e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2074e41f4b71Sopenharmony_ci
2075e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2076e41f4b71Sopenharmony_ci
2077e41f4b71Sopenharmony_ci**Parameters** 
2078e41f4b71Sopenharmony_ci
2079e41f4b71Sopenharmony_ci| Name     | Type    | Mandatory  | Description     |
2080e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------- |
2081e41f4b71Sopenharmony_ci| fontName | string | Yes   | System font name. |
2082e41f4b71Sopenharmony_ci
2083e41f4b71Sopenharmony_ci**Return value** 
2084e41f4b71Sopenharmony_ci
2085e41f4b71Sopenharmony_ci| Type                                     | Description          |
2086e41f4b71Sopenharmony_ci| ----------------------------------------- | -------------- |
2087e41f4b71Sopenharmony_ci| [font.FontInfo](js-apis-font.md#fontinfo10) | Information about the system font. |
2088e41f4b71Sopenharmony_ci
2089e41f4b71Sopenharmony_ci**Example** 
2090e41f4b71Sopenharmony_ci
2091e41f4b71Sopenharmony_ci```ts
2092e41f4b71Sopenharmony_ciimport { Font } from '@kit.ArkUI';
2093e41f4b71Sopenharmony_ci
2094e41f4b71Sopenharmony_cilet font:Font|undefined = uiContext.getFont();
2095e41f4b71Sopenharmony_ciif(font){
2096e41f4b71Sopenharmony_ci  font.getFontByName('Sans Italic')
2097e41f4b71Sopenharmony_ci}
2098e41f4b71Sopenharmony_ci```
2099e41f4b71Sopenharmony_ci
2100e41f4b71Sopenharmony_ci## ComponentUtils
2101e41f4b71Sopenharmony_ci
2102e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getComponentUtils()](#getcomponentutils) in **UIContext** to obtain a **ComponentUtils** instance, and then call the APIs using the obtained instance.
2103e41f4b71Sopenharmony_ci
2104e41f4b71Sopenharmony_ci### getRectangleById
2105e41f4b71Sopenharmony_ci
2106e41f4b71Sopenharmony_cigetRectangleById(id: string): componentUtils.ComponentInfo
2107e41f4b71Sopenharmony_ci
2108e41f4b71Sopenharmony_ciObtains the size, position, translation, scaling, rotation, and affine matrix information of the specified component.
2109e41f4b71Sopenharmony_ci
2110e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2111e41f4b71Sopenharmony_ci
2112e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2113e41f4b71Sopenharmony_ci
2114e41f4b71Sopenharmony_ci**Parameters**
2115e41f4b71Sopenharmony_ci
2116e41f4b71Sopenharmony_ci| Name | Type    | Mandatory  | Description       |
2117e41f4b71Sopenharmony_ci| ---- | ------ | ---- | --------- |
2118e41f4b71Sopenharmony_ci| id   | string | Yes   | Unique component ID. |
2119e41f4b71Sopenharmony_ci
2120e41f4b71Sopenharmony_ci**Return value**
2121e41f4b71Sopenharmony_ci
2122e41f4b71Sopenharmony_ci| Type                                                        | Description                                            |
2123e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------ |
2124e41f4b71Sopenharmony_ci| [componentUtils.ComponentInfo](js-apis-arkui-componentUtils.md#componentinfo) | Size, position, translation, scaling, rotation, and affine matrix information of the component. |
2125e41f4b71Sopenharmony_ci
2126e41f4b71Sopenharmony_ci**Example**
2127e41f4b71Sopenharmony_ci
2128e41f4b71Sopenharmony_ci```ts
2129e41f4b71Sopenharmony_ciimport { ComponentUtils } from '@kit.ArkUI';
2130e41f4b71Sopenharmony_ci
2131e41f4b71Sopenharmony_cilet componentUtils:ComponentUtils = uiContext.getComponentUtils();
2132e41f4b71Sopenharmony_cilet modePosition = componentUtils.getRectangleById("onClick");
2133e41f4b71Sopenharmony_cilet localOffsetWidth = modePosition.size.width;
2134e41f4b71Sopenharmony_cilet localOffsetHeight = modePosition.size.height;
2135e41f4b71Sopenharmony_ci```
2136e41f4b71Sopenharmony_ci
2137e41f4b71Sopenharmony_ci## UIInspector
2138e41f4b71Sopenharmony_ci
2139e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getUIInspector()](#getuiinspector) in **UIContext** to obtain a **UIInspector** instance, and then call the APIs using the obtained instance.
2140e41f4b71Sopenharmony_ci
2141e41f4b71Sopenharmony_ci### createComponentObserver
2142e41f4b71Sopenharmony_ci
2143e41f4b71Sopenharmony_cicreateComponentObserver(id: string): inspector.ComponentObserver
2144e41f4b71Sopenharmony_ci
2145e41f4b71Sopenharmony_ciCreates an observer for the specified component.
2146e41f4b71Sopenharmony_ci
2147e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
2148e41f4b71Sopenharmony_ci
2149e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2150e41f4b71Sopenharmony_ci
2151e41f4b71Sopenharmony_ci**Parameters**
2152e41f4b71Sopenharmony_ci
2153e41f4b71Sopenharmony_ci| Name | Type    | Mandatory  | Description     |
2154e41f4b71Sopenharmony_ci| ---- | ------ | ---- | ------- |
2155e41f4b71Sopenharmony_ci| id   | string | Yes   | Component ID. |
2156e41f4b71Sopenharmony_ci
2157e41f4b71Sopenharmony_ci**Return value** 
2158e41f4b71Sopenharmony_ci
2159e41f4b71Sopenharmony_ci| Type                                                        | Description                                              |
2160e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | -------------------------------------------------- |
2161e41f4b71Sopenharmony_ci| [inspector.ComponentObserver](js-apis-arkui-inspector.md#componentobserver) | Component observer, which is used to register or unregister listeners for completion of component layout or drawing. |
2162e41f4b71Sopenharmony_ci
2163e41f4b71Sopenharmony_ci**Example**
2164e41f4b71Sopenharmony_ci
2165e41f4b71Sopenharmony_ci```ts
2166e41f4b71Sopenharmony_ciimport { UIInspector } from '@kit.ArkUI';
2167e41f4b71Sopenharmony_ci
2168e41f4b71Sopenharmony_cilet inspector: UIInspector = uiContext.getUIInspector();
2169e41f4b71Sopenharmony_cilet listener = inspector.createComponentObserver('COMPONENT_ID');
2170e41f4b71Sopenharmony_ci```
2171e41f4b71Sopenharmony_ci
2172e41f4b71Sopenharmony_ci## PageInfo<sup>12+</sup>
2173e41f4b71Sopenharmony_ciRepresents the page information of the router or navigation destination. If there is no related page information, **undefined** is returned.
2174e41f4b71Sopenharmony_ci
2175e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2176e41f4b71Sopenharmony_ci
2177e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2178e41f4b71Sopenharmony_ci
2179e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
2180e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
2181e41f4b71Sopenharmony_ci| routerPageInfo | observer.[RouterPageInfo](js-apis-arkui-observer.md#routerpageinfo) | No | Router information. |
2182e41f4b71Sopenharmony_ci| navDestinationInfo | observer.[NavDestinationInfo](js-apis-arkui-observer.md#navdestinationinfo) | No | Navigation destination information. |
2183e41f4b71Sopenharmony_ci
2184e41f4b71Sopenharmony_ci## UIObserver<sup>11+</sup>
2185e41f4b71Sopenharmony_ci
2186e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getUIObserver()](#getuiobserver11) in **UIContext** to obtain a **UIObserver** instance, and then call the APIs using the obtained instance.
2187e41f4b71Sopenharmony_ci
2188e41f4b71Sopenharmony_ci### on('navDestinationUpdate')<sup>11+</sup>
2189e41f4b71Sopenharmony_ci
2190e41f4b71Sopenharmony_cion(type: 'navDestinationUpdate', callback: Callback\<observer.NavDestinationInfo\>): void
2191e41f4b71Sopenharmony_ci
2192e41f4b71Sopenharmony_ciSubscribes to state changes of this **\<NavDestination>** component.
2193e41f4b71Sopenharmony_ci
2194e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2195e41f4b71Sopenharmony_ci
2196e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2197e41f4b71Sopenharmony_ci
2198e41f4b71Sopenharmony_ci**Parameters** 
2199e41f4b71Sopenharmony_ci
2200e41f4b71Sopenharmony_ci| Name  | Type                                                 | Mandatory | Description                                                        |
2201e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
2202e41f4b71Sopenharmony_ci| type     | string                                                | Yes  | Event type. The value is fixed at **'navDestinationUpdate'**, which indicates the state change event of the **\<NavDestination>** component. |
2203e41f4b71Sopenharmony_ci| callback | Callback\<observer.[NavDestinationInfo](js-apis-arkui-observer.md#navdestinationinfo)\> | Yes  | Callback used to return the current state of the **\<NavDestination>** component.                |
2204e41f4b71Sopenharmony_ci
2205e41f4b71Sopenharmony_ci**Example**
2206e41f4b71Sopenharmony_ci
2207e41f4b71Sopenharmony_ci```ts
2208e41f4b71Sopenharmony_ciimport { UIObserver } from '@kit.ArkUI';
2209e41f4b71Sopenharmony_ci
2210e41f4b71Sopenharmony_cilet observer:UIObserver = uiContext.getUIObserver();
2211e41f4b71Sopenharmony_ciobserver.on('navDestinationUpdate', (info) => {
2212e41f4b71Sopenharmony_ci    console.info('NavDestination state update', JSON.stringify(info));
2213e41f4b71Sopenharmony_ci});
2214e41f4b71Sopenharmony_ci```
2215e41f4b71Sopenharmony_ci
2216e41f4b71Sopenharmony_ci### off('navDestinationUpdate')<sup>11+</sup>
2217e41f4b71Sopenharmony_ci
2218e41f4b71Sopenharmony_cioff(type: 'navDestinationUpdate', callback?: Callback\<observer.NavDestinationInfo\>): void
2219e41f4b71Sopenharmony_ci
2220e41f4b71Sopenharmony_ciUnsubscribes from state changes of this **\<NavDestination>** component.
2221e41f4b71Sopenharmony_ci
2222e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2223e41f4b71Sopenharmony_ci
2224e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2225e41f4b71Sopenharmony_ci
2226e41f4b71Sopenharmony_ci**Parameters** 
2227e41f4b71Sopenharmony_ci
2228e41f4b71Sopenharmony_ci| Name  | Type                                                 | Mandatory | Description                                                        |
2229e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
2230e41f4b71Sopenharmony_ci| type     | string                                                | Yes  | Event type. The value is fixed at **'navDestinationUpdate'**, which indicates the state change event of the **\<NavDestination>** component. |
2231e41f4b71Sopenharmony_ci| callback | Callback\<observer.[NavDestinationInfo](js-apis-arkui-observer.md#navdestinationinfo)\> | No  | Callback used to return the current state of the **\<NavDestination>** component.                |
2232e41f4b71Sopenharmony_ci
2233e41f4b71Sopenharmony_ci**Example** 
2234e41f4b71Sopenharmony_ci
2235e41f4b71Sopenharmony_ci```ts
2236e41f4b71Sopenharmony_ciimport { UIObserver } from '@kit.ArkUI';
2237e41f4b71Sopenharmony_ci
2238e41f4b71Sopenharmony_cilet observer:UIObserver = uiContext.getUIObserver();
2239e41f4b71Sopenharmony_ciobserver.off('navDestinationUpdate');
2240e41f4b71Sopenharmony_ci```
2241e41f4b71Sopenharmony_ci
2242e41f4b71Sopenharmony_ci### on('navDestinationUpdate')<sup>11+</sup>
2243e41f4b71Sopenharmony_ci
2244e41f4b71Sopenharmony_cion(type: 'navDestinationUpdate', options: { navigationId: ResourceStr }, callback: Callback\<observer.NavDestinationInfo\>): void
2245e41f4b71Sopenharmony_ci
2246e41f4b71Sopenharmony_ciSubscribes to state changes of this **\<NavDestination>** component.
2247e41f4b71Sopenharmony_ci
2248e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2249e41f4b71Sopenharmony_ci
2250e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2251e41f4b71Sopenharmony_ci
2252e41f4b71Sopenharmony_ci**Parameters** 
2253e41f4b71Sopenharmony_ci
2254e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2255e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2256e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value is fixed at **'navDestinationUpdate'**, which indicates the state change event of the **\<NavDestination>** component. |
2257e41f4b71Sopenharmony_ci| options  | { navigationId: [ResourceStr](arkui-ts/ts-types.md#resourcestr) } | Yes  | ID of the target **\<NavDestination>** component.                                  |
2258e41f4b71Sopenharmony_ci| callback | Callback\<observer.[NavDestinationInfo](js-apis-arkui-observer.md#navdestinationinfo)\>        | Yes  | Callback used to return the current state of the **\<NavDestination>** component.                |
2259e41f4b71Sopenharmony_ci
2260e41f4b71Sopenharmony_ci**Example**
2261e41f4b71Sopenharmony_ci
2262e41f4b71Sopenharmony_ci```ts
2263e41f4b71Sopenharmony_ciimport { UIObserver } from '@kit.ArkUI';
2264e41f4b71Sopenharmony_ci
2265e41f4b71Sopenharmony_cilet observer:UIObserver = uiContext.getUIObserver();
2266e41f4b71Sopenharmony_ciobserver.on('navDestinationUpdate', { navigationId: "testId" }, (info) => {
2267e41f4b71Sopenharmony_ci    console.info('NavDestination state update', JSON.stringify(info));
2268e41f4b71Sopenharmony_ci});
2269e41f4b71Sopenharmony_ci```
2270e41f4b71Sopenharmony_ci
2271e41f4b71Sopenharmony_ci### off('navDestinationUpdate')<sup>11+</sup>
2272e41f4b71Sopenharmony_ci
2273e41f4b71Sopenharmony_cioff(type: 'navDestinationUpdate', options: { navigationId: ResourceStr }, callback?: Callback\<observer.NavDestinationInfo\>): void
2274e41f4b71Sopenharmony_ci
2275e41f4b71Sopenharmony_ciUnsubscribes from state changes of this **\<NavDestination>** component.
2276e41f4b71Sopenharmony_ci
2277e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2278e41f4b71Sopenharmony_ci
2279e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2280e41f4b71Sopenharmony_ci
2281e41f4b71Sopenharmony_ci**Parameters** 
2282e41f4b71Sopenharmony_ci
2283e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2284e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2285e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value is fixed at **'navDestinationUpdate'**, which indicates the state change event of the **\<NavDestination>** component. |
2286e41f4b71Sopenharmony_ci| options  | { navigationId: [ResourceStr](arkui-ts/ts-types.md#resourcestr) } | Yes  | ID of the target **\<NavDestination>** component.                                  |
2287e41f4b71Sopenharmony_ci| callback | Callback\<observer.[NavDestinationInfo](js-apis-arkui-observer.md#navdestinationinfo)\>        | No  | Callback used to return the current state of the **\<NavDestination>** component.                |
2288e41f4b71Sopenharmony_ci
2289e41f4b71Sopenharmony_ci**Example**
2290e41f4b71Sopenharmony_ci
2291e41f4b71Sopenharmony_ci```ts
2292e41f4b71Sopenharmony_ciimport { UIObserver } from '@kit.ArkUI';
2293e41f4b71Sopenharmony_ci
2294e41f4b71Sopenharmony_cilet observer:UIObserver = uiContext.getUIObserver();
2295e41f4b71Sopenharmony_ciobserver.off('navDestinationUpdate', { navigationId: "testId" });
2296e41f4b71Sopenharmony_ci```
2297e41f4b71Sopenharmony_ci
2298e41f4b71Sopenharmony_ci### on('scrollEvent')<sup>12+</sup>
2299e41f4b71Sopenharmony_ci
2300e41f4b71Sopenharmony_cion(type: 'scrollEvent', callback: Callback\<observer.ScrollEventInfo\>): void
2301e41f4b71Sopenharmony_ci
2302e41f4b71Sopenharmony_ciSubscribes to the start and end of a scroll event.
2303e41f4b71Sopenharmony_ci
2304e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2305e41f4b71Sopenharmony_ci
2306e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2307e41f4b71Sopenharmony_ci
2308e41f4b71Sopenharmony_ci**Parameters** 
2309e41f4b71Sopenharmony_ci
2310e41f4b71Sopenharmony_ci| Name  | Type                                                 | Mandatory | Description                                                        |
2311e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
2312e41f4b71Sopenharmony_ci| type     | string                                                | Yes  | Event type. The value **'scrollEvent'** indicates the start and end of a scroll event.     |
2313e41f4b71Sopenharmony_ci| callback | Callback\<observer.[ScrollEventInfo](js-apis-arkui-observer.md#scrolleventinfo12)\> | Yes  | Callback used to return the Callback used to return the information about the scroll event.  |
2314e41f4b71Sopenharmony_ci
2315e41f4b71Sopenharmony_ci**Example**
2316e41f4b71Sopenharmony_ci
2317e41f4b71Sopenharmony_ciSee [offscrollevent Example](#offscrollevent12-1).
2318e41f4b71Sopenharmony_ci
2319e41f4b71Sopenharmony_ci### off('scrollEvent')<sup>12+</sup>
2320e41f4b71Sopenharmony_ci
2321e41f4b71Sopenharmony_cioff(type: 'scrollEvent', callback?: Callback\<observer.ScrollEventInfo\>): void
2322e41f4b71Sopenharmony_ci
2323e41f4b71Sopenharmony_ciUnsubscribes from the start and end of a scroll event.
2324e41f4b71Sopenharmony_ci
2325e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2326e41f4b71Sopenharmony_ci
2327e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2328e41f4b71Sopenharmony_ci
2329e41f4b71Sopenharmony_ci**Parameters** 
2330e41f4b71Sopenharmony_ci
2331e41f4b71Sopenharmony_ci| Name  | Type                                                 | Mandatory | Description                                                        |
2332e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------- | ---- | ------------------------------------------------------------ |
2333e41f4b71Sopenharmony_ci| type     | string                                                | Yes  | Event type. The value **'scrollEvent'** indicates the start and end of a scroll event.     |
2334e41f4b71Sopenharmony_ci| callback | Callback\<observer.[ScrollEventInfo](js-apis-arkui-observer.md#scrolleventinfo12)\> | No  | Callback used to return the Callback used to return the information about the scroll event.  |
2335e41f4b71Sopenharmony_ci
2336e41f4b71Sopenharmony_ci**Example**
2337e41f4b71Sopenharmony_ci
2338e41f4b71Sopenharmony_ciSee [offscrollevent Example](#offscrollevent12-1).
2339e41f4b71Sopenharmony_ci
2340e41f4b71Sopenharmony_ci### on('scrollEvent')<sup>12+</sup>
2341e41f4b71Sopenharmony_ci
2342e41f4b71Sopenharmony_cion(type: 'scrollEvent', options: observer.ObserverOptions, callback: Callback\<observer.ScrollEventInfo\>): void
2343e41f4b71Sopenharmony_ci
2344e41f4b71Sopenharmony_ciSubscribes to the start and end of a scroll event.
2345e41f4b71Sopenharmony_ci
2346e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2347e41f4b71Sopenharmony_ci
2348e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2349e41f4b71Sopenharmony_ci
2350e41f4b71Sopenharmony_ci**Parameters** 
2351e41f4b71Sopenharmony_ci
2352e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2353e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2354e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'scrollEvent'** indicates the start and end of a scroll event. |
2355e41f4b71Sopenharmony_ci| options  | [observer.ObserverOptions](js-apis-arkui-observer.md#observeroptions12) | Yes  | Observer options, including the ID of the target scrollable component.                   |
2356e41f4b71Sopenharmony_ci| callback | Callback\<observer.[ScrollEventInfo](js-apis-arkui-observer.md#scrolleventinfo12)\>        | Yes  | Callback used to return the Callback used to return the information about the scroll event.                |
2357e41f4b71Sopenharmony_ci
2358e41f4b71Sopenharmony_ci**Example**
2359e41f4b71Sopenharmony_ci
2360e41f4b71Sopenharmony_ciSee [offscrollevent Example](#offscrollevent12-1).
2361e41f4b71Sopenharmony_ci
2362e41f4b71Sopenharmony_ci### off('scrollEvent')<sup>12+</sup>
2363e41f4b71Sopenharmony_ci
2364e41f4b71Sopenharmony_cioff(type: 'scrollEvent', options: observer.ObserverOptions, callback?: Callback\<observer.ScrollEventInfo\>): void
2365e41f4b71Sopenharmony_ci
2366e41f4b71Sopenharmony_ciUnsubscribes from the start and end of a scroll event.
2367e41f4b71Sopenharmony_ci
2368e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2369e41f4b71Sopenharmony_ci
2370e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2371e41f4b71Sopenharmony_ci
2372e41f4b71Sopenharmony_ci**Parameters** 
2373e41f4b71Sopenharmony_ci
2374e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2375e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2376e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'scrollEvent'** indicates the start and end of a scroll event. |
2377e41f4b71Sopenharmony_ci| options  | [observer.ObserverOptions](js-apis-arkui-observer.md#observeroptions12) | Yes  | Observer options, including the ID of the target scrollable component.                   |
2378e41f4b71Sopenharmony_ci| callback | Callback\<observer.[ScrollEventInfo](js-apis-arkui-observer.md#scrolleventinfo12)\>        | No  | Callback used to return the Callback used to return the information about the scroll event.                |
2379e41f4b71Sopenharmony_ci
2380e41f4b71Sopenharmony_ci**Example**
2381e41f4b71Sopenharmony_ci
2382e41f4b71Sopenharmony_ci```ts
2383e41f4b71Sopenharmony_ciimport { UIObserver } from '@kit.ArkUI'
2384e41f4b71Sopenharmony_ci
2385e41f4b71Sopenharmony_ci@Entry
2386e41f4b71Sopenharmony_ci@Component
2387e41f4b71Sopenharmony_cistruct Index {
2388e41f4b71Sopenharmony_ci  scroller: Scroller = new Scroller()
2389e41f4b71Sopenharmony_ci  observer: UIObserver = new UIObserver()
2390e41f4b71Sopenharmony_ci  private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7]
2391e41f4b71Sopenharmony_ci
2392e41f4b71Sopenharmony_ci  build() {
2393e41f4b71Sopenharmony_ci    Row() {
2394e41f4b71Sopenharmony_ci      Column() {
2395e41f4b71Sopenharmony_ci        Scroll(this.scroller) {
2396e41f4b71Sopenharmony_ci          Column() {
2397e41f4b71Sopenharmony_ci            ForEach(this.arr, (item: number) => {
2398e41f4b71Sopenharmony_ci              Text(item.toString())
2399e41f4b71Sopenharmony_ci                .width('90%')
2400e41f4b71Sopenharmony_ci                .height(150)
2401e41f4b71Sopenharmony_ci                .backgroundColor(0xFFFFFF)
2402e41f4b71Sopenharmony_ci                .borderRadius(15)
2403e41f4b71Sopenharmony_ci                .fontSize(16)
2404e41f4b71Sopenharmony_ci                .textAlign(TextAlign.Center)
2405e41f4b71Sopenharmony_ci                .margin({ top: 10 })
2406e41f4b71Sopenharmony_ci            }, (item: string) => item)
2407e41f4b71Sopenharmony_ci          }.width('100%')
2408e41f4b71Sopenharmony_ci        }
2409e41f4b71Sopenharmony_ci        .id("testId")
2410e41f4b71Sopenharmony_ci        .height('80%')
2411e41f4b71Sopenharmony_ci      }
2412e41f4b71Sopenharmony_ci      .width('100%')
2413e41f4b71Sopenharmony_ci
2414e41f4b71Sopenharmony_ci      Row() {
2415e41f4b71Sopenharmony_ci        Button('UIObserver on')
2416e41f4b71Sopenharmony_ci          .onClick(() => {
2417e41f4b71Sopenharmony_ci            this.observer.on('scrollEvent', (info) => {
2418e41f4b71Sopenharmony_ci              console.info('scrollEventInfo', JSON.stringify(info));
2419e41f4b71Sopenharmony_ci            });
2420e41f4b71Sopenharmony_ci          })
2421e41f4b71Sopenharmony_ci        Button('UIObserver off')
2422e41f4b71Sopenharmony_ci          .onClick(() => {
2423e41f4b71Sopenharmony_ci            this.observer.off('scrollEvent');
2424e41f4b71Sopenharmony_ci          })
2425e41f4b71Sopenharmony_ci      }
2426e41f4b71Sopenharmony_ci
2427e41f4b71Sopenharmony_ci      Row() {
2428e41f4b71Sopenharmony_ci        Button('UIObserverWithId on')
2429e41f4b71Sopenharmony_ci          .onClick(() => {
2430e41f4b71Sopenharmony_ci            this.observer.on('scrollEvent', { id:"testId" }, (info) => {
2431e41f4b71Sopenharmony_ci              console.info('scrollEventInfo', JSON.stringify(info));
2432e41f4b71Sopenharmony_ci            });
2433e41f4b71Sopenharmony_ci          })
2434e41f4b71Sopenharmony_ci        Button('UIObserverWithId off')
2435e41f4b71Sopenharmony_ci          .onClick(() => {
2436e41f4b71Sopenharmony_ci            this.observer.off('scrollEvent', { id:"testId" });
2437e41f4b71Sopenharmony_ci          })
2438e41f4b71Sopenharmony_ci      }
2439e41f4b71Sopenharmony_ci    }
2440e41f4b71Sopenharmony_ci    .height('100%')
2441e41f4b71Sopenharmony_ci  }
2442e41f4b71Sopenharmony_ci}
2443e41f4b71Sopenharmony_ci```
2444e41f4b71Sopenharmony_ci
2445e41f4b71Sopenharmony_ci### on('routerPageUpdate')<sup>11+</sup>
2446e41f4b71Sopenharmony_ci
2447e41f4b71Sopenharmony_cion(type: 'routerPageUpdate', callback: Callback\<observer.RouterPageInfo\>): void
2448e41f4b71Sopenharmony_ci
2449e41f4b71Sopenharmony_ciSubscribes to state changes of the page in the router.
2450e41f4b71Sopenharmony_ci
2451e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2452e41f4b71Sopenharmony_ci
2453e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2454e41f4b71Sopenharmony_ci
2455e41f4b71Sopenharmony_ci**Parameters** 
2456e41f4b71Sopenharmony_ci
2457e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2458e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2459e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value is fixed at **'routerPageUpdate'**, which indicates the state change event of the page in the router. |
2460e41f4b71Sopenharmony_ci| callback | Callback\<observer.[RouterPageInfo](js-apis-arkui-observer.md#routerpageinfo)\>        | Yes  | Callback used to return the If **pageInfo** is passed, the current page state is returned.                |
2461e41f4b71Sopenharmony_ci
2462e41f4b71Sopenharmony_ci**Example**
2463e41f4b71Sopenharmony_ci
2464e41f4b71Sopenharmony_ci```ts
2465e41f4b71Sopenharmony_ciimport { UIContext, UIObserver } from '@kit.ArkUI';
2466e41f4b71Sopenharmony_ci
2467e41f4b71Sopenharmony_cilet observer:UIObserver = this.getUIContext().getUIObserver();
2468e41f4b71Sopenharmony_ciobserver.on('routerPageUpdate', (info) => {
2469e41f4b71Sopenharmony_ci    console.info('RouterPage state updated, called by ' + `${info.name}`);
2470e41f4b71Sopenharmony_ci});
2471e41f4b71Sopenharmony_ci```
2472e41f4b71Sopenharmony_ci
2473e41f4b71Sopenharmony_ci### off('routerPageUpdate')<sup>11+</sup>
2474e41f4b71Sopenharmony_ci
2475e41f4b71Sopenharmony_cioff(type: 'routerPageUpdate', callback?: Callback\<observer.RouterPageInfo\>): void
2476e41f4b71Sopenharmony_ci
2477e41f4b71Sopenharmony_ciUnsubscribes to state changes of the page in the router.
2478e41f4b71Sopenharmony_ci
2479e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2480e41f4b71Sopenharmony_ci
2481e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2482e41f4b71Sopenharmony_ci
2483e41f4b71Sopenharmony_ci**Parameters** 
2484e41f4b71Sopenharmony_ci
2485e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2486e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2487e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value is fixed at **'routerPageUpdate'**, which indicates the state change event of the page in the router. |
2488e41f4b71Sopenharmony_ci| callback | Callback\<observer.[RouterPageInfo](js-apis-arkui-observer.md#routerpageinfo)\>        | No  | Callback to be unregistered.                |
2489e41f4b71Sopenharmony_ci
2490e41f4b71Sopenharmony_ci**Example**
2491e41f4b71Sopenharmony_ci
2492e41f4b71Sopenharmony_ci```ts
2493e41f4b71Sopenharmony_ciimport { UIContext, UIObserver } from '@kit.ArkUI';
2494e41f4b71Sopenharmony_ci
2495e41f4b71Sopenharmony_cilet observer:UIObserver = this.getUIContext().getUIObserver();
2496e41f4b71Sopenharmony_cifunction callBackFunc(info:observer.RouterPageInfo) {};
2497e41f4b71Sopenharmony_ci// callBackFunc is defined and used before
2498e41f4b71Sopenharmony_ciobserver.off('routerPageUpdate', callBackFunc);
2499e41f4b71Sopenharmony_ci```
2500e41f4b71Sopenharmony_ci
2501e41f4b71Sopenharmony_ci### on('densityUpdate')<sup>12+</sup>
2502e41f4b71Sopenharmony_ci
2503e41f4b71Sopenharmony_cion(type: 'densityUpdate', callback: Callback\<observer.DensityInfo\>): void
2504e41f4b71Sopenharmony_ci
2505e41f4b71Sopenharmony_ciSubscribes to the pixel density changes of the screen.
2506e41f4b71Sopenharmony_ci
2507e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2508e41f4b71Sopenharmony_ci
2509e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2510e41f4b71Sopenharmony_ci
2511e41f4b71Sopenharmony_ci**Parameters** 
2512e41f4b71Sopenharmony_ci
2513e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2514e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2515e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'densityUpdate'** indicates the pixel density changes of the screen. |
2516e41f4b71Sopenharmony_ci| callback | Callback\<observer.[DensityInfo](./js-apis-arkui-observer.md#densityinfo12)\>        | Yes  | Callback used to return the screen pixel density after the change.                |
2517e41f4b71Sopenharmony_ci
2518e41f4b71Sopenharmony_ci```ts
2519e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI';
2520e41f4b71Sopenharmony_ci
2521e41f4b71Sopenharmony_ci@Entry
2522e41f4b71Sopenharmony_ci@Component
2523e41f4b71Sopenharmony_cistruct Index {
2524e41f4b71Sopenharmony_ci  @State density: number = 0;
2525e41f4b71Sopenharmony_ci  @State message: string = 'No listener registered'
2526e41f4b71Sopenharmony_ci
2527e41f4b71Sopenharmony_ci  densityUpdateCallback = (info: uiObserver.DensityInfo) => {
2528e41f4b71Sopenharmony_ci    this.density = info.density;
2529e41f4b71Sopenharmony_ci    this.message = 'DPI after change:' + this.density.toString();
2530e41f4b71Sopenharmony_ci  }
2531e41f4b71Sopenharmony_ci
2532e41f4b71Sopenharmony_ci  build() {
2533e41f4b71Sopenharmony_ci    Column() {
2534e41f4b71Sopenharmony_ci      Text(this.message)
2535e41f4b71Sopenharmony_ci        .fontSize(24)
2536e41f4b71Sopenharmony_ci        .fontWeight(FontWeight.Bold)
2537e41f4b71Sopenharmony_ci      Button ('Subscribe to Screen Pixel Density Changes')
2538e41f4b71Sopenharmony_ci        .onClick(() => {
2539e41f4b71Sopenharmony_ci          this.message = 'Listener registered'
2540e41f4b71Sopenharmony_ci          this.getUIContext().getUIObserver().on('densityUpdate', this.densityUpdateCallback);
2541e41f4b71Sopenharmony_ci        })
2542e41f4b71Sopenharmony_ci    }
2543e41f4b71Sopenharmony_ci  }
2544e41f4b71Sopenharmony_ci}
2545e41f4b71Sopenharmony_ci```
2546e41f4b71Sopenharmony_ci
2547e41f4b71Sopenharmony_ci### off('densityUpdate')<sup>12+</sup>
2548e41f4b71Sopenharmony_ci
2549e41f4b71Sopenharmony_cioff(type: 'densityUpdate', callback?: Callback\<observer.DensityInfo\>): void
2550e41f4b71Sopenharmony_ci
2551e41f4b71Sopenharmony_ciUnsubscribes from the pixel density changes of the screen.
2552e41f4b71Sopenharmony_ci
2553e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2554e41f4b71Sopenharmony_ci
2555e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2556e41f4b71Sopenharmony_ci
2557e41f4b71Sopenharmony_ci**Parameters** 
2558e41f4b71Sopenharmony_ci
2559e41f4b71Sopenharmony_ci| Name  | Type                                                                | Mandatory | Description                                                                                        |
2560e41f4b71Sopenharmony_ci| -------- | -------------------------------------------------------------------- | ---- | -------------------------------------------------------------------------------------------- |
2561e41f4b71Sopenharmony_ci| type     | string                                                               | Yes  | Event type. The value **'densityUpdate'** indicates the pixel density changes of the screen.                                       |
2562e41f4b71Sopenharmony_ci| callback | Callback\<observer.[DensityInfo](./js-apis-arkui-observer.md#densityinfo12)\> | No  | Callback to be unregistered. If this parameter is not specified, this API unregisters all callbacks for the **densityUpdate** event under the current UI context. |
2563e41f4b71Sopenharmony_ci
2564e41f4b71Sopenharmony_ci```ts
2565e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI';
2566e41f4b71Sopenharmony_ci
2567e41f4b71Sopenharmony_ci@Entry
2568e41f4b71Sopenharmony_ci@Component
2569e41f4b71Sopenharmony_cistruct Index {
2570e41f4b71Sopenharmony_ci  @State density: number = 0;
2571e41f4b71Sopenharmony_ci  @State message: string = 'No listener registered'
2572e41f4b71Sopenharmony_ci
2573e41f4b71Sopenharmony_ci  densityUpdateCallback = (info: uiObserver.DensityInfo) => {
2574e41f4b71Sopenharmony_ci    this.density = info.density;
2575e41f4b71Sopenharmony_ci    this.message = 'DPI after change:' + this.density.toString();
2576e41f4b71Sopenharmony_ci  }
2577e41f4b71Sopenharmony_ci
2578e41f4b71Sopenharmony_ci  build() {
2579e41f4b71Sopenharmony_ci    Column() {
2580e41f4b71Sopenharmony_ci      Text(this.message)
2581e41f4b71Sopenharmony_ci        .fontSize(24)
2582e41f4b71Sopenharmony_ci        .fontWeight(FontWeight.Bold)
2583e41f4b71Sopenharmony_ci      Button ('Subscribe to Screen Pixel Density Changes')
2584e41f4b71Sopenharmony_ci        .onClick(() => {
2585e41f4b71Sopenharmony_ci          this.message = 'Listener registered'
2586e41f4b71Sopenharmony_ci          this.getUIContext().getUIObserver().on('densityUpdate', this.densityUpdateCallback);
2587e41f4b71Sopenharmony_ci        })
2588e41f4b71Sopenharmony_ci      Button ('Unsubscribe from Screen Pixel Density Changes')
2589e41f4b71Sopenharmony_ci        .onClick(() => {
2590e41f4b71Sopenharmony_ci          this.message = 'Listener not registered'
2591e41f4b71Sopenharmony_ci          this.getUIContext().getUIObserver().off('densityUpdate', this.densityUpdateCallback);
2592e41f4b71Sopenharmony_ci        })
2593e41f4b71Sopenharmony_ci    }
2594e41f4b71Sopenharmony_ci  }
2595e41f4b71Sopenharmony_ci}
2596e41f4b71Sopenharmony_ci```
2597e41f4b71Sopenharmony_ci
2598e41f4b71Sopenharmony_ci### on('willDraw')<sup>12+</sup>
2599e41f4b71Sopenharmony_ci
2600e41f4b71Sopenharmony_cion(type: 'willDraw', callback: Callback\<void\>): void
2601e41f4b71Sopenharmony_ci
2602e41f4b71Sopenharmony_ciSubscribes to the dispatch of drawing instructions in each frame.
2603e41f4b71Sopenharmony_ci
2604e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2605e41f4b71Sopenharmony_ci
2606e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2607e41f4b71Sopenharmony_ci
2608e41f4b71Sopenharmony_ci**Parameters** 
2609e41f4b71Sopenharmony_ci
2610e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2611e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2612e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event event. The value **'willDraw'** indicates whether drawing is about to occur. |
2613e41f4b71Sopenharmony_ci| callback | Callback\<void\>        | Yes  | Callback used to return the result.                |
2614e41f4b71Sopenharmony_ci
2615e41f4b71Sopenharmony_ci```ts
2616e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI';
2617e41f4b71Sopenharmony_ci
2618e41f4b71Sopenharmony_ci@Entry
2619e41f4b71Sopenharmony_ci@Component
2620e41f4b71Sopenharmony_cistruct Index {
2621e41f4b71Sopenharmony_ci  willDrawCallback = () => {
2622e41f4b71Sopenharmony_ci    console.info("willDraw instruction dispatched.")
2623e41f4b71Sopenharmony_ci  }
2624e41f4b71Sopenharmony_ci  build() {
2625e41f4b71Sopenharmony_ci    Column() {
2626e41f4b71Sopenharmony_ci      Button('Subscribe to Drawing Instruction Dispatch')
2627e41f4b71Sopenharmony_ci        .onClick(() => {
2628e41f4b71Sopenharmony_ci          this.getUIContext().getUIObserver().on('willDraw', this.willDrawCallback);
2629e41f4b71Sopenharmony_ci        })
2630e41f4b71Sopenharmony_ci    }
2631e41f4b71Sopenharmony_ci  }
2632e41f4b71Sopenharmony_ci}
2633e41f4b71Sopenharmony_ci```
2634e41f4b71Sopenharmony_ci
2635e41f4b71Sopenharmony_ci### off('willDraw')<sup>12+</sup>
2636e41f4b71Sopenharmony_ci
2637e41f4b71Sopenharmony_cioff(type: 'willDraw', callback?: Callback\<void\>): void
2638e41f4b71Sopenharmony_ci
2639e41f4b71Sopenharmony_ciUnsubscribes from the dispatch of drawing instructions in each frame.
2640e41f4b71Sopenharmony_ci
2641e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2642e41f4b71Sopenharmony_ci
2643e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2644e41f4b71Sopenharmony_ci
2645e41f4b71Sopenharmony_ci**Parameters** 
2646e41f4b71Sopenharmony_ci
2647e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2648e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2649e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event event. The value **'willDraw'** indicates whether drawing is about to occur. |
2650e41f4b71Sopenharmony_ci| callback | Callback\<void\>        | No  | Callback to be unregistered.                 |
2651e41f4b71Sopenharmony_ci
2652e41f4b71Sopenharmony_ci```ts
2653e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI';
2654e41f4b71Sopenharmony_ci
2655e41f4b71Sopenharmony_ci@Entry
2656e41f4b71Sopenharmony_ci@Component
2657e41f4b71Sopenharmony_cistruct Index {
2658e41f4b71Sopenharmony_ci  willDrawCallback = () => {
2659e41f4b71Sopenharmony_ci    console.info("willDraw instruction dispatched.")
2660e41f4b71Sopenharmony_ci  }
2661e41f4b71Sopenharmony_ci
2662e41f4b71Sopenharmony_ci  build() {
2663e41f4b71Sopenharmony_ci    Column() {
2664e41f4b71Sopenharmony_ci      Button('Subscribe to Drawing Instruction Dispatch')
2665e41f4b71Sopenharmony_ci        .onClick(() => {
2666e41f4b71Sopenharmony_ci          this.getUIContext().getUIObserver().on('willDraw', this.willDrawCallback);
2667e41f4b71Sopenharmony_ci        })
2668e41f4b71Sopenharmony_ci      Button('Unsubscribe from Drawing Instruction Dispatch')
2669e41f4b71Sopenharmony_ci        .onClick(() => {
2670e41f4b71Sopenharmony_ci          this.getUIContext().getUIObserver().off('willDraw', this.willDrawCallback);
2671e41f4b71Sopenharmony_ci        })
2672e41f4b71Sopenharmony_ci    }
2673e41f4b71Sopenharmony_ci  }
2674e41f4b71Sopenharmony_ci}
2675e41f4b71Sopenharmony_ci```
2676e41f4b71Sopenharmony_ci
2677e41f4b71Sopenharmony_ci### on('didLayout')<sup>12+</sup>
2678e41f4b71Sopenharmony_ci
2679e41f4b71Sopenharmony_cion(type: 'didLayout', callback: Callback\<void\>): void
2680e41f4b71Sopenharmony_ci
2681e41f4b71Sopenharmony_ciSubscribes to layout completion status in each frame.
2682e41f4b71Sopenharmony_ci
2683e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2684e41f4b71Sopenharmony_ci
2685e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2686e41f4b71Sopenharmony_ci
2687e41f4b71Sopenharmony_ci**Parameters** 
2688e41f4b71Sopenharmony_ci
2689e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2690e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2691e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'didLayout'** indicates whether the layout has been completed. |
2692e41f4b71Sopenharmony_ci| callback | Callback\<void\>        | Yes  | Callback used to return the result.                |
2693e41f4b71Sopenharmony_ci
2694e41f4b71Sopenharmony_ci```ts
2695e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI';
2696e41f4b71Sopenharmony_ci
2697e41f4b71Sopenharmony_ci@Entry
2698e41f4b71Sopenharmony_ci@Component
2699e41f4b71Sopenharmony_cistruct Index {
2700e41f4b71Sopenharmony_ci  didLayoutCallback = () => {
2701e41f4b71Sopenharmony_ci    console.info("Layout completed.");
2702e41f4b71Sopenharmony_ci  }
2703e41f4b71Sopenharmony_ci  build() {
2704e41f4b71Sopenharmony_ci    Column() {
2705e41f4b71Sopenharmony_ci      Button('Subscribe to Layout Completion')
2706e41f4b71Sopenharmony_ci        .onClick(() => {
2707e41f4b71Sopenharmony_ci          this.getUIContext().getUIObserver().on('didLayout', this.didLayoutCallback);
2708e41f4b71Sopenharmony_ci        })
2709e41f4b71Sopenharmony_ci    }
2710e41f4b71Sopenharmony_ci  }
2711e41f4b71Sopenharmony_ci}
2712e41f4b71Sopenharmony_ci```
2713e41f4b71Sopenharmony_ci
2714e41f4b71Sopenharmony_ci### off('didLayout')<sup>12+</sup>
2715e41f4b71Sopenharmony_ci
2716e41f4b71Sopenharmony_cioff(type: 'didLayout', callback?: Callback\<void\>): void
2717e41f4b71Sopenharmony_ci
2718e41f4b71Sopenharmony_ciUnsubscribes from layout completion status in each frame.
2719e41f4b71Sopenharmony_ci
2720e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2721e41f4b71Sopenharmony_ci
2722e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2723e41f4b71Sopenharmony_ci
2724e41f4b71Sopenharmony_ci**Parameters** 
2725e41f4b71Sopenharmony_ci
2726e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2727e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2728e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event event. The value **'didLayout'** indicates whether the layout has been completed. |
2729e41f4b71Sopenharmony_ci| callback | Callback\<void\>        | No  | Callback to be unregistered.                 |
2730e41f4b71Sopenharmony_ci
2731e41f4b71Sopenharmony_ci```ts
2732e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI';
2733e41f4b71Sopenharmony_ci
2734e41f4b71Sopenharmony_ci@Entry
2735e41f4b71Sopenharmony_ci@Component
2736e41f4b71Sopenharmony_cistruct Index {
2737e41f4b71Sopenharmony_ci  didLayoutCallback = () => {
2738e41f4b71Sopenharmony_ci    console.info("Layout completed.")
2739e41f4b71Sopenharmony_ci  }
2740e41f4b71Sopenharmony_ci
2741e41f4b71Sopenharmony_ci  build() {
2742e41f4b71Sopenharmony_ci    Column() {
2743e41f4b71Sopenharmony_ci      Button('Subscribe to Layout Completion')
2744e41f4b71Sopenharmony_ci        .onClick(() => {
2745e41f4b71Sopenharmony_ci          this.getUIContext().getUIObserver().on('didLayout', this.didLayoutCallback);
2746e41f4b71Sopenharmony_ci        })
2747e41f4b71Sopenharmony_ci      Button('Unsubscribe from Layout Completion')
2748e41f4b71Sopenharmony_ci        .onClick(() => {
2749e41f4b71Sopenharmony_ci          this.getUIContext().getUIObserver().off('didLayout', this.didLayoutCallback);
2750e41f4b71Sopenharmony_ci        })
2751e41f4b71Sopenharmony_ci    }
2752e41f4b71Sopenharmony_ci  }
2753e41f4b71Sopenharmony_ci}
2754e41f4b71Sopenharmony_ci```
2755e41f4b71Sopenharmony_ci
2756e41f4b71Sopenharmony_ci### on('navDestinationSwitch')<sup>12+</sup>
2757e41f4b71Sopenharmony_ci
2758e41f4b71Sopenharmony_cion(type: 'navDestinationSwitch', callback: Callback\<observer.NavDestinationSwitchInfo\>): void
2759e41f4b71Sopenharmony_ci
2760e41f4b71Sopenharmony_ciSubscribes to the page switching event of the **Navigation** component.
2761e41f4b71Sopenharmony_ci
2762e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2763e41f4b71Sopenharmony_ci
2764e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2765e41f4b71Sopenharmony_ci
2766e41f4b71Sopenharmony_ci**Parameters** 
2767e41f4b71Sopenharmony_ci
2768e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2769e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2770e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'navDestinationSwitch'** indicates the page switching event of the **Navigation** component. |
2771e41f4b71Sopenharmony_ci| callback | Callback\<observer.[NavDestinationSwitchInfo](js-apis-arkui-observer.md#navdestinationswitchinfo12)\>        | Yes  | Callback used to return the information about the page switching event.                |
2772e41f4b71Sopenharmony_ci
2773e41f4b71Sopenharmony_ci**Example**
2774e41f4b71Sopenharmony_ci
2775e41f4b71Sopenharmony_ci```ts
2776e41f4b71Sopenharmony_ci// Index.ets
2777e41f4b71Sopenharmony_ci// UIObserver.on('navDestinationSwitch', callback) demo
2778e41f4b71Sopenharmony_ci// UIObserver.off('navDestinationSwitch', callback)
2779e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI';
2780e41f4b71Sopenharmony_ci
2781e41f4b71Sopenharmony_ci@Component
2782e41f4b71Sopenharmony_cistruct PageOne {
2783e41f4b71Sopenharmony_ci  build() {
2784e41f4b71Sopenharmony_ci    NavDestination() {
2785e41f4b71Sopenharmony_ci      Text("pageOne")
2786e41f4b71Sopenharmony_ci    }.title("pageOne")
2787e41f4b71Sopenharmony_ci  }
2788e41f4b71Sopenharmony_ci}
2789e41f4b71Sopenharmony_ci
2790e41f4b71Sopenharmony_cifunction callBackFunc(info: uiObserver.NavDestinationSwitchInfo) {
2791e41f4b71Sopenharmony_ci  console.info(`testTag navDestinationSwitch from: ${JSON.stringify(info.from)} to: ${JSON.stringify(info.to)}`)
2792e41f4b71Sopenharmony_ci}
2793e41f4b71Sopenharmony_ci
2794e41f4b71Sopenharmony_ci@Entry
2795e41f4b71Sopenharmony_ci@Component
2796e41f4b71Sopenharmony_cistruct Index {
2797e41f4b71Sopenharmony_ci  private stack: NavPathStack = new NavPathStack();
2798e41f4b71Sopenharmony_ci
2799e41f4b71Sopenharmony_ci  @Builder
2800e41f4b71Sopenharmony_ci  PageBuilder(name: string) {
2801e41f4b71Sopenharmony_ci    PageOne()
2802e41f4b71Sopenharmony_ci  }
2803e41f4b71Sopenharmony_ci
2804e41f4b71Sopenharmony_ci  aboutToAppear() {
2805e41f4b71Sopenharmony_ci    let obs = this.getUIContext().getUIObserver();
2806e41f4b71Sopenharmony_ci    obs.on('navDestinationSwitch', callBackFunc);
2807e41f4b71Sopenharmony_ci  }
2808e41f4b71Sopenharmony_ci
2809e41f4b71Sopenharmony_ci  aboutToDisappear() {
2810e41f4b71Sopenharmony_ci    let obs = this.getUIContext().getUIObserver();
2811e41f4b71Sopenharmony_ci    obs.off('navDestinationSwitch', callBackFunc);
2812e41f4b71Sopenharmony_ci  }
2813e41f4b71Sopenharmony_ci
2814e41f4b71Sopenharmony_ci  build() {
2815e41f4b71Sopenharmony_ci    Column() {
2816e41f4b71Sopenharmony_ci      Navigation(this.stack) {
2817e41f4b71Sopenharmony_ci        Button("push").onClick(() => {
2818e41f4b71Sopenharmony_ci          this.stack.pushPath({name: "pageOne"});
2819e41f4b71Sopenharmony_ci        })
2820e41f4b71Sopenharmony_ci      }
2821e41f4b71Sopenharmony_ci      .title("Navigation")
2822e41f4b71Sopenharmony_ci      .navDestination(this.PageBuilder)
2823e41f4b71Sopenharmony_ci    }
2824e41f4b71Sopenharmony_ci    .width('100%')
2825e41f4b71Sopenharmony_ci    .height('100%')
2826e41f4b71Sopenharmony_ci  }
2827e41f4b71Sopenharmony_ci}
2828e41f4b71Sopenharmony_ci```
2829e41f4b71Sopenharmony_ci
2830e41f4b71Sopenharmony_ci### off('navDestinationSwitch')<sup>12+</sup>
2831e41f4b71Sopenharmony_ci
2832e41f4b71Sopenharmony_cioff(type: 'navDestinationSwitch', callback?: Callback\<observer.NavDestinationSwitchInfo\>): void
2833e41f4b71Sopenharmony_ci
2834e41f4b71Sopenharmony_ciUnsubscribes from the page switching event of the **Navigation** component.
2835e41f4b71Sopenharmony_ci
2836e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2837e41f4b71Sopenharmony_ci
2838e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2839e41f4b71Sopenharmony_ci
2840e41f4b71Sopenharmony_ci**Parameters** 
2841e41f4b71Sopenharmony_ci
2842e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2843e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2844e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'navDestinationSwitch'** indicates the page switching event of the **Navigation** component. |
2845e41f4b71Sopenharmony_ci| callback | Callback\<observer.[NavDestinationSwitchInfo](js-apis-arkui-observer.md#navdestinationswitchinfo12)\>        | No  | Callback to be unregistered.                |
2846e41f4b71Sopenharmony_ci
2847e41f4b71Sopenharmony_ciFor the sample code, see the sample code of the **UIObserver.on('navDestinationSwitch')** API.
2848e41f4b71Sopenharmony_ci
2849e41f4b71Sopenharmony_ci### on('navDestinationSwitch')<sup>12+</sup>
2850e41f4b71Sopenharmony_ci
2851e41f4b71Sopenharmony_cion(type: 'navDestinationSwitch', observerOptions: observer.NavDestinationSwitchObserverOptions, callback: Callback\<observer.NavDestinationSwitchInfo\>): void
2852e41f4b71Sopenharmony_ci
2853e41f4b71Sopenharmony_ciSubscribes to the page switching event of the **Navigation** component.
2854e41f4b71Sopenharmony_ci
2855e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2856e41f4b71Sopenharmony_ci
2857e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2858e41f4b71Sopenharmony_ci
2859e41f4b71Sopenharmony_ci**Parameters** 
2860e41f4b71Sopenharmony_ci
2861e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2862e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2863e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'navDestinationSwitch'** indicates the page switching event of the **Navigation** component. |
2864e41f4b71Sopenharmony_ci| observerOptions | observer.[NavDestinationSwitchObserverOptions](js-apis-arkui-observer.md#navdestinationswitchobserveroptions12)        | Yes  | Observer options.  |
2865e41f4b71Sopenharmony_ci| callback | Callback\<observer.[NavDestinationSwitchInfo](js-apis-arkui-observer.md#navdestinationswitchinfo12)\>        | Yes  | Callback used to return the information about the page switching event.                |
2866e41f4b71Sopenharmony_ci
2867e41f4b71Sopenharmony_ci**Example**
2868e41f4b71Sopenharmony_ci
2869e41f4b71Sopenharmony_ci```ts
2870e41f4b71Sopenharmony_ci// Index.ets
2871e41f4b71Sopenharmony_ci// Demo UIObserver.on('navDestinationSwitch', NavDestinationSwitchObserverOptions, callback)
2872e41f4b71Sopenharmony_ci// UIObserver.off('navDestinationSwitch', NavDestinationSwitchObserverOptions, callback)
2873e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI';
2874e41f4b71Sopenharmony_ci
2875e41f4b71Sopenharmony_ci@Component
2876e41f4b71Sopenharmony_cistruct PageOne {
2877e41f4b71Sopenharmony_ci  build() {
2878e41f4b71Sopenharmony_ci    NavDestination() {
2879e41f4b71Sopenharmony_ci      Text("pageOne")
2880e41f4b71Sopenharmony_ci    }.title("pageOne")
2881e41f4b71Sopenharmony_ci  }
2882e41f4b71Sopenharmony_ci}
2883e41f4b71Sopenharmony_ci
2884e41f4b71Sopenharmony_cifunction callBackFunc(info: uiObserver.NavDestinationSwitchInfo) {
2885e41f4b71Sopenharmony_ci  console.info(`testTag navDestinationSwitch from: ${JSON.stringify(info.from)} to: ${JSON.stringify(info.to)}`)
2886e41f4b71Sopenharmony_ci}
2887e41f4b71Sopenharmony_ci
2888e41f4b71Sopenharmony_ci@Entry
2889e41f4b71Sopenharmony_ci@Component
2890e41f4b71Sopenharmony_cistruct Index {
2891e41f4b71Sopenharmony_ci  private stack: NavPathStack = new NavPathStack();
2892e41f4b71Sopenharmony_ci
2893e41f4b71Sopenharmony_ci  @Builder
2894e41f4b71Sopenharmony_ci  PageBuilder(name: string) {
2895e41f4b71Sopenharmony_ci    PageOne()
2896e41f4b71Sopenharmony_ci  }
2897e41f4b71Sopenharmony_ci
2898e41f4b71Sopenharmony_ci  aboutToAppear() {
2899e41f4b71Sopenharmony_ci    let obs = this.getUIContext().getUIObserver();
2900e41f4b71Sopenharmony_ci    obs.on('navDestinationSwitch', { navigationId: "myNavId" }, callBackFunc)
2901e41f4b71Sopenharmony_ci  }
2902e41f4b71Sopenharmony_ci
2903e41f4b71Sopenharmony_ci  aboutToDisappear() {
2904e41f4b71Sopenharmony_ci    let obs = this.getUIContext().getUIObserver();
2905e41f4b71Sopenharmony_ci    obs.off('navDestinationSwitch', { navigationId: "myNavId" }, callBackFunc)
2906e41f4b71Sopenharmony_ci  }
2907e41f4b71Sopenharmony_ci
2908e41f4b71Sopenharmony_ci  build() {
2909e41f4b71Sopenharmony_ci    Column() {
2910e41f4b71Sopenharmony_ci      Navigation(this.stack) {
2911e41f4b71Sopenharmony_ci        Button("push").onClick(() => {
2912e41f4b71Sopenharmony_ci          this.stack.pushPath({name: "pageOne"});
2913e41f4b71Sopenharmony_ci        })
2914e41f4b71Sopenharmony_ci      }
2915e41f4b71Sopenharmony_ci      .id("myNavId")
2916e41f4b71Sopenharmony_ci      .title("Navigation")
2917e41f4b71Sopenharmony_ci      .navDestination(this.PageBuilder)
2918e41f4b71Sopenharmony_ci    }
2919e41f4b71Sopenharmony_ci    .width('100%')
2920e41f4b71Sopenharmony_ci    .height('100%')
2921e41f4b71Sopenharmony_ci  }
2922e41f4b71Sopenharmony_ci}
2923e41f4b71Sopenharmony_ci```
2924e41f4b71Sopenharmony_ci
2925e41f4b71Sopenharmony_ci### off('navDestinationSwitch')<sup>12+</sup>
2926e41f4b71Sopenharmony_ci
2927e41f4b71Sopenharmony_cioff(type: 'navDestinationSwitch', observerOptions: observer.NavDestinationSwitchObserverOptions, callback?: Callback\<observer.NavDestinationSwitchInfo\>): void
2928e41f4b71Sopenharmony_ci
2929e41f4b71Sopenharmony_ciUnsubscribes from the page switching event of the **Navigation** component.
2930e41f4b71Sopenharmony_ci
2931e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2932e41f4b71Sopenharmony_ci
2933e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2934e41f4b71Sopenharmony_ci
2935e41f4b71Sopenharmony_ci**Parameters** 
2936e41f4b71Sopenharmony_ci
2937e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2938e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2939e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'navDestinationSwitch'** indicates the page switching event of the **Navigation** component. |
2940e41f4b71Sopenharmony_ci| observerOptions | observer.[NavDestinationSwitchObserverOptions](js-apis-arkui-observer.md#navdestinationswitchobserveroptions12)        | Yes  | Observer options.  |
2941e41f4b71Sopenharmony_ci| callback | Callback\<observer.[NavDestinationSwitchInfo](js-apis-arkui-observer.md#navdestinationswitchinfo12)\>        | No  | Callback to be unregistered.                |
2942e41f4b71Sopenharmony_ci
2943e41f4b71Sopenharmony_ciFor the sample code, see the sample code of the **UIObserver.on('navDestinationSwitch')** API.
2944e41f4b71Sopenharmony_ci
2945e41f4b71Sopenharmony_ci### on('willClick')<sup>12+</sup>
2946e41f4b71Sopenharmony_ci
2947e41f4b71Sopenharmony_cion(type: 'willClick', callback: GestureEventListenerCallback): void
2948e41f4b71Sopenharmony_ci
2949e41f4b71Sopenharmony_ciSubscribes to the dispatch of click event instructions.
2950e41f4b71Sopenharmony_ci
2951e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2952e41f4b71Sopenharmony_ci
2953e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2954e41f4b71Sopenharmony_ci
2955e41f4b71Sopenharmony_ci**Parameters** 
2956e41f4b71Sopenharmony_ci
2957e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
2958e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2959e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'willClick'** indicates the dispatch of click event instructions. The registered callback is triggered when the click event is about to occur. |
2960e41f4b71Sopenharmony_ci| callback | [GestureEventListenerCallback](#gestureeventlistenercallback12) | Yes  | Callback used to return the **GestureEvent** object of the click event and the FrameNode of the component. |
2961e41f4b71Sopenharmony_ci
2962e41f4b71Sopenharmony_ci**Example**
2963e41f4b71Sopenharmony_ci
2964e41f4b71Sopenharmony_ci```ts
2965e41f4b71Sopenharmony_ci// Used in page components.
2966e41f4b71Sopenharmony_ciimport { UIContext, UIObserver, FrameNode } from '@kit.ArkUI';
2967e41f4b71Sopenharmony_ci
2968e41f4b71Sopenharmony_ci// callback is a callback defined by you.
2969e41f4b71Sopenharmony_cilet callback = (event: GestureEvent, frameNode?: FrameNode) => {};
2970e41f4b71Sopenharmony_cilet observer: UIObserver = this.getUIContext().getUIObserver();
2971e41f4b71Sopenharmony_ciobserver.on('willClick', callback);
2972e41f4b71Sopenharmony_ci```
2973e41f4b71Sopenharmony_ci
2974e41f4b71Sopenharmony_ci### off('willClick')<sup>12+</sup>
2975e41f4b71Sopenharmony_ci
2976e41f4b71Sopenharmony_cioff(type: 'willClick', callback?: GestureEventListenerCallback): void
2977e41f4b71Sopenharmony_ci
2978e41f4b71Sopenharmony_ciUnsubscribes from the dispatch of click event instructions.
2979e41f4b71Sopenharmony_ci
2980e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
2981e41f4b71Sopenharmony_ci
2982e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
2983e41f4b71Sopenharmony_ci
2984e41f4b71Sopenharmony_ci**Parameters** 
2985e41f4b71Sopenharmony_ci
2986e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                 |
2987e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
2988e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'willClick'** indicates the dispatch of click event instructions. |
2989e41f4b71Sopenharmony_ci| callback | [GestureEventListenerCallback](#gestureeventlistenercallback12) | No  | Callback to be unregistered.                               |
2990e41f4b71Sopenharmony_ci
2991e41f4b71Sopenharmony_ci**Example**
2992e41f4b71Sopenharmony_ci
2993e41f4b71Sopenharmony_ci```ts
2994e41f4b71Sopenharmony_ci// Used in page components.
2995e41f4b71Sopenharmony_ciimport { UIContext, UIObserver, FrameNode } from '@kit.ArkUI';
2996e41f4b71Sopenharmony_ci
2997e41f4b71Sopenharmony_ci// callback is a callback defined by you.
2998e41f4b71Sopenharmony_cilet callback = (event: GestureEvent, frameNode?: FrameNode) => {};
2999e41f4b71Sopenharmony_cilet observer: UIObserver = this.getUIContext().getUIObserver();
3000e41f4b71Sopenharmony_ciobserver.off('willClick', callback);
3001e41f4b71Sopenharmony_ci```
3002e41f4b71Sopenharmony_ci
3003e41f4b71Sopenharmony_ci### on('didClick')<sup>12+</sup>
3004e41f4b71Sopenharmony_ci
3005e41f4b71Sopenharmony_cion(type: 'didClick', callback: GestureEventListenerCallback): void
3006e41f4b71Sopenharmony_ci
3007e41f4b71Sopenharmony_ciSubscribes to the dispatch of click event instructions.
3008e41f4b71Sopenharmony_ci
3009e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3010e41f4b71Sopenharmony_ci
3011e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3012e41f4b71Sopenharmony_ci
3013e41f4b71Sopenharmony_ci**Parameters** 
3014e41f4b71Sopenharmony_ci
3015e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
3016e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
3017e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'didClick'** indicates the dispatch of click event instructions. The registered callback is triggered when the click event occurs. |
3018e41f4b71Sopenharmony_ci| callback | [GestureEventListenerCallback](#gestureeventlistenercallback12) | Yes  | Callback used to return the **GestureEvent** object of the click event and the FrameNode of the component. |
3019e41f4b71Sopenharmony_ci
3020e41f4b71Sopenharmony_ci**Example**
3021e41f4b71Sopenharmony_ci
3022e41f4b71Sopenharmony_ci```ts
3023e41f4b71Sopenharmony_ci// Used in page components.
3024e41f4b71Sopenharmony_ciimport { UIContext, UIObserver, FrameNode } from '@kit.ArkUI';
3025e41f4b71Sopenharmony_ci
3026e41f4b71Sopenharmony_ci// callback is a callback defined by you.
3027e41f4b71Sopenharmony_cilet callback = (event: GestureEvent, frameNode?: FrameNode) => {};
3028e41f4b71Sopenharmony_cilet observer: UIObserver = this.getUIContext().getUIObserver();
3029e41f4b71Sopenharmony_ciobserver.on('didClick', callback);
3030e41f4b71Sopenharmony_ci```
3031e41f4b71Sopenharmony_ci
3032e41f4b71Sopenharmony_ci### off('didClick')<sup>12+</sup>
3033e41f4b71Sopenharmony_ci
3034e41f4b71Sopenharmony_cioff(type: 'didClick', callback?: GestureEventListenerCallback): void
3035e41f4b71Sopenharmony_ci
3036e41f4b71Sopenharmony_ciUnsubscribes from the dispatch of click event instructions.
3037e41f4b71Sopenharmony_ci
3038e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3039e41f4b71Sopenharmony_ci
3040e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3041e41f4b71Sopenharmony_ci
3042e41f4b71Sopenharmony_ci**Parameters** 
3043e41f4b71Sopenharmony_ci
3044e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                |
3045e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ---------------------------------------------------- |
3046e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'didClick'** indicates the dispatch of click event instructions. |
3047e41f4b71Sopenharmony_ci| callback | [GestureEventListenerCallback](#gestureeventlistenercallback12) | No  | Callback to be unregistered.                              |
3048e41f4b71Sopenharmony_ci
3049e41f4b71Sopenharmony_ci**Example**
3050e41f4b71Sopenharmony_ci
3051e41f4b71Sopenharmony_ci```ts
3052e41f4b71Sopenharmony_ci// Used in page components.
3053e41f4b71Sopenharmony_ciimport { UIContext, UIObserver, FrameNode } from '@kit.ArkUI';
3054e41f4b71Sopenharmony_ci
3055e41f4b71Sopenharmony_ci// callback is a callback defined by you.
3056e41f4b71Sopenharmony_cilet callback = (event: GestureEvent, frameNode?: FrameNode) => {};
3057e41f4b71Sopenharmony_cilet observer: UIObserver = this.getUIContext().getUIObserver();
3058e41f4b71Sopenharmony_ciobserver.off('didClick', callback);
3059e41f4b71Sopenharmony_ci```
3060e41f4b71Sopenharmony_ci
3061e41f4b71Sopenharmony_ci### on('willClick')<sup>12+</sup>
3062e41f4b71Sopenharmony_ci
3063e41f4b71Sopenharmony_cion(type: 'willClick', callback: ClickEventListenerCallback): void
3064e41f4b71Sopenharmony_ci
3065e41f4b71Sopenharmony_ciSubscribes to the dispatch of click event instructions.
3066e41f4b71Sopenharmony_ci
3067e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3068e41f4b71Sopenharmony_ci
3069e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3070e41f4b71Sopenharmony_ci
3071e41f4b71Sopenharmony_ci**Parameters** 
3072e41f4b71Sopenharmony_ci
3073e41f4b71Sopenharmony_ci| Name  | Type                                                       | Mandatory | Description                                                        |
3074e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
3075e41f4b71Sopenharmony_ci| type     | string                                                      | Yes  | Event type. The value **'willClick'** indicates the dispatch of click event instructions. The registered callback is triggered when the click event is about to occur. |
3076e41f4b71Sopenharmony_ci| callback | [ClickEventListenerCallback](#clickeventlistenercallback12) | Yes  | Callback used to return the **ClickEvent** object and the FrameNode of the component.   |
3077e41f4b71Sopenharmony_ci
3078e41f4b71Sopenharmony_ci**Example**
3079e41f4b71Sopenharmony_ci
3080e41f4b71Sopenharmony_ci```ts
3081e41f4b71Sopenharmony_ci// Used in page components.
3082e41f4b71Sopenharmony_ciimport { UIContext, UIObserver, FrameNode } from '@kit.ArkUI';
3083e41f4b71Sopenharmony_ci
3084e41f4b71Sopenharmony_ci// callback is a callback defined by you.
3085e41f4b71Sopenharmony_cilet callback = (event: ClickEvent, frameNode?: FrameNode) => {};
3086e41f4b71Sopenharmony_cilet observer: UIObserver = this.getUIContext().getUIObserver();
3087e41f4b71Sopenharmony_ciobserver.on('willClick', callback);
3088e41f4b71Sopenharmony_ci```
3089e41f4b71Sopenharmony_ci
3090e41f4b71Sopenharmony_ci### off('willClick')<sup>12+</sup>
3091e41f4b71Sopenharmony_ci
3092e41f4b71Sopenharmony_cioff(type: 'willClick', callback?: ClickEventListenerCallback): void
3093e41f4b71Sopenharmony_ci
3094e41f4b71Sopenharmony_ciUnsubscribes from the dispatch of click event instructions.
3095e41f4b71Sopenharmony_ci
3096e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3097e41f4b71Sopenharmony_ci
3098e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3099e41f4b71Sopenharmony_ci
3100e41f4b71Sopenharmony_ci**Parameters** 
3101e41f4b71Sopenharmony_ci
3102e41f4b71Sopenharmony_ci| Name  | Type                                                       | Mandatory | Description                                                 |
3103e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------------- | ---- | ----------------------------------------------------- |
3104e41f4b71Sopenharmony_ci| type     | string                                                      | Yes  | Event type. The value **'willClick'** indicates the dispatch of click event instructions. |
3105e41f4b71Sopenharmony_ci| callback | [ClickEventListenerCallback](#clickeventlistenercallback12) | No  | Callback to be unregistered.                               |
3106e41f4b71Sopenharmony_ci
3107e41f4b71Sopenharmony_ci**Example**
3108e41f4b71Sopenharmony_ci
3109e41f4b71Sopenharmony_ci```ts
3110e41f4b71Sopenharmony_ci// Used in page components.
3111e41f4b71Sopenharmony_ciimport { UIContext, UIObserver, FrameNode } from '@kit.ArkUI';
3112e41f4b71Sopenharmony_ci
3113e41f4b71Sopenharmony_ci// callback is a callback defined by you.
3114e41f4b71Sopenharmony_cilet callback = (event: ClickEvent, frameNode?: FrameNode) => {};
3115e41f4b71Sopenharmony_cilet observer: UIObserver = this.getUIContext().getUIObserver();
3116e41f4b71Sopenharmony_ciobserver.off('willClick', callback);
3117e41f4b71Sopenharmony_ci```
3118e41f4b71Sopenharmony_ci
3119e41f4b71Sopenharmony_ci### on('didClick')<sup>12+</sup>
3120e41f4b71Sopenharmony_ci
3121e41f4b71Sopenharmony_cion(type: 'didClick', callback: ClickEventListenerCallback): void
3122e41f4b71Sopenharmony_ci
3123e41f4b71Sopenharmony_ciSubscribes to the dispatch of click event instructions.
3124e41f4b71Sopenharmony_ci
3125e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3126e41f4b71Sopenharmony_ci
3127e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3128e41f4b71Sopenharmony_ci
3129e41f4b71Sopenharmony_ci**Parameters** 
3130e41f4b71Sopenharmony_ci
3131e41f4b71Sopenharmony_ci| Name  | Type                                                       | Mandatory | Description                                                        |
3132e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
3133e41f4b71Sopenharmony_ci| type     | string                                                      | Yes  | Event type. The value **'didClick'** indicates the dispatch of click event instructions. The registered callback is triggered after the click event is about to occur. |
3134e41f4b71Sopenharmony_ci| callback | [ClickEventListenerCallback](#clickeventlistenercallback12) | Yes  | Callback used to return the **ClickEvent** object and the FrameNode of the component.   |
3135e41f4b71Sopenharmony_ci
3136e41f4b71Sopenharmony_ci**Example**
3137e41f4b71Sopenharmony_ci
3138e41f4b71Sopenharmony_ci```ts
3139e41f4b71Sopenharmony_ci// Used in page components.
3140e41f4b71Sopenharmony_ciimport { UIContext, UIObserver, FrameNode } from '@kit.ArkUI';
3141e41f4b71Sopenharmony_ci
3142e41f4b71Sopenharmony_ci// callback is a callback defined by you.
3143e41f4b71Sopenharmony_cilet callback = (event: ClickEvent, frameNode?: FrameNode) => {};
3144e41f4b71Sopenharmony_cilet observer: UIObserver = this.getUIContext().getUIObserver();
3145e41f4b71Sopenharmony_ciobserver.on('didClick', callback);
3146e41f4b71Sopenharmony_ci```
3147e41f4b71Sopenharmony_ci
3148e41f4b71Sopenharmony_ci### off('didClick')<sup>12+</sup>
3149e41f4b71Sopenharmony_ci
3150e41f4b71Sopenharmony_cioff(type: 'didClick', callback?: ClickEventListenerCallback): void
3151e41f4b71Sopenharmony_ci
3152e41f4b71Sopenharmony_ciUnsubscribes from the dispatch of click event instructions.
3153e41f4b71Sopenharmony_ci
3154e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3155e41f4b71Sopenharmony_ci
3156e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3157e41f4b71Sopenharmony_ci
3158e41f4b71Sopenharmony_ci**Parameters** 
3159e41f4b71Sopenharmony_ci
3160e41f4b71Sopenharmony_ci| Name  | Type                                                       | Mandatory | Description                                                |
3161e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------------- | ---- | ---------------------------------------------------- |
3162e41f4b71Sopenharmony_ci| type     | string                                                      | Yes  | Event type. The value **'didClick'** indicates the dispatch of click event instructions. |
3163e41f4b71Sopenharmony_ci| callback | [ClickEventListenerCallback](#clickeventlistenercallback12) | No  | Callback to be unregistered.                              |
3164e41f4b71Sopenharmony_ci
3165e41f4b71Sopenharmony_ci**Example**
3166e41f4b71Sopenharmony_ci
3167e41f4b71Sopenharmony_ci```ts
3168e41f4b71Sopenharmony_ci// Used in page components.
3169e41f4b71Sopenharmony_ciimport { UIContext, UIObserver, FrameNode } from '@kit.ArkUI';
3170e41f4b71Sopenharmony_ci
3171e41f4b71Sopenharmony_ci// callback is a callback defined by you.
3172e41f4b71Sopenharmony_cilet callback = (event: ClickEvent, frameNode?: FrameNode) => {};
3173e41f4b71Sopenharmony_cilet observer: UIObserver = this.getUIContext().getUIObserver();
3174e41f4b71Sopenharmony_ciobserver.off('didClick', callback);
3175e41f4b71Sopenharmony_ci```
3176e41f4b71Sopenharmony_ci
3177e41f4b71Sopenharmony_ci### on('tabContentUpdate')<sup>12+</sup>
3178e41f4b71Sopenharmony_ci
3179e41f4b71Sopenharmony_cion(type: 'tabContentUpdate', callback: Callback\<observer.TabContentInfo\>): void
3180e41f4b71Sopenharmony_ci
3181e41f4b71Sopenharmony_ciSubscribes to the **TabContent** switching event.
3182e41f4b71Sopenharmony_ci
3183e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3184e41f4b71Sopenharmony_ci
3185e41f4b71Sopenharmony_ci**Parameters** 
3186e41f4b71Sopenharmony_ci
3187e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
3188e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
3189e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'tabContentUpdate'** indicates the **TabContent** switching event. |
3190e41f4b71Sopenharmony_ci| callback | Callback\<observer.[TabContentInfo](js-apis-arkui-observer.md#tabcontentinfo12)\> | Yes  | Callback used to return the information about the **TabContent** switching event. |
3191e41f4b71Sopenharmony_ci
3192e41f4b71Sopenharmony_ci**Example**
3193e41f4b71Sopenharmony_ci
3194e41f4b71Sopenharmony_ci```ts
3195e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI';
3196e41f4b71Sopenharmony_ci
3197e41f4b71Sopenharmony_cifunction callbackFunc(info: uiObserver.TabContentInfo) {
3198e41f4b71Sopenharmony_ci  console.info('tabContentUpdate', JSON.stringify(info));
3199e41f4b71Sopenharmony_ci}
3200e41f4b71Sopenharmony_ci
3201e41f4b71Sopenharmony_ci@Entry
3202e41f4b71Sopenharmony_ci@Component
3203e41f4b71Sopenharmony_cistruct TabsExample {
3204e41f4b71Sopenharmony_ci
3205e41f4b71Sopenharmony_ci  aboutToAppear(): void {
3206e41f4b71Sopenharmony_ci    let observer = this.getUIContext().getUIObserver();
3207e41f4b71Sopenharmony_ci    observer.on('tabContentUpdate', callbackFunc);
3208e41f4b71Sopenharmony_ci  }
3209e41f4b71Sopenharmony_ci
3210e41f4b71Sopenharmony_ci  aboutToDisappear(): void {
3211e41f4b71Sopenharmony_ci    let observer = this.getUIContext().getUIObserver();
3212e41f4b71Sopenharmony_ci    observer.off('tabContentUpdate', callbackFunc);
3213e41f4b71Sopenharmony_ci  }
3214e41f4b71Sopenharmony_ci
3215e41f4b71Sopenharmony_ci  build() {
3216e41f4b71Sopenharmony_ci    Column() {
3217e41f4b71Sopenharmony_ci      Tabs() {
3218e41f4b71Sopenharmony_ci        TabContent() {
3219e41f4b71Sopenharmony_ci          Column().width('100%').height('100%').backgroundColor('#00CB87')
3220e41f4b71Sopenharmony_ci        }.tabBar('green').id('tabContentId0')
3221e41f4b71Sopenharmony_ci
3222e41f4b71Sopenharmony_ci        TabContent() {
3223e41f4b71Sopenharmony_ci          Column().width('100%').height('100%').backgroundColor('#007DFF')
3224e41f4b71Sopenharmony_ci        }.tabBar('blue').id('tabContentId1')
3225e41f4b71Sopenharmony_ci
3226e41f4b71Sopenharmony_ci        TabContent() {
3227e41f4b71Sopenharmony_ci          Column().width('100%').height('100%').backgroundColor('#FFBF00')
3228e41f4b71Sopenharmony_ci        }.tabBar('yellow').id('tabContentId2')
3229e41f4b71Sopenharmony_ci
3230e41f4b71Sopenharmony_ci        TabContent() {
3231e41f4b71Sopenharmony_ci          Column().width('100%').height('100%').backgroundColor('#E67C92')
3232e41f4b71Sopenharmony_ci        }.tabBar('pink').id('tabContentId3')
3233e41f4b71Sopenharmony_ci      }
3234e41f4b71Sopenharmony_ci      .width(360)
3235e41f4b71Sopenharmony_ci      .height(296)
3236e41f4b71Sopenharmony_ci      .backgroundColor('#F1F3F5')
3237e41f4b71Sopenharmony_ci      .id('tabsId')
3238e41f4b71Sopenharmony_ci    }.width('100%')
3239e41f4b71Sopenharmony_ci  }
3240e41f4b71Sopenharmony_ci}
3241e41f4b71Sopenharmony_ci```
3242e41f4b71Sopenharmony_ci
3243e41f4b71Sopenharmony_ci### off('tabContentUpdate')<sup>12+</sup>
3244e41f4b71Sopenharmony_ci
3245e41f4b71Sopenharmony_cioff(type: 'tabContentUpdate', callback?: Callback\<observer.TabContentInfo\>): void
3246e41f4b71Sopenharmony_ci
3247e41f4b71Sopenharmony_ciUnsubscribes from the **TabContent** switching event.
3248e41f4b71Sopenharmony_ci
3249e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3250e41f4b71Sopenharmony_ci
3251e41f4b71Sopenharmony_ci**Parameters** 
3252e41f4b71Sopenharmony_ci
3253e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
3254e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
3255e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'tabContentUpdate'** indicates the **TabContent** switching event. |
3256e41f4b71Sopenharmony_ci| callback | Callback\<observer.[TabContentInfo](js-apis-arkui-observer.md#tabcontentinfo12)\> | No  | Callback to be unregistered. |
3257e41f4b71Sopenharmony_ci
3258e41f4b71Sopenharmony_ci**Example**
3259e41f4b71Sopenharmony_ci
3260e41f4b71Sopenharmony_ciSee the example of [on('tabContentUpdate')](#ontabcontentupdate12).
3261e41f4b71Sopenharmony_ci
3262e41f4b71Sopenharmony_ci### on('tabContentUpdate')<sup>12+</sup>
3263e41f4b71Sopenharmony_ci
3264e41f4b71Sopenharmony_cion(type: 'tabContentUpdate', options: observer.ObserverOptions, callback: Callback\<observer.TabContentInfo\>): void
3265e41f4b71Sopenharmony_ci
3266e41f4b71Sopenharmony_ciSubscribes to the **TabContent** switching event.
3267e41f4b71Sopenharmony_ci
3268e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3269e41f4b71Sopenharmony_ci
3270e41f4b71Sopenharmony_ci**Parameters** 
3271e41f4b71Sopenharmony_ci
3272e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
3273e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
3274e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'tabContentUpdate'** indicates the **TabContent** switching event. |
3275e41f4b71Sopenharmony_ci| options  | observer.[ObserverOptions](js-apis-arkui-observer.md#observeroptions12) | Yes  | ID of the target **Tabs** component. |
3276e41f4b71Sopenharmony_ci| callback | Callback\<observer.[TabContentInfo](js-apis-arkui-observer.md#tabcontentinfo12)\> | Yes  | Callback used to return the information about the **TabContent** switching event. |
3277e41f4b71Sopenharmony_ci
3278e41f4b71Sopenharmony_ci**Example**
3279e41f4b71Sopenharmony_ci
3280e41f4b71Sopenharmony_ci```ts
3281e41f4b71Sopenharmony_ciimport { uiObserver } from '@kit.ArkUI';
3282e41f4b71Sopenharmony_ci
3283e41f4b71Sopenharmony_cifunction callbackFunc(info: uiObserver.TabContentInfo) {
3284e41f4b71Sopenharmony_ci  console.info('tabContentUpdate', JSON.stringify(info));
3285e41f4b71Sopenharmony_ci}
3286e41f4b71Sopenharmony_ci
3287e41f4b71Sopenharmony_ci@Entry
3288e41f4b71Sopenharmony_ci@Component
3289e41f4b71Sopenharmony_cistruct TabsExample {
3290e41f4b71Sopenharmony_ci
3291e41f4b71Sopenharmony_ci  aboutToAppear(): void {
3292e41f4b71Sopenharmony_ci    let observer = this.getUIContext().getUIObserver();
3293e41f4b71Sopenharmony_ci    observer.on('tabContentUpdate', { id: 'tabsId' }, callbackFunc);
3294e41f4b71Sopenharmony_ci  }
3295e41f4b71Sopenharmony_ci
3296e41f4b71Sopenharmony_ci  aboutToDisappear(): void {
3297e41f4b71Sopenharmony_ci    let observer = this.getUIContext().getUIObserver();
3298e41f4b71Sopenharmony_ci    observer.off('tabContentUpdate', { id: 'tabsId' }, callbackFunc);
3299e41f4b71Sopenharmony_ci  }
3300e41f4b71Sopenharmony_ci
3301e41f4b71Sopenharmony_ci  build() {
3302e41f4b71Sopenharmony_ci    Column() {
3303e41f4b71Sopenharmony_ci      Tabs() {
3304e41f4b71Sopenharmony_ci        TabContent() {
3305e41f4b71Sopenharmony_ci          Column().width('100%').height('100%').backgroundColor('#00CB87')
3306e41f4b71Sopenharmony_ci        }.tabBar('green').id('tabContentId0')
3307e41f4b71Sopenharmony_ci
3308e41f4b71Sopenharmony_ci        TabContent() {
3309e41f4b71Sopenharmony_ci          Column().width('100%').height('100%').backgroundColor('#007DFF')
3310e41f4b71Sopenharmony_ci        }.tabBar('blue').id('tabContentId1')
3311e41f4b71Sopenharmony_ci
3312e41f4b71Sopenharmony_ci        TabContent() {
3313e41f4b71Sopenharmony_ci          Column().width('100%').height('100%').backgroundColor('#FFBF00')
3314e41f4b71Sopenharmony_ci        }.tabBar('yellow').id('tabContentId2')
3315e41f4b71Sopenharmony_ci
3316e41f4b71Sopenharmony_ci        TabContent() {
3317e41f4b71Sopenharmony_ci          Column().width('100%').height('100%').backgroundColor('#E67C92')
3318e41f4b71Sopenharmony_ci        }.tabBar('pink').id('tabContentId3')
3319e41f4b71Sopenharmony_ci      }
3320e41f4b71Sopenharmony_ci      .width(360)
3321e41f4b71Sopenharmony_ci      .height(296)
3322e41f4b71Sopenharmony_ci      .backgroundColor('#F1F3F5')
3323e41f4b71Sopenharmony_ci      .id('tabsId')
3324e41f4b71Sopenharmony_ci    }.width('100%')
3325e41f4b71Sopenharmony_ci  }
3326e41f4b71Sopenharmony_ci}
3327e41f4b71Sopenharmony_ci```
3328e41f4b71Sopenharmony_ci
3329e41f4b71Sopenharmony_ci### off('tabContentUpdate')<sup>12+</sup>
3330e41f4b71Sopenharmony_ci
3331e41f4b71Sopenharmony_cioff(type: 'tabContentUpdate', options: observer.ObserverOptions, callback?: Callback\<observer.TabContentInfo\>): void
3332e41f4b71Sopenharmony_ci
3333e41f4b71Sopenharmony_ciUnsubscribes from the **TabContent** switching event.
3334e41f4b71Sopenharmony_ci
3335e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3336e41f4b71Sopenharmony_ci
3337e41f4b71Sopenharmony_ci**Parameters** 
3338e41f4b71Sopenharmony_ci
3339e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
3340e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
3341e41f4b71Sopenharmony_ci| type     | string                                                       | Yes  | Event type. The value **'tabContentUpdate'** indicates the **TabContent** switching event. |
3342e41f4b71Sopenharmony_ci| options  | observer.[ObserverOptions](js-apis-arkui-observer.md#observeroptions12) | Yes  | ID of the target **Tabs** component. |
3343e41f4b71Sopenharmony_ci| callback | Callback\<observer.[TabContentInfo](js-apis-arkui-observer.md#tabcontentinfo12)\> | No  | Callback to be unregistered. |
3344e41f4b71Sopenharmony_ci
3345e41f4b71Sopenharmony_ci**Example**
3346e41f4b71Sopenharmony_ci
3347e41f4b71Sopenharmony_ciSee the example of [on('tabContentUpdate')](#ontabcontentupdate12-1).
3348e41f4b71Sopenharmony_ci
3349e41f4b71Sopenharmony_ci## GestureEventListenerCallback<sup>12+</sup>
3350e41f4b71Sopenharmony_citype GestureEventListenerCallback = (event: GestureEvent, node?: FrameNode) => void
3351e41f4b71Sopenharmony_ci
3352e41f4b71Sopenharmony_ciImplements a callback for the ArkTS gesture event.
3353e41f4b71Sopenharmony_ci
3354e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3355e41f4b71Sopenharmony_ci
3356e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3357e41f4b71Sopenharmony_ci
3358e41f4b71Sopenharmony_ci**Parameters**
3359e41f4b71Sopenharmony_ci
3360e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                         |
3361e41f4b71Sopenharmony_ci| ------- | ------ | ---- | --------------------------- |
3362e41f4b71Sopenharmony_ci| event | [GestureEvent](../apis-arkui/arkui-ts/ts-gesture-settings.md#gestureevent) | Yes | Information about the subscribed-to gesture event. |
3363e41f4b71Sopenharmony_ci| node | [FrameNode](js-apis-arkui-frameNode.md#framenode) | No | Component bound to the subscribed-to gesture event. |
3364e41f4b71Sopenharmony_ci
3365e41f4b71Sopenharmony_ci## ClickEventListenerCallback<sup>12+</sup>
3366e41f4b71Sopenharmony_citype ClickEventListenerCallback = (event: ClickEvent, node?: FrameNode) => void
3367e41f4b71Sopenharmony_ci
3368e41f4b71Sopenharmony_ciImplements a callback for the ArkTS gesture event.
3369e41f4b71Sopenharmony_ci
3370e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
3371e41f4b71Sopenharmony_ci
3372e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3373e41f4b71Sopenharmony_ci
3374e41f4b71Sopenharmony_ci**Parameters**
3375e41f4b71Sopenharmony_ci
3376e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                         |
3377e41f4b71Sopenharmony_ci| ------- | ------ | ---- | --------------------------- |
3378e41f4b71Sopenharmony_ci| event | [ClickEvent](../apis-arkui/arkui-ts/ts-universal-events-click.md#clickevent) | Yes | Information about the subscribed-to click event. |
3379e41f4b71Sopenharmony_ci| node | [FrameNode](js-apis-arkui-frameNode.md#framenode) | No | Component bound to the subscribed-to click event. |
3380e41f4b71Sopenharmony_ci
3381e41f4b71Sopenharmony_ci## MediaQuery
3382e41f4b71Sopenharmony_ci
3383e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getMediaQuery()](#getmediaquery) in **UIContext** to obtain a **MediaQuery** instance, and then call the APIs using the obtained instance.
3384e41f4b71Sopenharmony_ci
3385e41f4b71Sopenharmony_ci### matchMediaSync
3386e41f4b71Sopenharmony_ci
3387e41f4b71Sopenharmony_cimatchMediaSync(condition: string): mediaQuery.MediaQueryListener
3388e41f4b71Sopenharmony_ci
3389e41f4b71Sopenharmony_ciSets the media query criteria and returns the corresponding listening handle.
3390e41f4b71Sopenharmony_ci
3391e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3392e41f4b71Sopenharmony_ci
3393e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3394e41f4b71Sopenharmony_ci
3395e41f4b71Sopenharmony_ci**Parameters**
3396e41f4b71Sopenharmony_ci
3397e41f4b71Sopenharmony_ci| Name      | Type    | Mandatory  | Description                                      |
3398e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ---------------------------------------- |
3399e41f4b71Sopenharmony_ci| condition | string | Yes   | Media query condition. For details, see [Syntax](../../ui/arkts-layout-development-media-query.md#syntax). |
3400e41f4b71Sopenharmony_ci
3401e41f4b71Sopenharmony_ci**Return value**
3402e41f4b71Sopenharmony_ci
3403e41f4b71Sopenharmony_ci| Type                                                        | Description                                        |
3404e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | -------------------------------------------- |
3405e41f4b71Sopenharmony_ci| [mediaQuery.MediaQueryListener](js-apis-mediaquery.md#mediaquerylistener) | Listening handle to a media event, which is used to register or unregister the listening callback. |
3406e41f4b71Sopenharmony_ci
3407e41f4b71Sopenharmony_ci**Example**
3408e41f4b71Sopenharmony_ci
3409e41f4b71Sopenharmony_ci```ts
3410e41f4b71Sopenharmony_ciimport { MediaQuery } from '@kit.ArkUI';
3411e41f4b71Sopenharmony_ci
3412e41f4b71Sopenharmony_cilet mediaquery: MediaQuery = uiContext.getMediaQuery();
3413e41f4b71Sopenharmony_cilet listener = mediaquery.matchMediaSync('(orientation: landscape)'); // Listen for landscape events.
3414e41f4b71Sopenharmony_ci```
3415e41f4b71Sopenharmony_ci
3416e41f4b71Sopenharmony_ci## Router
3417e41f4b71Sopenharmony_ci
3418e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getRouter()](#getrouter) in **UIContext** to obtain a **Router** instance, and then call the APIs using the obtained instance.
3419e41f4b71Sopenharmony_ci
3420e41f4b71Sopenharmony_ci### pushUrl
3421e41f4b71Sopenharmony_ci
3422e41f4b71Sopenharmony_cipushUrl(options: router.RouterOptions): Promise&lt;void&gt;
3423e41f4b71Sopenharmony_ci
3424e41f4b71Sopenharmony_ciNavigates to a specified page in the application. This API uses a promise to return the result.
3425e41f4b71Sopenharmony_ci
3426e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3427e41f4b71Sopenharmony_ci
3428e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3429e41f4b71Sopenharmony_ci
3430e41f4b71Sopenharmony_ci**Parameters**
3431e41f4b71Sopenharmony_ci
3432e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description       |
3433e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | --------- |
3434e41f4b71Sopenharmony_ci| options | [router.RouterOptions](js-apis-router.md#routeroptions) | Yes   | Page routing parameters. |
3435e41f4b71Sopenharmony_ci
3436e41f4b71Sopenharmony_ci**Return value**
3437e41f4b71Sopenharmony_ci
3438e41f4b71Sopenharmony_ci| Type                 | Description     |
3439e41f4b71Sopenharmony_ci| ------------------- | ------- |
3440e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise used to return the result. |
3441e41f4b71Sopenharmony_ci
3442e41f4b71Sopenharmony_ci**Error codes**
3443e41f4b71Sopenharmony_ci
3444e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
3445e41f4b71Sopenharmony_ci
3446e41f4b71Sopenharmony_ci| ID | Error Message                              |
3447e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
3448e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
3449e41f4b71Sopenharmony_ci| 100001 | Internal error. |
3450e41f4b71Sopenharmony_ci| 100002 | Uri error. The URI of the page to redirect is incorrect or does not exist.           |
3451e41f4b71Sopenharmony_ci| 100003 | Page stack error. Too many pages are pushed.  |
3452e41f4b71Sopenharmony_ci
3453e41f4b71Sopenharmony_ci**Example**
3454e41f4b71Sopenharmony_ci
3455e41f4b71Sopenharmony_ci```ts
3456e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
3457e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3458e41f4b71Sopenharmony_ci
3459e41f4b71Sopenharmony_cilet router:Router = uiContext.getRouter();
3460e41f4b71Sopenharmony_citry {
3461e41f4b71Sopenharmony_ci  router.pushUrl({
3462e41f4b71Sopenharmony_ci    url: 'pages/routerpage2',
3463e41f4b71Sopenharmony_ci    params: {
3464e41f4b71Sopenharmony_ci      data1: 'message',
3465e41f4b71Sopenharmony_ci      data2: {
3466e41f4b71Sopenharmony_ci        data3: [123, 456, 789]
3467e41f4b71Sopenharmony_ci      }
3468e41f4b71Sopenharmony_ci    }
3469e41f4b71Sopenharmony_ci  })
3470e41f4b71Sopenharmony_ci} catch (err) {
3471e41f4b71Sopenharmony_ci  let message = (err as BusinessError).message;
3472e41f4b71Sopenharmony_ci  let code = (err as BusinessError).code;
3473e41f4b71Sopenharmony_ci  console.error(`pushUrl failed, code is ${code}, message is ${message}`);
3474e41f4b71Sopenharmony_ci}
3475e41f4b71Sopenharmony_ci```
3476e41f4b71Sopenharmony_ci
3477e41f4b71Sopenharmony_ci### pushUrl
3478e41f4b71Sopenharmony_ci
3479e41f4b71Sopenharmony_cipushUrl(options: router.RouterOptions, callback: AsyncCallback&lt;void&gt;): void
3480e41f4b71Sopenharmony_ci
3481e41f4b71Sopenharmony_ciNavigates to a specified page in the application.
3482e41f4b71Sopenharmony_ci
3483e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3484e41f4b71Sopenharmony_ci
3485e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3486e41f4b71Sopenharmony_ci
3487e41f4b71Sopenharmony_ci**Parameters**
3488e41f4b71Sopenharmony_ci
3489e41f4b71Sopenharmony_ci| Name     | Type                                      | Mandatory  | Description       |
3490e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | --------- |
3491e41f4b71Sopenharmony_ci| options  | [router.RouterOptions](js-apis-router.md#routeroptions) | Yes   | Page routing parameters. |
3492e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt;                | Yes   | Callback used to return the result.  |
3493e41f4b71Sopenharmony_ci
3494e41f4b71Sopenharmony_ci**Error codes**
3495e41f4b71Sopenharmony_ci
3496e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
3497e41f4b71Sopenharmony_ci
3498e41f4b71Sopenharmony_ci| ID | Error Message                              |
3499e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
3500e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
3501e41f4b71Sopenharmony_ci| 100001 | Internal error. |
3502e41f4b71Sopenharmony_ci| 100002 | Uri error. The URI of the page to redirect is incorrect or does not exist.           |
3503e41f4b71Sopenharmony_ci| 100003 | Page stack error. Too many pages are pushed.  |
3504e41f4b71Sopenharmony_ci
3505e41f4b71Sopenharmony_ci**Example**
3506e41f4b71Sopenharmony_ci
3507e41f4b71Sopenharmony_ci```ts
3508e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
3509e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3510e41f4b71Sopenharmony_ci
3511e41f4b71Sopenharmony_cilet router:Router = uiContext.getRouter();
3512e41f4b71Sopenharmony_cirouter.pushUrl({
3513e41f4b71Sopenharmony_ci  url: 'pages/routerpage2',
3514e41f4b71Sopenharmony_ci  params: {
3515e41f4b71Sopenharmony_ci    data1: 'message',
3516e41f4b71Sopenharmony_ci    data2: {
3517e41f4b71Sopenharmony_ci      data3: [123, 456, 789]
3518e41f4b71Sopenharmony_ci    }
3519e41f4b71Sopenharmony_ci  }
3520e41f4b71Sopenharmony_ci}, (err: Error) => {
3521e41f4b71Sopenharmony_ci  if (err) {
3522e41f4b71Sopenharmony_ci    let message = (err as BusinessError).message;
3523e41f4b71Sopenharmony_ci    let code = (err as BusinessError).code;
3524e41f4b71Sopenharmony_ci    console.error(`pushUrl failed, code is ${code}, message is ${message}`);
3525e41f4b71Sopenharmony_ci    return;
3526e41f4b71Sopenharmony_ci  }
3527e41f4b71Sopenharmony_ci  console.info('pushUrl success');
3528e41f4b71Sopenharmony_ci})
3529e41f4b71Sopenharmony_ci```
3530e41f4b71Sopenharmony_ci
3531e41f4b71Sopenharmony_ci### pushUrl
3532e41f4b71Sopenharmony_ci
3533e41f4b71Sopenharmony_cipushUrl(options: router.RouterOptions, mode: router.RouterMode): Promise&lt;void&gt;
3534e41f4b71Sopenharmony_ci
3535e41f4b71Sopenharmony_ciNavigates to a specified page in the application. This API uses a promise to return the result.
3536e41f4b71Sopenharmony_ci
3537e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3538e41f4b71Sopenharmony_ci
3539e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3540e41f4b71Sopenharmony_ci
3541e41f4b71Sopenharmony_ci**Parameters**
3542e41f4b71Sopenharmony_ci
3543e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description        |
3544e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ---------- |
3545e41f4b71Sopenharmony_ci| options | [router.RouterOptions](js-apis-router.md#routeroptions) | Yes   | Page routing parameters. |
3546e41f4b71Sopenharmony_ci| mode    | [router.RouterMode](js-apis-router.md#routermode9) | Yes   | Routing mode. |
3547e41f4b71Sopenharmony_ci
3548e41f4b71Sopenharmony_ci**Return value**
3549e41f4b71Sopenharmony_ci
3550e41f4b71Sopenharmony_ci| Type                 | Description     |
3551e41f4b71Sopenharmony_ci| ------------------- | ------- |
3552e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise used to return the result. |
3553e41f4b71Sopenharmony_ci
3554e41f4b71Sopenharmony_ci**Error codes**
3555e41f4b71Sopenharmony_ci
3556e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
3557e41f4b71Sopenharmony_ci
3558e41f4b71Sopenharmony_ci| ID | Error Message                              |
3559e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
3560e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
3561e41f4b71Sopenharmony_ci| 100001 | Internal error. |
3562e41f4b71Sopenharmony_ci| 100002 | Uri error. The URI of the page to redirect is incorrect or does not exist.           |
3563e41f4b71Sopenharmony_ci| 100003 | Page stack error. Too many pages are pushed.  |
3564e41f4b71Sopenharmony_ci
3565e41f4b71Sopenharmony_ci**Example**
3566e41f4b71Sopenharmony_ci
3567e41f4b71Sopenharmony_ci```ts
3568e41f4b71Sopenharmony_ciimport { Router, router } from '@kit.ArkUI';
3569e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3570e41f4b71Sopenharmony_ci
3571e41f4b71Sopenharmony_cilet routerF:Router = uiContext.getRouter();
3572e41f4b71Sopenharmony_ciclass RouterTmp{
3573e41f4b71Sopenharmony_ci  Standard:router.RouterMode = router.RouterMode.Standard
3574e41f4b71Sopenharmony_ci}
3575e41f4b71Sopenharmony_cilet rtm:RouterTmp = new RouterTmp()
3576e41f4b71Sopenharmony_citry {
3577e41f4b71Sopenharmony_ci  routerF.pushUrl({
3578e41f4b71Sopenharmony_ci    url: 'pages/routerpage2',
3579e41f4b71Sopenharmony_ci    params: {
3580e41f4b71Sopenharmony_ci      data1: 'message',
3581e41f4b71Sopenharmony_ci      data2: {
3582e41f4b71Sopenharmony_ci        data3: [123, 456, 789]
3583e41f4b71Sopenharmony_ci      }
3584e41f4b71Sopenharmony_ci    }
3585e41f4b71Sopenharmony_ci  }, rtm.Standard)
3586e41f4b71Sopenharmony_ci} catch (err) {
3587e41f4b71Sopenharmony_ci  let message = (err as BusinessError).message;
3588e41f4b71Sopenharmony_ci  let code = (err as BusinessError).code;
3589e41f4b71Sopenharmony_ci  console.error(`pushUrl failed, code is ${code}, message is ${message}`);
3590e41f4b71Sopenharmony_ci}
3591e41f4b71Sopenharmony_ci```
3592e41f4b71Sopenharmony_ci
3593e41f4b71Sopenharmony_ci### pushUrl
3594e41f4b71Sopenharmony_ci
3595e41f4b71Sopenharmony_cipushUrl(options: router.RouterOptions, mode: router.RouterMode, callback: AsyncCallback&lt;void&gt;): void
3596e41f4b71Sopenharmony_ci
3597e41f4b71Sopenharmony_ciNavigates to a specified page in the application.
3598e41f4b71Sopenharmony_ci
3599e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3600e41f4b71Sopenharmony_ci
3601e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3602e41f4b71Sopenharmony_ci
3603e41f4b71Sopenharmony_ci**Parameters**
3604e41f4b71Sopenharmony_ci
3605e41f4b71Sopenharmony_ci| Name     | Type                                      | Mandatory  | Description        |
3606e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ---------- |
3607e41f4b71Sopenharmony_ci| options  | [router.RouterOptions](js-apis-router.md#routeroptions) | Yes   | Page routing parameters. |
3608e41f4b71Sopenharmony_ci| mode     | [router.RouterMode](js-apis-router.md#routermode9) | Yes   | Routing mode. |
3609e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt;                | Yes   | Callback used to return the result.   |
3610e41f4b71Sopenharmony_ci
3611e41f4b71Sopenharmony_ci**Error codes**
3612e41f4b71Sopenharmony_ci
3613e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
3614e41f4b71Sopenharmony_ci
3615e41f4b71Sopenharmony_ci| ID | Error Message                              |
3616e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
3617e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
3618e41f4b71Sopenharmony_ci| 100001 | Internal error. |
3619e41f4b71Sopenharmony_ci| 100002 | Uri error. The URI of the page to redirect is incorrect or does not exist.           |
3620e41f4b71Sopenharmony_ci| 100003 | Page stack error. Too many pages are pushed.  |
3621e41f4b71Sopenharmony_ci
3622e41f4b71Sopenharmony_ci**Example**
3623e41f4b71Sopenharmony_ci
3624e41f4b71Sopenharmony_ci```ts
3625e41f4b71Sopenharmony_ciimport { Router, router } from '@kit.ArkUI';
3626e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3627e41f4b71Sopenharmony_ci
3628e41f4b71Sopenharmony_cilet routerF:Router = uiContext.getRouter();
3629e41f4b71Sopenharmony_ciclass RouterTmp{
3630e41f4b71Sopenharmony_ci  Standard:router.RouterMode = router.RouterMode.Standard
3631e41f4b71Sopenharmony_ci}
3632e41f4b71Sopenharmony_cilet rtm:RouterTmp = new RouterTmp()
3633e41f4b71Sopenharmony_cirouterF.pushUrl({
3634e41f4b71Sopenharmony_ci  url: 'pages/routerpage2',
3635e41f4b71Sopenharmony_ci  params: {
3636e41f4b71Sopenharmony_ci    data1: 'message',
3637e41f4b71Sopenharmony_ci    data2: {
3638e41f4b71Sopenharmony_ci      data3: [123, 456, 789]
3639e41f4b71Sopenharmony_ci    }
3640e41f4b71Sopenharmony_ci  }
3641e41f4b71Sopenharmony_ci}, rtm.Standard, (err) => {
3642e41f4b71Sopenharmony_ci  if (err) {
3643e41f4b71Sopenharmony_ci    let message = (err as BusinessError).message;
3644e41f4b71Sopenharmony_ci    let code = (err as BusinessError).code;
3645e41f4b71Sopenharmony_ci    console.error(`pushUrl failed, code is ${code}, message is ${message}`);
3646e41f4b71Sopenharmony_ci    return;
3647e41f4b71Sopenharmony_ci  }
3648e41f4b71Sopenharmony_ci  console.info('pushUrl success');
3649e41f4b71Sopenharmony_ci})
3650e41f4b71Sopenharmony_ci```
3651e41f4b71Sopenharmony_ci
3652e41f4b71Sopenharmony_ci### replaceUrl
3653e41f4b71Sopenharmony_ci
3654e41f4b71Sopenharmony_cireplaceUrl(options: router.RouterOptions): Promise&lt;void&gt;
3655e41f4b71Sopenharmony_ci
3656e41f4b71Sopenharmony_ciReplaces the current page with another one in the application and destroys the current page. This API uses a promise to return the result.
3657e41f4b71Sopenharmony_ci
3658e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3659e41f4b71Sopenharmony_ci
3660e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3661e41f4b71Sopenharmony_ci
3662e41f4b71Sopenharmony_ci**Parameters**
3663e41f4b71Sopenharmony_ci
3664e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description       |
3665e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | --------- |
3666e41f4b71Sopenharmony_ci| options | [router.RouterOptions](js-apis-router.md#routeroptions) | Yes   | Description of the new page. |
3667e41f4b71Sopenharmony_ci
3668e41f4b71Sopenharmony_ci**Return value**
3669e41f4b71Sopenharmony_ci
3670e41f4b71Sopenharmony_ci| Type                 | Description     |
3671e41f4b71Sopenharmony_ci| ------------------- | ------- |
3672e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise used to return the result. |
3673e41f4b71Sopenharmony_ci
3674e41f4b71Sopenharmony_ci**Error codes**
3675e41f4b71Sopenharmony_ci
3676e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
3677e41f4b71Sopenharmony_ci
3678e41f4b71Sopenharmony_ci| ID | Error Message                                    |
3679e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- |
3680e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
3681e41f4b71Sopenharmony_ci| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. |
3682e41f4b71Sopenharmony_ci| 200002 | Uri error. The URI of the page to be used for replacement is incorrect or does not exist.                 |
3683e41f4b71Sopenharmony_ci
3684e41f4b71Sopenharmony_ci**Example**
3685e41f4b71Sopenharmony_ci
3686e41f4b71Sopenharmony_ci```ts
3687e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
3688e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3689e41f4b71Sopenharmony_ci
3690e41f4b71Sopenharmony_cilet router:Router = uiContext.getRouter();
3691e41f4b71Sopenharmony_citry {
3692e41f4b71Sopenharmony_ci  router.replaceUrl({
3693e41f4b71Sopenharmony_ci    url: 'pages/detail',
3694e41f4b71Sopenharmony_ci    params: {
3695e41f4b71Sopenharmony_ci      data1: 'message'
3696e41f4b71Sopenharmony_ci    }
3697e41f4b71Sopenharmony_ci  })
3698e41f4b71Sopenharmony_ci} catch (err) {
3699e41f4b71Sopenharmony_ci  let message = (err as BusinessError).message;
3700e41f4b71Sopenharmony_ci  let code = (err as BusinessError).code;
3701e41f4b71Sopenharmony_ci  console.error(`replaceUrl failed, code is ${code}, message is ${message}`);
3702e41f4b71Sopenharmony_ci}
3703e41f4b71Sopenharmony_ci```
3704e41f4b71Sopenharmony_ci
3705e41f4b71Sopenharmony_ci### replaceUrl
3706e41f4b71Sopenharmony_ci
3707e41f4b71Sopenharmony_cireplaceUrl(options: router.RouterOptions, callback: AsyncCallback&lt;void&gt;): void
3708e41f4b71Sopenharmony_ci
3709e41f4b71Sopenharmony_ciReplaces the current page with another one in the application and destroys the current page.
3710e41f4b71Sopenharmony_ci
3711e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3712e41f4b71Sopenharmony_ci
3713e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3714e41f4b71Sopenharmony_ci
3715e41f4b71Sopenharmony_ci**Parameters**
3716e41f4b71Sopenharmony_ci
3717e41f4b71Sopenharmony_ci| Name     | Type                                      | Mandatory  | Description       |
3718e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | --------- |
3719e41f4b71Sopenharmony_ci| options  | [router.RouterOptions](js-apis-router.md#routeroptions) | Yes   | Description of the new page. |
3720e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt;                | Yes   | Callback used to return the result.  |
3721e41f4b71Sopenharmony_ci
3722e41f4b71Sopenharmony_ci**Error codes**
3723e41f4b71Sopenharmony_ci
3724e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
3725e41f4b71Sopenharmony_ci
3726e41f4b71Sopenharmony_ci| ID | Error Message                                    |
3727e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- |
3728e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
3729e41f4b71Sopenharmony_ci| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. |
3730e41f4b71Sopenharmony_ci| 200002 | if the uri is not exist.                 |
3731e41f4b71Sopenharmony_ci
3732e41f4b71Sopenharmony_ci**Example**
3733e41f4b71Sopenharmony_ci
3734e41f4b71Sopenharmony_ci```ts
3735e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
3736e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3737e41f4b71Sopenharmony_ci
3738e41f4b71Sopenharmony_cilet router:Router = uiContext.getRouter();
3739e41f4b71Sopenharmony_cirouter.replaceUrl({
3740e41f4b71Sopenharmony_ci  url: 'pages/detail',
3741e41f4b71Sopenharmony_ci  params: {
3742e41f4b71Sopenharmony_ci    data1: 'message'
3743e41f4b71Sopenharmony_ci  }
3744e41f4b71Sopenharmony_ci}, (err: Error) => {
3745e41f4b71Sopenharmony_ci  if (err) {
3746e41f4b71Sopenharmony_ci    let message = (err as BusinessError).message;
3747e41f4b71Sopenharmony_ci    let code = (err as BusinessError).code;
3748e41f4b71Sopenharmony_ci    console.error(`replaceUrl failed, code is ${code}, message is ${message}`);
3749e41f4b71Sopenharmony_ci    return;
3750e41f4b71Sopenharmony_ci  }
3751e41f4b71Sopenharmony_ci  console.info('replaceUrl success');
3752e41f4b71Sopenharmony_ci})
3753e41f4b71Sopenharmony_ci```
3754e41f4b71Sopenharmony_ci
3755e41f4b71Sopenharmony_ci### replaceUrl
3756e41f4b71Sopenharmony_ci
3757e41f4b71Sopenharmony_cireplaceUrl(options: router.RouterOptions, mode: router.RouterMode): Promise&lt;void&gt;
3758e41f4b71Sopenharmony_ci
3759e41f4b71Sopenharmony_ciReplaces the current page with another one in the application and destroys the current page. This API uses a promise to return the result.
3760e41f4b71Sopenharmony_ci
3761e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3762e41f4b71Sopenharmony_ci
3763e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3764e41f4b71Sopenharmony_ci
3765e41f4b71Sopenharmony_ci**Parameters**
3766e41f4b71Sopenharmony_ci
3767e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description        |
3768e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ---------- |
3769e41f4b71Sopenharmony_ci| options | [router.RouterOptions](js-apis-router.md#routeroptions) | Yes   | Description of the new page. |
3770e41f4b71Sopenharmony_ci| mode    | [router.RouterMode](js-apis-router.md#routermode9) | Yes   | Routing mode. |
3771e41f4b71Sopenharmony_ci
3772e41f4b71Sopenharmony_ci**Return value**
3773e41f4b71Sopenharmony_ci
3774e41f4b71Sopenharmony_ci| Type                 | Description     |
3775e41f4b71Sopenharmony_ci| ------------------- | ------- |
3776e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise used to return the result. |
3777e41f4b71Sopenharmony_ci
3778e41f4b71Sopenharmony_ci**Error codes**
3779e41f4b71Sopenharmony_ci
3780e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
3781e41f4b71Sopenharmony_ci
3782e41f4b71Sopenharmony_ci| ID | Error Message                                    |
3783e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- |
3784e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
3785e41f4b71Sopenharmony_ci| 100001 | if can not get the delegate, only throw in standard system. |
3786e41f4b71Sopenharmony_ci| 200002 | Uri error. The URI of the page to be used for replacement is incorrect or does not exist.                 |
3787e41f4b71Sopenharmony_ci
3788e41f4b71Sopenharmony_ci**Example**
3789e41f4b71Sopenharmony_ci
3790e41f4b71Sopenharmony_ci```ts
3791e41f4b71Sopenharmony_ciimport { Router, router } from '@kit.ArkUI';
3792e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3793e41f4b71Sopenharmony_ci
3794e41f4b71Sopenharmony_cilet routerF:Router = uiContext.getRouter();
3795e41f4b71Sopenharmony_ciclass RouterTmp{
3796e41f4b71Sopenharmony_ci  Standard:router.RouterMode = router.RouterMode.Standard
3797e41f4b71Sopenharmony_ci}
3798e41f4b71Sopenharmony_cilet rtm:RouterTmp = new RouterTmp()
3799e41f4b71Sopenharmony_citry {
3800e41f4b71Sopenharmony_ci  routerF.replaceUrl({
3801e41f4b71Sopenharmony_ci    url: 'pages/detail',
3802e41f4b71Sopenharmony_ci    params: {
3803e41f4b71Sopenharmony_ci      data1: 'message'
3804e41f4b71Sopenharmony_ci    }
3805e41f4b71Sopenharmony_ci  }, rtm.Standard)
3806e41f4b71Sopenharmony_ci} catch (err) {
3807e41f4b71Sopenharmony_ci  let message = (err as BusinessError).message;
3808e41f4b71Sopenharmony_ci  let code = (err as BusinessError).code;
3809e41f4b71Sopenharmony_ci  console.error(`replaceUrl failed, code is ${code}, message is ${message}`);
3810e41f4b71Sopenharmony_ci}
3811e41f4b71Sopenharmony_ci```
3812e41f4b71Sopenharmony_ci
3813e41f4b71Sopenharmony_ci### replaceUrl
3814e41f4b71Sopenharmony_ci
3815e41f4b71Sopenharmony_cireplaceUrl(options: router.RouterOptions, mode: router.RouterMode, callback: AsyncCallback&lt;void&gt;): void
3816e41f4b71Sopenharmony_ci
3817e41f4b71Sopenharmony_ciReplaces the current page with another one in the application and destroys the current page.
3818e41f4b71Sopenharmony_ci
3819e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3820e41f4b71Sopenharmony_ci
3821e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3822e41f4b71Sopenharmony_ci
3823e41f4b71Sopenharmony_ci**Parameters**
3824e41f4b71Sopenharmony_ci
3825e41f4b71Sopenharmony_ci| Name     | Type                                      | Mandatory  | Description        |
3826e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ---------- |
3827e41f4b71Sopenharmony_ci| options  | [router.RouterOptions](js-apis-router.md#routeroptions) | Yes   | Description of the new page. |
3828e41f4b71Sopenharmony_ci| mode     | [router.RouterMode](js-apis-router.md#routermode9) | Yes   | Routing mode. |
3829e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt;                | Yes   | Callback used to return the result.   |
3830e41f4b71Sopenharmony_ci
3831e41f4b71Sopenharmony_ci**Error codes**
3832e41f4b71Sopenharmony_ci
3833e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
3834e41f4b71Sopenharmony_ci
3835e41f4b71Sopenharmony_ci| ID | Error Message                                    |
3836e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- |
3837e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
3838e41f4b71Sopenharmony_ci| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. |
3839e41f4b71Sopenharmony_ci| 200002 | Uri error. The URI of the page to be used for replacement is incorrect or does not exist.               |
3840e41f4b71Sopenharmony_ci
3841e41f4b71Sopenharmony_ci**Example**
3842e41f4b71Sopenharmony_ci
3843e41f4b71Sopenharmony_ci```ts
3844e41f4b71Sopenharmony_ciimport { Router, router } from '@kit.ArkUI';
3845e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3846e41f4b71Sopenharmony_ci
3847e41f4b71Sopenharmony_cilet routerF:Router = uiContext.getRouter();
3848e41f4b71Sopenharmony_ciclass RouterTmp{
3849e41f4b71Sopenharmony_ci  Standard:router.RouterMode = router.RouterMode.Standard
3850e41f4b71Sopenharmony_ci}
3851e41f4b71Sopenharmony_cilet rtm:RouterTmp = new RouterTmp()
3852e41f4b71Sopenharmony_cirouterF.replaceUrl({
3853e41f4b71Sopenharmony_ci  url: 'pages/detail',
3854e41f4b71Sopenharmony_ci  params: {
3855e41f4b71Sopenharmony_ci    data1: 'message'
3856e41f4b71Sopenharmony_ci  }
3857e41f4b71Sopenharmony_ci}, rtm.Standard, (err: Error) => {
3858e41f4b71Sopenharmony_ci  if (err) {
3859e41f4b71Sopenharmony_ci    let message = (err as BusinessError).message;
3860e41f4b71Sopenharmony_ci    let code = (err as BusinessError).code;
3861e41f4b71Sopenharmony_ci    console.error(`replaceUrl failed, code is ${code}, message is ${message}`);
3862e41f4b71Sopenharmony_ci    return;
3863e41f4b71Sopenharmony_ci  }
3864e41f4b71Sopenharmony_ci  console.info('replaceUrl success');
3865e41f4b71Sopenharmony_ci});
3866e41f4b71Sopenharmony_ci```
3867e41f4b71Sopenharmony_ci
3868e41f4b71Sopenharmony_ci### pushNamedRoute
3869e41f4b71Sopenharmony_ci
3870e41f4b71Sopenharmony_cipushNamedRoute(options: router.NamedRouterOptions): Promise&lt;void&gt;
3871e41f4b71Sopenharmony_ci
3872e41f4b71Sopenharmony_ciNavigates to a page using the named route. This API uses a promise to return the result.
3873e41f4b71Sopenharmony_ci
3874e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3875e41f4b71Sopenharmony_ci
3876e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3877e41f4b71Sopenharmony_ci
3878e41f4b71Sopenharmony_ci**Parameters**
3879e41f4b71Sopenharmony_ci
3880e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description       |
3881e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | --------- |
3882e41f4b71Sopenharmony_ci| options | [router.NamedRouterOptions](js-apis-router.md#namedrouteroptions10) | Yes   | Page routing parameters. |
3883e41f4b71Sopenharmony_ci
3884e41f4b71Sopenharmony_ci**Return value**
3885e41f4b71Sopenharmony_ci
3886e41f4b71Sopenharmony_ci| Type                 | Description     |
3887e41f4b71Sopenharmony_ci| ------------------- | ------- |
3888e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise used to return the result. |
3889e41f4b71Sopenharmony_ci
3890e41f4b71Sopenharmony_ci**Error codes**
3891e41f4b71Sopenharmony_ci
3892e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
3893e41f4b71Sopenharmony_ci
3894e41f4b71Sopenharmony_ci| ID | Error Message                              |
3895e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
3896e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
3897e41f4b71Sopenharmony_ci| 100001 | Internal error. |
3898e41f4b71Sopenharmony_ci| 100003 | Page stack error. Too many pages are pushed.  |
3899e41f4b71Sopenharmony_ci| 100004 | Named route error. The named route does not exist.   |
3900e41f4b71Sopenharmony_ci
3901e41f4b71Sopenharmony_ci**Example**
3902e41f4b71Sopenharmony_ci
3903e41f4b71Sopenharmony_ci```ts
3904e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
3905e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3906e41f4b71Sopenharmony_ci
3907e41f4b71Sopenharmony_cilet router:Router = uiContext.getRouter();
3908e41f4b71Sopenharmony_citry {
3909e41f4b71Sopenharmony_ci  router.pushNamedRoute({
3910e41f4b71Sopenharmony_ci    name: 'myPage',
3911e41f4b71Sopenharmony_ci    params: {
3912e41f4b71Sopenharmony_ci      data1: 'message',
3913e41f4b71Sopenharmony_ci      data2: {
3914e41f4b71Sopenharmony_ci        data3: [123, 456, 789]
3915e41f4b71Sopenharmony_ci      }
3916e41f4b71Sopenharmony_ci    }
3917e41f4b71Sopenharmony_ci  })
3918e41f4b71Sopenharmony_ci} catch (err) {
3919e41f4b71Sopenharmony_ci  let message = (err as BusinessError).message;
3920e41f4b71Sopenharmony_ci  let code = (err as BusinessError).code;
3921e41f4b71Sopenharmony_ci  console.error(`pushNamedRoute failed, code is ${code}, message is ${message}`);
3922e41f4b71Sopenharmony_ci}
3923e41f4b71Sopenharmony_ci```
3924e41f4b71Sopenharmony_ci
3925e41f4b71Sopenharmony_ci### pushNamedRoute
3926e41f4b71Sopenharmony_ci
3927e41f4b71Sopenharmony_cipushNamedRoute(options: router.NamedRouterOptions, callback: AsyncCallback&lt;void&gt;): void
3928e41f4b71Sopenharmony_ci
3929e41f4b71Sopenharmony_ciNavigates to a page using the named route. This API uses a promise to return the result.
3930e41f4b71Sopenharmony_ci
3931e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3932e41f4b71Sopenharmony_ci
3933e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3934e41f4b71Sopenharmony_ci
3935e41f4b71Sopenharmony_ci**Parameters**
3936e41f4b71Sopenharmony_ci
3937e41f4b71Sopenharmony_ci| Name     | Type                                      | Mandatory  | Description       |
3938e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | --------- |
3939e41f4b71Sopenharmony_ci| options  | [router.NamedRouterOptions](js-apis-router.md#namedrouteroptions10) | Yes   | Page routing parameters. |
3940e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt;                | Yes   | Callback used to return the result.  |
3941e41f4b71Sopenharmony_ci
3942e41f4b71Sopenharmony_ci**Error codes**
3943e41f4b71Sopenharmony_ci
3944e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
3945e41f4b71Sopenharmony_ci
3946e41f4b71Sopenharmony_ci| ID | Error Message                              |
3947e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
3948e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
3949e41f4b71Sopenharmony_ci| 100001 | Internal error. |
3950e41f4b71Sopenharmony_ci| 100003 | Page stack error. Too many pages are pushed.  |
3951e41f4b71Sopenharmony_ci| 100004 | Named route error. The named route does not exist.  |
3952e41f4b71Sopenharmony_ci
3953e41f4b71Sopenharmony_ci**Example**
3954e41f4b71Sopenharmony_ci
3955e41f4b71Sopenharmony_ci```ts
3956e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
3957e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
3958e41f4b71Sopenharmony_ci
3959e41f4b71Sopenharmony_cilet router:Router = uiContext.getRouter();
3960e41f4b71Sopenharmony_cirouter.pushNamedRoute({
3961e41f4b71Sopenharmony_ci  name: 'myPage',
3962e41f4b71Sopenharmony_ci  params: {
3963e41f4b71Sopenharmony_ci    data1: 'message',
3964e41f4b71Sopenharmony_ci    data2: {
3965e41f4b71Sopenharmony_ci      data3: [123, 456, 789]
3966e41f4b71Sopenharmony_ci    }
3967e41f4b71Sopenharmony_ci  }
3968e41f4b71Sopenharmony_ci}, (err: Error) => {
3969e41f4b71Sopenharmony_ci  if (err) {
3970e41f4b71Sopenharmony_ci    let message = (err as BusinessError).message;
3971e41f4b71Sopenharmony_ci    let code = (err as BusinessError).code;
3972e41f4b71Sopenharmony_ci    console.error(`pushNamedRoute failed, code is ${code}, message is ${message}`);
3973e41f4b71Sopenharmony_ci    return;
3974e41f4b71Sopenharmony_ci  }
3975e41f4b71Sopenharmony_ci  console.info('pushNamedRoute success');
3976e41f4b71Sopenharmony_ci})
3977e41f4b71Sopenharmony_ci```
3978e41f4b71Sopenharmony_ci### pushNamedRoute
3979e41f4b71Sopenharmony_ci
3980e41f4b71Sopenharmony_cipushNamedRoute(options: router.NamedRouterOptions, mode: router.RouterMode): Promise&lt;void&gt;
3981e41f4b71Sopenharmony_ci
3982e41f4b71Sopenharmony_ciNavigates to a page using the named route. This API uses a promise to return the result.
3983e41f4b71Sopenharmony_ci
3984e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
3985e41f4b71Sopenharmony_ci
3986e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
3987e41f4b71Sopenharmony_ci
3988e41f4b71Sopenharmony_ci**Parameters**
3989e41f4b71Sopenharmony_ci
3990e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description        |
3991e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ---------- |
3992e41f4b71Sopenharmony_ci| options | [router.NamedRouterOptions](js-apis-router.md#namedrouteroptions10) | Yes   | Page routing parameters. |
3993e41f4b71Sopenharmony_ci| mode    | [router.RouterMode](js-apis-router.md#routermode9) | Yes   | Routing mode. |
3994e41f4b71Sopenharmony_ci
3995e41f4b71Sopenharmony_ci**Return value**
3996e41f4b71Sopenharmony_ci
3997e41f4b71Sopenharmony_ci| Type                 | Description     |
3998e41f4b71Sopenharmony_ci| ------------------- | ------- |
3999e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise used to return the result. |
4000e41f4b71Sopenharmony_ci
4001e41f4b71Sopenharmony_ci**Error codes**
4002e41f4b71Sopenharmony_ci
4003e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
4004e41f4b71Sopenharmony_ci
4005e41f4b71Sopenharmony_ci| ID | Error Message                              |
4006e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
4007e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
4008e41f4b71Sopenharmony_ci| 100001 | Internal error. |
4009e41f4b71Sopenharmony_ci| 100003 | Page stack error. Too many pages are pushed.  |
4010e41f4b71Sopenharmony_ci| 100004 | Named route error. The named route does not exist.  |
4011e41f4b71Sopenharmony_ci
4012e41f4b71Sopenharmony_ci**Example**
4013e41f4b71Sopenharmony_ci
4014e41f4b71Sopenharmony_ci```ts
4015e41f4b71Sopenharmony_ciimport { Router, router } from '@kit.ArkUI';
4016e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4017e41f4b71Sopenharmony_ci
4018e41f4b71Sopenharmony_cilet routerF:Router = uiContext.getRouter();
4019e41f4b71Sopenharmony_ciclass RouterTmp{
4020e41f4b71Sopenharmony_ci  Standard:router.RouterMode = router.RouterMode.Standard
4021e41f4b71Sopenharmony_ci}
4022e41f4b71Sopenharmony_cilet rtm:RouterTmp = new RouterTmp()
4023e41f4b71Sopenharmony_citry {
4024e41f4b71Sopenharmony_ci  routerF.pushNamedRoute({
4025e41f4b71Sopenharmony_ci    name: 'myPage',
4026e41f4b71Sopenharmony_ci    params: {
4027e41f4b71Sopenharmony_ci      data1: 'message',
4028e41f4b71Sopenharmony_ci      data2: {
4029e41f4b71Sopenharmony_ci        data3: [123, 456, 789]
4030e41f4b71Sopenharmony_ci      }
4031e41f4b71Sopenharmony_ci    }
4032e41f4b71Sopenharmony_ci  }, rtm.Standard)
4033e41f4b71Sopenharmony_ci} catch (err) {
4034e41f4b71Sopenharmony_ci  let message = (err as BusinessError).message;
4035e41f4b71Sopenharmony_ci  let code = (err as BusinessError).code;
4036e41f4b71Sopenharmony_ci  console.error(`pushNamedRoute failed, code is ${code}, message is ${message}`);
4037e41f4b71Sopenharmony_ci}
4038e41f4b71Sopenharmony_ci```
4039e41f4b71Sopenharmony_ci
4040e41f4b71Sopenharmony_ci### pushNamedRoute
4041e41f4b71Sopenharmony_ci
4042e41f4b71Sopenharmony_cipushNamedRoute(options: router.NamedRouterOptions, mode: router.RouterMode, callback: AsyncCallback&lt;void&gt;): void
4043e41f4b71Sopenharmony_ci
4044e41f4b71Sopenharmony_ciNavigates to a page using the named route. This API uses a promise to return the result.
4045e41f4b71Sopenharmony_ci
4046e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4047e41f4b71Sopenharmony_ci
4048e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4049e41f4b71Sopenharmony_ci
4050e41f4b71Sopenharmony_ci**Parameters**
4051e41f4b71Sopenharmony_ci
4052e41f4b71Sopenharmony_ci| Name     | Type                                      | Mandatory  | Description        |
4053e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ---------- |
4054e41f4b71Sopenharmony_ci| options  | [router.NamedRouterOptions](js-apis-router.md#namedrouteroptions10) | Yes   | Page routing parameters. |
4055e41f4b71Sopenharmony_ci| mode     | [router.RouterMode](js-apis-router.md#routermode9) | Yes   | Routing mode. |
4056e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt;                | Yes   | Callback used to return the result.   |
4057e41f4b71Sopenharmony_ci
4058e41f4b71Sopenharmony_ci**Error codes**
4059e41f4b71Sopenharmony_ci
4060e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
4061e41f4b71Sopenharmony_ci
4062e41f4b71Sopenharmony_ci| ID | Error Message                              |
4063e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
4064e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
4065e41f4b71Sopenharmony_ci| 100001 | Internal error. |
4066e41f4b71Sopenharmony_ci| 100003 | Page stack error. Too many pages are pushed.  |
4067e41f4b71Sopenharmony_ci| 100004 | Named route error. The named route does not exist.   |
4068e41f4b71Sopenharmony_ci
4069e41f4b71Sopenharmony_ci**Example**
4070e41f4b71Sopenharmony_ci
4071e41f4b71Sopenharmony_ci```ts
4072e41f4b71Sopenharmony_ciimport { Router, router } from '@kit.ArkUI';
4073e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4074e41f4b71Sopenharmony_ci
4075e41f4b71Sopenharmony_cilet routerF:Router = uiContext.getRouter();
4076e41f4b71Sopenharmony_ciclass RouterTmp{
4077e41f4b71Sopenharmony_ci  Standard:router.RouterMode = router.RouterMode.Standard
4078e41f4b71Sopenharmony_ci}
4079e41f4b71Sopenharmony_cilet rtm:RouterTmp = new RouterTmp()
4080e41f4b71Sopenharmony_cirouterF.pushNamedRoute({
4081e41f4b71Sopenharmony_ci  name: 'myPage',
4082e41f4b71Sopenharmony_ci  params: {
4083e41f4b71Sopenharmony_ci    data1: 'message',
4084e41f4b71Sopenharmony_ci    data2: {
4085e41f4b71Sopenharmony_ci      data3: [123, 456, 789]
4086e41f4b71Sopenharmony_ci    }
4087e41f4b71Sopenharmony_ci  }
4088e41f4b71Sopenharmony_ci}, rtm.Standard, (err: Error) => {
4089e41f4b71Sopenharmony_ci  if (err) {
4090e41f4b71Sopenharmony_ci    let message = (err as BusinessError).message;
4091e41f4b71Sopenharmony_ci    let code = (err as BusinessError).code;
4092e41f4b71Sopenharmony_ci    console.error(`pushNamedRoute failed, code is ${code}, message is ${message}`);
4093e41f4b71Sopenharmony_ci    return;
4094e41f4b71Sopenharmony_ci  }
4095e41f4b71Sopenharmony_ci  console.info('pushNamedRoute success');
4096e41f4b71Sopenharmony_ci})
4097e41f4b71Sopenharmony_ci```
4098e41f4b71Sopenharmony_ci
4099e41f4b71Sopenharmony_ci### replaceNamedRoute
4100e41f4b71Sopenharmony_ci
4101e41f4b71Sopenharmony_cireplaceNamedRoute(options: router.NamedRouterOptions): Promise&lt;void&gt;
4102e41f4b71Sopenharmony_ci
4103e41f4b71Sopenharmony_ciReplaces the current page with another one using the named route and destroys the current page. This API uses a promise to return the result.
4104e41f4b71Sopenharmony_ci
4105e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4106e41f4b71Sopenharmony_ci
4107e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4108e41f4b71Sopenharmony_ci
4109e41f4b71Sopenharmony_ci**Parameters**
4110e41f4b71Sopenharmony_ci
4111e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description       |
4112e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | --------- |
4113e41f4b71Sopenharmony_ci| options | [router.NamedRouterOptions](js-apis-router.md#namedrouteroptions10) | Yes   | Description of the new page. |
4114e41f4b71Sopenharmony_ci
4115e41f4b71Sopenharmony_ci**Return value**
4116e41f4b71Sopenharmony_ci
4117e41f4b71Sopenharmony_ci| Type                 | Description     |
4118e41f4b71Sopenharmony_ci| ------------------- | ------- |
4119e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise used to return the result. |
4120e41f4b71Sopenharmony_ci
4121e41f4b71Sopenharmony_ci**Error codes**
4122e41f4b71Sopenharmony_ci
4123e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
4124e41f4b71Sopenharmony_ci
4125e41f4b71Sopenharmony_ci| ID | Error Message                                    |
4126e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- |
4127e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
4128e41f4b71Sopenharmony_ci| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. |
4129e41f4b71Sopenharmony_ci| 100004 | Named route error. The named route does not exist.        |
4130e41f4b71Sopenharmony_ci
4131e41f4b71Sopenharmony_ci**Example**
4132e41f4b71Sopenharmony_ci
4133e41f4b71Sopenharmony_ci```ts
4134e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4135e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4136e41f4b71Sopenharmony_ci
4137e41f4b71Sopenharmony_cilet router:Router = uiContext.getRouter();
4138e41f4b71Sopenharmony_citry {
4139e41f4b71Sopenharmony_ci  router.replaceNamedRoute({
4140e41f4b71Sopenharmony_ci    name: 'myPage',
4141e41f4b71Sopenharmony_ci    params: {
4142e41f4b71Sopenharmony_ci      data1: 'message'
4143e41f4b71Sopenharmony_ci    }
4144e41f4b71Sopenharmony_ci  })
4145e41f4b71Sopenharmony_ci} catch (err) {
4146e41f4b71Sopenharmony_ci  let message = (err as BusinessError).message;
4147e41f4b71Sopenharmony_ci  let code = (err as BusinessError).code;
4148e41f4b71Sopenharmony_ci  console.error(`replaceNamedRoute failed, code is ${code}, message is ${message}`);
4149e41f4b71Sopenharmony_ci}
4150e41f4b71Sopenharmony_ci```
4151e41f4b71Sopenharmony_ci
4152e41f4b71Sopenharmony_ci### replaceNamedRoute
4153e41f4b71Sopenharmony_ci
4154e41f4b71Sopenharmony_cireplaceNamedRoute(options: router.NamedRouterOptions, callback: AsyncCallback&lt;void&gt;): void
4155e41f4b71Sopenharmony_ci
4156e41f4b71Sopenharmony_ciReplaces the current page with another one using the named route and destroys the current page. This API uses a promise to return the result.
4157e41f4b71Sopenharmony_ci
4158e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4159e41f4b71Sopenharmony_ci
4160e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4161e41f4b71Sopenharmony_ci
4162e41f4b71Sopenharmony_ci**Parameters**
4163e41f4b71Sopenharmony_ci
4164e41f4b71Sopenharmony_ci| Name     | Type                                      | Mandatory  | Description       |
4165e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | --------- |
4166e41f4b71Sopenharmony_ci| options  | [router.NamedRouterOptions](js-apis-router.md#namedrouteroptions10) | Yes   | Description of the new page. |
4167e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt;                | Yes   | Callback used to return the result.  |
4168e41f4b71Sopenharmony_ci
4169e41f4b71Sopenharmony_ci**Error codes**
4170e41f4b71Sopenharmony_ci
4171e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
4172e41f4b71Sopenharmony_ci
4173e41f4b71Sopenharmony_ci| ID | Error Message                                    |
4174e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- |
4175e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
4176e41f4b71Sopenharmony_ci| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. |
4177e41f4b71Sopenharmony_ci| 100004 | Named route error. The named route does not exist.         |
4178e41f4b71Sopenharmony_ci
4179e41f4b71Sopenharmony_ci**Example**
4180e41f4b71Sopenharmony_ci
4181e41f4b71Sopenharmony_ci```ts
4182e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4183e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4184e41f4b71Sopenharmony_ci
4185e41f4b71Sopenharmony_cilet router:Router = uiContext.getRouter();
4186e41f4b71Sopenharmony_cirouter.replaceNamedRoute({
4187e41f4b71Sopenharmony_ci  name: 'myPage',
4188e41f4b71Sopenharmony_ci  params: {
4189e41f4b71Sopenharmony_ci    data1: 'message'
4190e41f4b71Sopenharmony_ci  }
4191e41f4b71Sopenharmony_ci}, (err: Error) => {
4192e41f4b71Sopenharmony_ci  if (err) {
4193e41f4b71Sopenharmony_ci    let message = (err as BusinessError).message;
4194e41f4b71Sopenharmony_ci    let code = (err as BusinessError).code;
4195e41f4b71Sopenharmony_ci    console.error(`replaceNamedRoute failed, code is ${code}, message is ${message}`);
4196e41f4b71Sopenharmony_ci    return;
4197e41f4b71Sopenharmony_ci  }
4198e41f4b71Sopenharmony_ci  console.info('replaceNamedRoute success');
4199e41f4b71Sopenharmony_ci})
4200e41f4b71Sopenharmony_ci```
4201e41f4b71Sopenharmony_ci
4202e41f4b71Sopenharmony_ci### replaceNamedRoute
4203e41f4b71Sopenharmony_ci
4204e41f4b71Sopenharmony_cireplaceNamedRoute(options: router.NamedRouterOptions, mode: router.RouterMode): Promise&lt;void&gt;
4205e41f4b71Sopenharmony_ci
4206e41f4b71Sopenharmony_ciReplaces the current page with another one using the named route and destroys the current page. This API uses a promise to return the result.
4207e41f4b71Sopenharmony_ci
4208e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4209e41f4b71Sopenharmony_ci
4210e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4211e41f4b71Sopenharmony_ci
4212e41f4b71Sopenharmony_ci**Parameters**
4213e41f4b71Sopenharmony_ci
4214e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description        |
4215e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ---------- |
4216e41f4b71Sopenharmony_ci| options | [router.NamedRouterOptions](js-apis-router.md#namedrouteroptions10) | Yes   | Description of the new page. |
4217e41f4b71Sopenharmony_ci| mode    | [router.RouterMode](js-apis-router.md#routermode9) | Yes   | Routing mode. |
4218e41f4b71Sopenharmony_ci
4219e41f4b71Sopenharmony_ci
4220e41f4b71Sopenharmony_ci**Return value**
4221e41f4b71Sopenharmony_ci
4222e41f4b71Sopenharmony_ci| Type                 | Description     |
4223e41f4b71Sopenharmony_ci| ------------------- | ------- |
4224e41f4b71Sopenharmony_ci| Promise&lt;void&gt; | Promise used to return the result. |
4225e41f4b71Sopenharmony_ci
4226e41f4b71Sopenharmony_ci**Error codes**
4227e41f4b71Sopenharmony_ci
4228e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
4229e41f4b71Sopenharmony_ci
4230e41f4b71Sopenharmony_ci| ID | Error Message                                    |
4231e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- |
4232e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
4233e41f4b71Sopenharmony_ci| 100001 | if can not get the delegate, only throw in standard system. |
4234e41f4b71Sopenharmony_ci| 100004 | Named route error. The named route does not exist.       |
4235e41f4b71Sopenharmony_ci
4236e41f4b71Sopenharmony_ci**Example**
4237e41f4b71Sopenharmony_ci
4238e41f4b71Sopenharmony_ci```ts
4239e41f4b71Sopenharmony_ciimport { Router, router } from '@kit.ArkUI';
4240e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4241e41f4b71Sopenharmony_ci
4242e41f4b71Sopenharmony_cilet routerF:Router = uiContext.getRouter();
4243e41f4b71Sopenharmony_ciclass RouterTmp{
4244e41f4b71Sopenharmony_ci  Standard:router.RouterMode = router.RouterMode.Standard
4245e41f4b71Sopenharmony_ci}
4246e41f4b71Sopenharmony_cilet rtm:RouterTmp = new RouterTmp()
4247e41f4b71Sopenharmony_citry {
4248e41f4b71Sopenharmony_ci  routerF.replaceNamedRoute({
4249e41f4b71Sopenharmony_ci    name: 'myPage',
4250e41f4b71Sopenharmony_ci    params: {
4251e41f4b71Sopenharmony_ci      data1: 'message'
4252e41f4b71Sopenharmony_ci    }
4253e41f4b71Sopenharmony_ci  }, rtm.Standard)
4254e41f4b71Sopenharmony_ci} catch (err) {
4255e41f4b71Sopenharmony_ci  let message = (err as BusinessError).message;
4256e41f4b71Sopenharmony_ci  let code = (err as BusinessError).code;
4257e41f4b71Sopenharmony_ci  console.error(`replaceNamedRoute failed, code is ${code}, message is ${message}`);
4258e41f4b71Sopenharmony_ci}
4259e41f4b71Sopenharmony_ci```
4260e41f4b71Sopenharmony_ci
4261e41f4b71Sopenharmony_ci### replaceNamedRoute
4262e41f4b71Sopenharmony_ci
4263e41f4b71Sopenharmony_cireplaceNamedRoute(options: router.NamedRouterOptions, mode: router.RouterMode, callback: AsyncCallback&lt;void&gt;): void
4264e41f4b71Sopenharmony_ci
4265e41f4b71Sopenharmony_ciReplaces the current page with another one using the named route and destroys the current page. This API uses a promise to return the result.
4266e41f4b71Sopenharmony_ci
4267e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4268e41f4b71Sopenharmony_ci
4269e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4270e41f4b71Sopenharmony_ci
4271e41f4b71Sopenharmony_ci**Parameters**
4272e41f4b71Sopenharmony_ci
4273e41f4b71Sopenharmony_ci| Name     | Type                                      | Mandatory  | Description        |
4274e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ---------- |
4275e41f4b71Sopenharmony_ci| options  | [router.NamedRouterOptions](js-apis-router.md#namedrouteroptions10) | Yes   | Description of the new page. |
4276e41f4b71Sopenharmony_ci| mode     | [router.RouterMode](js-apis-router.md#routermode9) | Yes   | Routing mode. |
4277e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;void&gt;                | Yes   | Callback used to return the result.   |
4278e41f4b71Sopenharmony_ci
4279e41f4b71Sopenharmony_ci**Error codes**
4280e41f4b71Sopenharmony_ci
4281e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
4282e41f4b71Sopenharmony_ci
4283e41f4b71Sopenharmony_ci| ID | Error Message                                    |
4284e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- |
4285e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
4286e41f4b71Sopenharmony_ci| 100001 | The UI execution context is not found. This error code is thrown only in the standard system. |
4287e41f4b71Sopenharmony_ci| 100004 | Named route error. The named route does not exist.        |
4288e41f4b71Sopenharmony_ci
4289e41f4b71Sopenharmony_ci**Example**
4290e41f4b71Sopenharmony_ci
4291e41f4b71Sopenharmony_ci```ts
4292e41f4b71Sopenharmony_ciimport { Router, router } from '@kit.ArkUI';
4293e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4294e41f4b71Sopenharmony_ci
4295e41f4b71Sopenharmony_cilet routerF:Router = uiContext.getRouter();
4296e41f4b71Sopenharmony_ciclass RouterTmp{
4297e41f4b71Sopenharmony_ci  Standard:router.RouterMode = router.RouterMode.Standard
4298e41f4b71Sopenharmony_ci}
4299e41f4b71Sopenharmony_cilet rtm:RouterTmp = new RouterTmp()
4300e41f4b71Sopenharmony_cirouterF.replaceNamedRoute({
4301e41f4b71Sopenharmony_ci  name: 'myPage',
4302e41f4b71Sopenharmony_ci  params: {
4303e41f4b71Sopenharmony_ci    data1: 'message'
4304e41f4b71Sopenharmony_ci  }
4305e41f4b71Sopenharmony_ci}, rtm.Standard, (err: Error) => {
4306e41f4b71Sopenharmony_ci  if (err) {
4307e41f4b71Sopenharmony_ci    let message = (err as BusinessError).message;
4308e41f4b71Sopenharmony_ci    let code = (err as BusinessError).code;
4309e41f4b71Sopenharmony_ci    console.error(`replaceNamedRoute failed, code is ${code}, message is ${message}`);
4310e41f4b71Sopenharmony_ci    return;
4311e41f4b71Sopenharmony_ci  }
4312e41f4b71Sopenharmony_ci  console.info('replaceNamedRoute success');
4313e41f4b71Sopenharmony_ci});
4314e41f4b71Sopenharmony_ci```
4315e41f4b71Sopenharmony_ci
4316e41f4b71Sopenharmony_ci### back
4317e41f4b71Sopenharmony_ci
4318e41f4b71Sopenharmony_ciback(options?: router.RouterOptions ): void
4319e41f4b71Sopenharmony_ci
4320e41f4b71Sopenharmony_ciReturns to the previous page or a specified page.
4321e41f4b71Sopenharmony_ci
4322e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4323e41f4b71Sopenharmony_ci
4324e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4325e41f4b71Sopenharmony_ci
4326e41f4b71Sopenharmony_ci**Parameters**
4327e41f4b71Sopenharmony_ci
4328e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description                                      |
4329e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ---------------------------------------- |
4330e41f4b71Sopenharmony_ci| options | [router.RouterOptions](js-apis-router.md#routeroptions) | No   | Description of the page. The **url** parameter indicates the URL of the page to return to. If the specified page does not exist in the page stack, the application does not respond. If no URL is set, the application returns to the previous page, and the page is not rebuilt. The page in the page stack is not reclaimed. It will be reclaimed after being popped up. |
4331e41f4b71Sopenharmony_ci
4332e41f4b71Sopenharmony_ci**Example**
4333e41f4b71Sopenharmony_ci
4334e41f4b71Sopenharmony_ci```ts
4335e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4336e41f4b71Sopenharmony_cilet router: Router = uiContext.getRouter();
4337e41f4b71Sopenharmony_cirouter.back({url:'pages/detail'});    
4338e41f4b71Sopenharmony_ci```
4339e41f4b71Sopenharmony_ci
4340e41f4b71Sopenharmony_ci### back<sup>12+</sup>
4341e41f4b71Sopenharmony_ci
4342e41f4b71Sopenharmony_ciback(index: number, params?: Object): void;
4343e41f4b71Sopenharmony_ci
4344e41f4b71Sopenharmony_ciReturns to the specified page.
4345e41f4b71Sopenharmony_ci
4346e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4347e41f4b71Sopenharmony_ci
4348e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4349e41f4b71Sopenharmony_ci
4350e41f4b71Sopenharmony_ci**Parameters**
4351e41f4b71Sopenharmony_ci
4352e41f4b71Sopenharmony_ci| Name    | Type                             | Mandatory  | Description        |
4353e41f4b71Sopenharmony_ci| ------- | ------------------------------- | ---- | ---------- |
4354e41f4b71Sopenharmony_ci| index | number | Yes   | Index of the target page to navigate to. |
4355e41f4b71Sopenharmony_ci| params    | Object      | No   | Parameters carried when returning to the page. |
4356e41f4b71Sopenharmony_ci
4357e41f4b71Sopenharmony_ci**Example**
4358e41f4b71Sopenharmony_ci
4359e41f4b71Sopenharmony_ci```ts
4360e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4361e41f4b71Sopenharmony_ci
4362e41f4b71Sopenharmony_cilet router: Router = uiContext.getRouter();
4363e41f4b71Sopenharmony_cirouter.back(1);
4364e41f4b71Sopenharmony_ci```
4365e41f4b71Sopenharmony_ci
4366e41f4b71Sopenharmony_ci```ts
4367e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4368e41f4b71Sopenharmony_ci
4369e41f4b71Sopenharmony_cilet router: Router = uiContext.getRouter();
4370e41f4b71Sopenharmony_cirouter.back(1, {info:'From Home'}); // Returning with parameters.
4371e41f4b71Sopenharmony_ci```
4372e41f4b71Sopenharmony_ci
4373e41f4b71Sopenharmony_ci### clear
4374e41f4b71Sopenharmony_ci
4375e41f4b71Sopenharmony_ciclear(): void
4376e41f4b71Sopenharmony_ci
4377e41f4b71Sopenharmony_ciClears all historical pages in the stack and retains only the current page at the top of the stack.
4378e41f4b71Sopenharmony_ci
4379e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4380e41f4b71Sopenharmony_ci
4381e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4382e41f4b71Sopenharmony_ci
4383e41f4b71Sopenharmony_ci**Example**
4384e41f4b71Sopenharmony_ci
4385e41f4b71Sopenharmony_ci```ts
4386e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4387e41f4b71Sopenharmony_ci
4388e41f4b71Sopenharmony_cilet router: Router = uiContext.getRouter();
4389e41f4b71Sopenharmony_cirouter.clear();    
4390e41f4b71Sopenharmony_ci```
4391e41f4b71Sopenharmony_ci
4392e41f4b71Sopenharmony_ci### getLength
4393e41f4b71Sopenharmony_ci
4394e41f4b71Sopenharmony_cigetLength(): string
4395e41f4b71Sopenharmony_ci
4396e41f4b71Sopenharmony_ciObtains the number of pages in the current stack.
4397e41f4b71Sopenharmony_ci
4398e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4399e41f4b71Sopenharmony_ci
4400e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4401e41f4b71Sopenharmony_ci
4402e41f4b71Sopenharmony_ci**Return value**
4403e41f4b71Sopenharmony_ci
4404e41f4b71Sopenharmony_ci| Type    | Description                |
4405e41f4b71Sopenharmony_ci| ------ | ------------------ |
4406e41f4b71Sopenharmony_ci| string | Number of pages in the stack. The maximum value is **32**. |
4407e41f4b71Sopenharmony_ci
4408e41f4b71Sopenharmony_ci**Example**
4409e41f4b71Sopenharmony_ci
4410e41f4b71Sopenharmony_ci```ts
4411e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4412e41f4b71Sopenharmony_ci
4413e41f4b71Sopenharmony_cilet router: Router = uiContext.getRouter();
4414e41f4b71Sopenharmony_cilet size = router.getLength();        
4415e41f4b71Sopenharmony_ciconsole.info('pages stack size = ' + size);    
4416e41f4b71Sopenharmony_ci```
4417e41f4b71Sopenharmony_ci
4418e41f4b71Sopenharmony_ci### getState
4419e41f4b71Sopenharmony_ci
4420e41f4b71Sopenharmony_cigetState(): router.RouterState
4421e41f4b71Sopenharmony_ci
4422e41f4b71Sopenharmony_ciObtains state information about the current page.
4423e41f4b71Sopenharmony_ci
4424e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4425e41f4b71Sopenharmony_ci
4426e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4427e41f4b71Sopenharmony_ci
4428e41f4b71Sopenharmony_ci**Return value**
4429e41f4b71Sopenharmony_ci
4430e41f4b71Sopenharmony_ci| Type                                      | Description     |
4431e41f4b71Sopenharmony_ci| ---------------------------------------- | ------- |
4432e41f4b71Sopenharmony_ci| router.[RouterState](js-apis-router.md#routerstate) | Page routing state. |
4433e41f4b71Sopenharmony_ci
4434e41f4b71Sopenharmony_ci**Example**
4435e41f4b71Sopenharmony_ci
4436e41f4b71Sopenharmony_ci```ts
4437e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4438e41f4b71Sopenharmony_ci
4439e41f4b71Sopenharmony_cilet router: Router = uiContext.getRouter();
4440e41f4b71Sopenharmony_cilet page = router.getState();
4441e41f4b71Sopenharmony_ciconsole.info('current index = ' + page.index);
4442e41f4b71Sopenharmony_ciconsole.info('current name = ' + page.name);
4443e41f4b71Sopenharmony_ciconsole.info('current path = ' + page.path);
4444e41f4b71Sopenharmony_ci```
4445e41f4b71Sopenharmony_ci
4446e41f4b71Sopenharmony_ci### getStateByIndex<sup>12+</sup>
4447e41f4b71Sopenharmony_ci
4448e41f4b71Sopenharmony_cigetStateByIndex(index: number): router.RouterState | undefined
4449e41f4b71Sopenharmony_ci
4450e41f4b71Sopenharmony_ciObtains the status information about a page by its index.
4451e41f4b71Sopenharmony_ci
4452e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4453e41f4b71Sopenharmony_ci
4454e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4455e41f4b71Sopenharmony_ci
4456e41f4b71Sopenharmony_ci**Parameters**
4457e41f4b71Sopenharmony_ci
4458e41f4b71Sopenharmony_ci| Name    | Type                             | Mandatory  | Description        |
4459e41f4b71Sopenharmony_ci| ------- | ------------------------------- | ---- | ---------- |
4460e41f4b71Sopenharmony_ci| index    | number | Yes  | Index of the target page. |
4461e41f4b71Sopenharmony_ci
4462e41f4b71Sopenharmony_ci**Return value**
4463e41f4b71Sopenharmony_ci
4464e41f4b71Sopenharmony_ci| Type                         | Description     |
4465e41f4b71Sopenharmony_ci| --------------------------- | ------- |
4466e41f4b71Sopenharmony_ci| router.[RouterState](js-apis-router.md#routerstate) \| undefined | State information about the target page. **undefined** if the specified index does not exist. |
4467e41f4b71Sopenharmony_ci
4468e41f4b71Sopenharmony_ci**Example** 
4469e41f4b71Sopenharmony_ci
4470e41f4b71Sopenharmony_ci```ts
4471e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4472e41f4b71Sopenharmony_ci
4473e41f4b71Sopenharmony_cilet router: Router = uiContext.getRouter();
4474e41f4b71Sopenharmony_cilet options: router.RouterState | undefined = router.getStateByIndex(1);
4475e41f4b71Sopenharmony_ciif (options != undefined) {
4476e41f4b71Sopenharmony_ci  console.info('index = ' + options.index);
4477e41f4b71Sopenharmony_ci  console.info('name = ' + options.name);
4478e41f4b71Sopenharmony_ci  console.info('path = ' + options.path);
4479e41f4b71Sopenharmony_ci  console.info('params = ' + options.params);
4480e41f4b71Sopenharmony_ci}
4481e41f4b71Sopenharmony_ci```
4482e41f4b71Sopenharmony_ci### getStateByUrl<sup>12+</sup>
4483e41f4b71Sopenharmony_ci
4484e41f4b71Sopenharmony_cigetStateByUrl(url: string): Array<router.[RouterState](js-apis-router.md#routerstate)>
4485e41f4b71Sopenharmony_ci
4486e41f4b71Sopenharmony_ciObtains the status information about a page by its URL.
4487e41f4b71Sopenharmony_ci
4488e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4489e41f4b71Sopenharmony_ci
4490e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4491e41f4b71Sopenharmony_ci
4492e41f4b71Sopenharmony_ci**Parameters**
4493e41f4b71Sopenharmony_ci
4494e41f4b71Sopenharmony_ci| Name    | Type                             | Mandatory  | Description        |
4495e41f4b71Sopenharmony_ci| ------- | ------------------------------- | ---- | ---------- |
4496e41f4b71Sopenharmony_ci| url    | string | Yes  | URL of the target page. |
4497e41f4b71Sopenharmony_ci
4498e41f4b71Sopenharmony_ci**Return value**
4499e41f4b71Sopenharmony_ci
4500e41f4b71Sopenharmony_ci| Type                         | Description     |
4501e41f4b71Sopenharmony_ci| --------------------------- | ------- |
4502e41f4b71Sopenharmony_ci| Array<router.[RouterState](js-apis-router.md#routerstate)> | Page routing state. |
4503e41f4b71Sopenharmony_ci
4504e41f4b71Sopenharmony_ci**Example** 
4505e41f4b71Sopenharmony_ci
4506e41f4b71Sopenharmony_ci```ts
4507e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4508e41f4b71Sopenharmony_cilet router: Router = uiContext.getRouter();
4509e41f4b71Sopenharmony_cilet options:Array<router.RouterState> = router.getStateByUrl('pages/index');
4510e41f4b71Sopenharmony_cifor (let i: number = 0; i < options.length; i++) {
4511e41f4b71Sopenharmony_ci  console.info('index = ' + options[i].index);
4512e41f4b71Sopenharmony_ci  console.info('name = ' + options[i].name);
4513e41f4b71Sopenharmony_ci  console.info('path = ' + options[i].path);
4514e41f4b71Sopenharmony_ci  console.info('params = ' + options[i].params);
4515e41f4b71Sopenharmony_ci}
4516e41f4b71Sopenharmony_ci```
4517e41f4b71Sopenharmony_ci
4518e41f4b71Sopenharmony_ci### showAlertBeforeBackPage
4519e41f4b71Sopenharmony_ci
4520e41f4b71Sopenharmony_cishowAlertBeforeBackPage(options: router.EnableAlertOptions): void
4521e41f4b71Sopenharmony_ci
4522e41f4b71Sopenharmony_ciEnables the display of a confirm dialog box before returning to the previous page.
4523e41f4b71Sopenharmony_ci
4524e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4525e41f4b71Sopenharmony_ci
4526e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4527e41f4b71Sopenharmony_ci
4528e41f4b71Sopenharmony_ci**Parameters**
4529e41f4b71Sopenharmony_ci
4530e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description       |
4531e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | --------- |
4532e41f4b71Sopenharmony_ci| options | [router.EnableAlertOptions](js-apis-router.md#enablealertoptions) | Yes   | Description of the dialog box. |
4533e41f4b71Sopenharmony_ci
4534e41f4b71Sopenharmony_ci**Error codes**
4535e41f4b71Sopenharmony_ci
4536e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Router Error Codes](errorcode-router.md).
4537e41f4b71Sopenharmony_ci
4538e41f4b71Sopenharmony_ci| ID | Error Message                              |
4539e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
4540e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
4541e41f4b71Sopenharmony_ci| 100001 | Internal error. |
4542e41f4b71Sopenharmony_ci
4543e41f4b71Sopenharmony_ci**Example**
4544e41f4b71Sopenharmony_ci
4545e41f4b71Sopenharmony_ci```ts
4546e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4547e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4548e41f4b71Sopenharmony_ci
4549e41f4b71Sopenharmony_cilet router: Router = uiContext.getRouter();
4550e41f4b71Sopenharmony_citry {
4551e41f4b71Sopenharmony_ci  router.showAlertBeforeBackPage({            
4552e41f4b71Sopenharmony_ci    message: 'Message Info'        
4553e41f4b71Sopenharmony_ci  });
4554e41f4b71Sopenharmony_ci} catch(error) {
4555e41f4b71Sopenharmony_ci  let message = (error as BusinessError).message;
4556e41f4b71Sopenharmony_ci  let code = (error as BusinessError).code;
4557e41f4b71Sopenharmony_ci  console.error(`showAlertBeforeBackPage failed, code is ${code}, message is ${message}`);
4558e41f4b71Sopenharmony_ci}
4559e41f4b71Sopenharmony_ci```
4560e41f4b71Sopenharmony_ci
4561e41f4b71Sopenharmony_ci### hideAlertBeforeBackPage
4562e41f4b71Sopenharmony_ci
4563e41f4b71Sopenharmony_cihideAlertBeforeBackPage(): void
4564e41f4b71Sopenharmony_ci
4565e41f4b71Sopenharmony_ciDisables the display of a confirm dialog box before returning to the previous page.
4566e41f4b71Sopenharmony_ci
4567e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4568e41f4b71Sopenharmony_ci
4569e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4570e41f4b71Sopenharmony_ci
4571e41f4b71Sopenharmony_ci**Example**
4572e41f4b71Sopenharmony_ci
4573e41f4b71Sopenharmony_ci```ts
4574e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4575e41f4b71Sopenharmony_ci
4576e41f4b71Sopenharmony_cilet router: Router = uiContext.getRouter();
4577e41f4b71Sopenharmony_cirouter.hideAlertBeforeBackPage();    
4578e41f4b71Sopenharmony_ci```
4579e41f4b71Sopenharmony_ci
4580e41f4b71Sopenharmony_ci### getParams
4581e41f4b71Sopenharmony_ci
4582e41f4b71Sopenharmony_cigetParams(): Object
4583e41f4b71Sopenharmony_ci
4584e41f4b71Sopenharmony_ciObtains the parameters passed from the page that initiates redirection to the current page.
4585e41f4b71Sopenharmony_ci
4586e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4587e41f4b71Sopenharmony_ci
4588e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4589e41f4b71Sopenharmony_ci
4590e41f4b71Sopenharmony_ci**Return value**
4591e41f4b71Sopenharmony_ci
4592e41f4b71Sopenharmony_ci| Type    | Description               |
4593e41f4b71Sopenharmony_ci| ------ | ----------------- |
4594e41f4b71Sopenharmony_ci| object | Parameters passed from the page that initiates redirection to the current page. |
4595e41f4b71Sopenharmony_ci
4596e41f4b71Sopenharmony_ci**Example**
4597e41f4b71Sopenharmony_ci
4598e41f4b71Sopenharmony_ci```ts
4599e41f4b71Sopenharmony_ciimport { Router } from '@kit.ArkUI';
4600e41f4b71Sopenharmony_ci
4601e41f4b71Sopenharmony_cilet router: Router = uiContext.getRouter();
4602e41f4b71Sopenharmony_cirouter.getParams();
4603e41f4b71Sopenharmony_ci```
4604e41f4b71Sopenharmony_ci
4605e41f4b71Sopenharmony_ci## PromptAction
4606e41f4b71Sopenharmony_ci
4607e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getPromptAction()](#getpromptaction) in **UIContext** to obtain a **PromptAction** instance, and then call the APIs using the obtained instance.
4608e41f4b71Sopenharmony_ci
4609e41f4b71Sopenharmony_ci### showToast
4610e41f4b71Sopenharmony_ci
4611e41f4b71Sopenharmony_cishowToast(options: promptAction.ShowToastOptions): void
4612e41f4b71Sopenharmony_ci
4613e41f4b71Sopenharmony_ciShows a toast in the given settings.
4614e41f4b71Sopenharmony_ci
4615e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4616e41f4b71Sopenharmony_ci
4617e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4618e41f4b71Sopenharmony_ci
4619e41f4b71Sopenharmony_ci**Parameters**
4620e41f4b71Sopenharmony_ci
4621e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description     |
4622e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------- |
4623e41f4b71Sopenharmony_ci| options | [promptAction.ShowToastOptions](js-apis-promptAction.md#showtoastoptions) | Yes   | Toast options. |
4624e41f4b71Sopenharmony_ci
4625e41f4b71Sopenharmony_ci**Error codes**
4626e41f4b71Sopenharmony_ci
4627e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
4628e41f4b71Sopenharmony_ci
4629e41f4b71Sopenharmony_ci| ID | Error Message                              |
4630e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
4631e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
4632e41f4b71Sopenharmony_ci| 100001 | Internal error. |
4633e41f4b71Sopenharmony_ci
4634e41f4b71Sopenharmony_ci**Example**
4635e41f4b71Sopenharmony_ci
4636e41f4b71Sopenharmony_ci```ts
4637e41f4b71Sopenharmony_ciimport { PromptAction } from '@kit.ArkUI';
4638e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4639e41f4b71Sopenharmony_ci
4640e41f4b71Sopenharmony_cilet promptAction: PromptAction = uiContext.getPromptAction();
4641e41f4b71Sopenharmony_citry {
4642e41f4b71Sopenharmony_ci  promptAction.showToast({            
4643e41f4b71Sopenharmony_ci    message: 'Message Info',
4644e41f4b71Sopenharmony_ci    duration: 2000 
4645e41f4b71Sopenharmony_ci  });
4646e41f4b71Sopenharmony_ci} catch (error) {
4647e41f4b71Sopenharmony_ci  let message = (error as BusinessError).message;
4648e41f4b71Sopenharmony_ci  let code = (error as BusinessError).code;
4649e41f4b71Sopenharmony_ci  console.error(`showToast args error code is ${code}, message is ${message}`);
4650e41f4b71Sopenharmony_ci};
4651e41f4b71Sopenharmony_ci```
4652e41f4b71Sopenharmony_ci
4653e41f4b71Sopenharmony_ci### openToast<sup>12+</sup>
4654e41f4b71Sopenharmony_ci
4655e41f4b71Sopenharmony_ciopenToast(options: ShowToastOptions): Promise&lt;number&gt;
4656e41f4b71Sopenharmony_ci
4657e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4658e41f4b71Sopenharmony_ci
4659e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4660e41f4b71Sopenharmony_ci
4661e41f4b71Sopenharmony_ci**Parameters**
4662e41f4b71Sopenharmony_ci
4663e41f4b71Sopenharmony_ci| Name | Type                                                        | Mandatory | Description          |
4664e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ | ---- | -------------- |
4665e41f4b71Sopenharmony_ci| options | [promptAction.ShowToastOptions](js-apis-promptAction.md#showtoastoptions) | Yes  | Toast options. |
4666e41f4b71Sopenharmony_ci
4667e41f4b71Sopenharmony_ci**Return value**
4668e41f4b71Sopenharmony_ci
4669e41f4b71Sopenharmony_ci| Type            | Description                                |
4670e41f4b71Sopenharmony_ci| ---------------- | ------------------------------------ |
4671e41f4b71Sopenharmony_ci| Promise&lt;number&gt; | ID of the toast, which is required in **closeToast**. |
4672e41f4b71Sopenharmony_ci
4673e41f4b71Sopenharmony_ci**Error codes**
4674e41f4b71Sopenharmony_ci
4675e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
4676e41f4b71Sopenharmony_ci
4677e41f4b71Sopenharmony_ci| ID | Error Message                                                    |
4678e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
4679e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. |
4680e41f4b71Sopenharmony_ci| 100001   | Internal error.                                              |
4681e41f4b71Sopenharmony_ci
4682e41f4b71Sopenharmony_ci**Example**
4683e41f4b71Sopenharmony_ci
4684e41f4b71Sopenharmony_ci```ts
4685e41f4b71Sopenharmony_ciimport { PromptAction } from '@kit.ArkUI';
4686e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4687e41f4b71Sopenharmony_ci@Entry
4688e41f4b71Sopenharmony_ci@Component
4689e41f4b71Sopenharmony_cistruct toastExample {
4690e41f4b71Sopenharmony_ci  @State toastId: number = 0;
4691e41f4b71Sopenharmony_ci  promptAction: PromptAction = this.getUIContext().getPromptAction()
4692e41f4b71Sopenharmony_ci  build() {
4693e41f4b71Sopenharmony_ci    Column() {
4694e41f4b71Sopenharmony_ci      Button('Open Toast')
4695e41f4b71Sopenharmony_ci        .height(100)
4696e41f4b71Sopenharmony_ci        .onClick(() => {
4697e41f4b71Sopenharmony_ci          try {
4698e41f4b71Sopenharmony_ci            this.promptAction.openToast({
4699e41f4b71Sopenharmony_ci              message: 'Toast Massage',
4700e41f4b71Sopenharmony_ci              duration: 10000,
4701e41f4b71Sopenharmony_ci            }).then((toastId: number) => {
4702e41f4b71Sopenharmony_ci              this.toastId = toastId;
4703e41f4b71Sopenharmony_ci            });
4704e41f4b71Sopenharmony_ci          } catch (error) {
4705e41f4b71Sopenharmony_ci            let message = (error as BusinessError).message;
4706e41f4b71Sopenharmony_ci            let code = (error as BusinessError).code;
4707e41f4b71Sopenharmony_ci            console.error(`OpenToast error code is ${code}, message is ${message}`);
4708e41f4b71Sopenharmony_ci          };
4709e41f4b71Sopenharmony_ci        })
4710e41f4b71Sopenharmony_ci      Blank().height(50);
4711e41f4b71Sopenharmony_ci      Button('Close Toast')
4712e41f4b71Sopenharmony_ci        .height(100)
4713e41f4b71Sopenharmony_ci        .onClick(() => {
4714e41f4b71Sopenharmony_ci          try {
4715e41f4b71Sopenharmony_ci            this.promptAction.closeToast(this.toastId);
4716e41f4b71Sopenharmony_ci          } catch (error) {
4717e41f4b71Sopenharmony_ci            let message = (error as BusinessError).message;
4718e41f4b71Sopenharmony_ci            let code = (error as BusinessError).code;
4719e41f4b71Sopenharmony_ci            console.error(`CloseToast error code is ${code}, message is ${message}`);
4720e41f4b71Sopenharmony_ci          };
4721e41f4b71Sopenharmony_ci        })
4722e41f4b71Sopenharmony_ci    }.height('100%').width('100%').justifyContent(FlexAlign.Center)
4723e41f4b71Sopenharmony_ci  }
4724e41f4b71Sopenharmony_ci}
4725e41f4b71Sopenharmony_ci```
4726e41f4b71Sopenharmony_ci
4727e41f4b71Sopenharmony_ci### closeToast<sup>12+</sup>
4728e41f4b71Sopenharmony_ci
4729e41f4b71Sopenharmony_cicloseToast(toastId: number): void
4730e41f4b71Sopenharmony_ci
4731e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
4732e41f4b71Sopenharmony_ci
4733e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4734e41f4b71Sopenharmony_ci
4735e41f4b71Sopenharmony_ci**Parameters**
4736e41f4b71Sopenharmony_ci
4737e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                         |
4738e41f4b71Sopenharmony_ci| ------- | ------ | ---- | ----------------------------- |
4739e41f4b71Sopenharmony_ci| toastId | number | Yes  | ID of the toast to close, which is returned by **openToast**. |
4740e41f4b71Sopenharmony_ci
4741e41f4b71Sopenharmony_ci**Error codes**
4742e41f4b71Sopenharmony_ci
4743e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
4744e41f4b71Sopenharmony_ci
4745e41f4b71Sopenharmony_ci| ID | Error Message                                                    |
4746e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
4747e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. |
4748e41f4b71Sopenharmony_ci| 100001   | Internal error.                                              |
4749e41f4b71Sopenharmony_ci
4750e41f4b71Sopenharmony_ci**Example**
4751e41f4b71Sopenharmony_ci
4752e41f4b71Sopenharmony_ciSee the example of [openToaset12](#opentoast12).
4753e41f4b71Sopenharmony_ci
4754e41f4b71Sopenharmony_ci### showDialog
4755e41f4b71Sopenharmony_ci
4756e41f4b71Sopenharmony_cishowDialog(options: promptAction.ShowDialogOptions, callback: AsyncCallback&lt;promptAction.ShowDialogSuccessResponse&gt;): void
4757e41f4b71Sopenharmony_ci
4758e41f4b71Sopenharmony_ciShows a dialog box in the given settings. This API uses an asynchronous callback to return the result.
4759e41f4b71Sopenharmony_ci
4760e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4761e41f4b71Sopenharmony_ci
4762e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4763e41f4b71Sopenharmony_ci
4764e41f4b71Sopenharmony_ci**Parameters**
4765e41f4b71Sopenharmony_ci
4766e41f4b71Sopenharmony_ci| Name     | Type                                      | Mandatory  | Description          |
4767e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ------------ |
4768e41f4b71Sopenharmony_ci| options  | [promptAction.ShowDialogOptions](js-apis-promptAction.md#showdialogoptions) | Yes   | Dialog box options. |
4769e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;[promptAction.ShowDialogSuccessResponse](js-apis-promptAction.md#showdialogsuccessresponse)&gt; | Yes   | Callback used to return the dialog box response result.  |
4770e41f4b71Sopenharmony_ci
4771e41f4b71Sopenharmony_ci**Error codes**
4772e41f4b71Sopenharmony_ci
4773e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
4774e41f4b71Sopenharmony_ci
4775e41f4b71Sopenharmony_ci| ID | Error Message                              |
4776e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
4777e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
4778e41f4b71Sopenharmony_ci| 100001 | Internal error. |
4779e41f4b71Sopenharmony_ci
4780e41f4b71Sopenharmony_ci**Example**
4781e41f4b71Sopenharmony_ci
4782e41f4b71Sopenharmony_ci```ts
4783e41f4b71Sopenharmony_ciimport { PromptAction } from '@kit.ArkUI';
4784e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4785e41f4b71Sopenharmony_ci
4786e41f4b71Sopenharmony_ciclass ButtonsModel {
4787e41f4b71Sopenharmony_ci  text: string = ""
4788e41f4b71Sopenharmony_ci  color: string = ""
4789e41f4b71Sopenharmony_ci}
4790e41f4b71Sopenharmony_cilet promptAction: PromptAction = uiContext.getPromptAction();
4791e41f4b71Sopenharmony_citry {
4792e41f4b71Sopenharmony_ci  promptAction.showDialog({
4793e41f4b71Sopenharmony_ci    title: 'showDialog Title Info',
4794e41f4b71Sopenharmony_ci    message: 'Message Info',
4795e41f4b71Sopenharmony_ci    buttons: [
4796e41f4b71Sopenharmony_ci      {
4797e41f4b71Sopenharmony_ci        text: 'button1',
4798e41f4b71Sopenharmony_ci        color: '#000000'
4799e41f4b71Sopenharmony_ci      } as ButtonsModel,
4800e41f4b71Sopenharmony_ci      {
4801e41f4b71Sopenharmony_ci        text: 'button2',
4802e41f4b71Sopenharmony_ci        color: '#000000'
4803e41f4b71Sopenharmony_ci      } as ButtonsModel
4804e41f4b71Sopenharmony_ci    ]
4805e41f4b71Sopenharmony_ci  }, (err, data) => {
4806e41f4b71Sopenharmony_ci    if (err) {
4807e41f4b71Sopenharmony_ci      console.error('showDialog err: ' + err);
4808e41f4b71Sopenharmony_ci      return;
4809e41f4b71Sopenharmony_ci    }
4810e41f4b71Sopenharmony_ci    console.info('showDialog success callback, click button: ' + data.index);
4811e41f4b71Sopenharmony_ci  });
4812e41f4b71Sopenharmony_ci} catch (error) {
4813e41f4b71Sopenharmony_ci  let message = (error as BusinessError).message;
4814e41f4b71Sopenharmony_ci  let code = (error as BusinessError).code;
4815e41f4b71Sopenharmony_ci  console.error(`showDialog args error code is ${code}, message is ${message}`);
4816e41f4b71Sopenharmony_ci};
4817e41f4b71Sopenharmony_ci```
4818e41f4b71Sopenharmony_ci
4819e41f4b71Sopenharmony_ci### showDialog
4820e41f4b71Sopenharmony_ci
4821e41f4b71Sopenharmony_cishowDialog(options: promptAction.ShowDialogOptions): Promise&lt;promptAction.ShowDialogSuccessResponse&gt;
4822e41f4b71Sopenharmony_ci
4823e41f4b71Sopenharmony_ciShows a dialog box. This API uses a promise to return the result.
4824e41f4b71Sopenharmony_ci
4825e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4826e41f4b71Sopenharmony_ci
4827e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4828e41f4b71Sopenharmony_ci
4829e41f4b71Sopenharmony_ci**Parameters**
4830e41f4b71Sopenharmony_ci
4831e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description    |
4832e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------ |
4833e41f4b71Sopenharmony_ci| options | [promptAction.ShowDialogOptions](js-apis-promptAction.md#showdialogoptions) | Yes   | Dialog box options. |
4834e41f4b71Sopenharmony_ci
4835e41f4b71Sopenharmony_ci**Return value**
4836e41f4b71Sopenharmony_ci
4837e41f4b71Sopenharmony_ci| Type                                      | Description      |
4838e41f4b71Sopenharmony_ci| ---------------------------------------- | -------- |
4839e41f4b71Sopenharmony_ci| Promise&lt;[promptAction.ShowDialogSuccessResponse](js-apis-promptAction.md#showdialogsuccessresponse)&gt; | Promise used to return the dialog box response result. |
4840e41f4b71Sopenharmony_ci
4841e41f4b71Sopenharmony_ci**Error codes**
4842e41f4b71Sopenharmony_ci
4843e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
4844e41f4b71Sopenharmony_ci
4845e41f4b71Sopenharmony_ci| ID | Error Message                              |
4846e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
4847e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
4848e41f4b71Sopenharmony_ci| 100001 | Internal error. |
4849e41f4b71Sopenharmony_ci
4850e41f4b71Sopenharmony_ci**Example**
4851e41f4b71Sopenharmony_ci
4852e41f4b71Sopenharmony_ci```ts
4853e41f4b71Sopenharmony_ciimport { PromptAction } from '@kit.ArkUI';
4854e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4855e41f4b71Sopenharmony_ci
4856e41f4b71Sopenharmony_cilet promptAction: PromptAction = uiContext.getPromptAction();
4857e41f4b71Sopenharmony_citry {
4858e41f4b71Sopenharmony_ci  promptAction.showDialog({
4859e41f4b71Sopenharmony_ci    title: 'Title Info',
4860e41f4b71Sopenharmony_ci    message: 'Message Info',
4861e41f4b71Sopenharmony_ci    buttons: [
4862e41f4b71Sopenharmony_ci      {
4863e41f4b71Sopenharmony_ci        text: 'button1',
4864e41f4b71Sopenharmony_ci        color: '#000000'
4865e41f4b71Sopenharmony_ci      },
4866e41f4b71Sopenharmony_ci      {
4867e41f4b71Sopenharmony_ci        text: 'button2',
4868e41f4b71Sopenharmony_ci        color: '#000000'
4869e41f4b71Sopenharmony_ci      }
4870e41f4b71Sopenharmony_ci    ],
4871e41f4b71Sopenharmony_ci  })
4872e41f4b71Sopenharmony_ci    .then(data => {
4873e41f4b71Sopenharmony_ci      console.info('showDialog success, click button: ' + data.index);
4874e41f4b71Sopenharmony_ci    })
4875e41f4b71Sopenharmony_ci    .catch((err:Error) => {
4876e41f4b71Sopenharmony_ci      console.error('showDialog error: ' + err);
4877e41f4b71Sopenharmony_ci    })
4878e41f4b71Sopenharmony_ci} catch (error) {
4879e41f4b71Sopenharmony_ci  let message = (error as BusinessError).message;
4880e41f4b71Sopenharmony_ci  let code = (error as BusinessError).code;
4881e41f4b71Sopenharmony_ci  console.error(`showDialog args error code is ${code}, message is ${message}`);
4882e41f4b71Sopenharmony_ci};
4883e41f4b71Sopenharmony_ci```
4884e41f4b71Sopenharmony_ci
4885e41f4b71Sopenharmony_ci### showActionMenu<sup>11+</sup>
4886e41f4b71Sopenharmony_ci
4887e41f4b71Sopenharmony_cishowActionMenu(options: promptAction.ActionMenuOptions, callback: AsyncCallback&lt;[promptAction.ActionMenuSuccessResponse](js-apis-promptAction.md#actionmenusuccessresponse)&gt;):void
4888e41f4b71Sopenharmony_ci
4889e41f4b71Sopenharmony_ciShows an action menu in the given settings. This API uses an asynchronous callback to return the result.
4890e41f4b71Sopenharmony_ci
4891e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
4892e41f4b71Sopenharmony_ci
4893e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4894e41f4b71Sopenharmony_ci
4895e41f4b71Sopenharmony_ci**Parameters**
4896e41f4b71Sopenharmony_ci
4897e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description              |
4898e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------ |
4899e41f4b71Sopenharmony_ci| options  | [promptAction.ActionMenuOptions](js-apis-promptAction.md#actionmenuoptions) | Yes  | Action menu options.    |
4900e41f4b71Sopenharmony_ci| callback | AsyncCallback&lt;[promptAction.ActionMenuSuccessResponse](js-apis-promptAction.md#actionmenusuccessresponse)&gt; | Yes  | Callback used to return the action menu response result. |
4901e41f4b71Sopenharmony_ci
4902e41f4b71Sopenharmony_ci**Error codes**
4903e41f4b71Sopenharmony_ci
4904e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
4905e41f4b71Sopenharmony_ci
4906e41f4b71Sopenharmony_ci| ID | Error Message                          |
4907e41f4b71Sopenharmony_ci| -------- | ---------------------------------- |
4908e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
4909e41f4b71Sopenharmony_ci| 100001   | Internal error. |
4910e41f4b71Sopenharmony_ci
4911e41f4b71Sopenharmony_ci**Example**
4912e41f4b71Sopenharmony_ci
4913e41f4b71Sopenharmony_ci```ts
4914e41f4b71Sopenharmony_ciimport { PromptAction, promptAction  } from '@kit.ArkUI';
4915e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4916e41f4b71Sopenharmony_ci
4917e41f4b71Sopenharmony_cilet promptActionF: PromptAction = uiContext.getPromptAction();
4918e41f4b71Sopenharmony_citry {
4919e41f4b71Sopenharmony_ci  promptActionF.showActionMenu({
4920e41f4b71Sopenharmony_ci    title: 'Title Info',
4921e41f4b71Sopenharmony_ci    buttons: [
4922e41f4b71Sopenharmony_ci      {
4923e41f4b71Sopenharmony_ci        text: 'item1',
4924e41f4b71Sopenharmony_ci        color: '#666666'
4925e41f4b71Sopenharmony_ci      },
4926e41f4b71Sopenharmony_ci      {
4927e41f4b71Sopenharmony_ci        text: 'item2',
4928e41f4b71Sopenharmony_ci        color: '#000000'
4929e41f4b71Sopenharmony_ci      }
4930e41f4b71Sopenharmony_ci    ]
4931e41f4b71Sopenharmony_ci  }, (err:BusinessError, data:promptAction.ActionMenuSuccessResponse) => {
4932e41f4b71Sopenharmony_ci    if (err) {
4933e41f4b71Sopenharmony_ci      console.error('showDialog err: ' + err);
4934e41f4b71Sopenharmony_ci      return;
4935e41f4b71Sopenharmony_ci    }
4936e41f4b71Sopenharmony_ci    console.info('showDialog success callback, click button: ' + data.index);
4937e41f4b71Sopenharmony_ci  });
4938e41f4b71Sopenharmony_ci} catch (error) {
4939e41f4b71Sopenharmony_ci  let message = (error as BusinessError).message;
4940e41f4b71Sopenharmony_ci  let code = (error as BusinessError).code;
4941e41f4b71Sopenharmony_ci  console.error(`showActionMenu args error code is ${code}, message is ${message}`);
4942e41f4b71Sopenharmony_ci};
4943e41f4b71Sopenharmony_ci```
4944e41f4b71Sopenharmony_ci
4945e41f4b71Sopenharmony_ci### showActionMenu<sup>(deprecated)</sup>
4946e41f4b71Sopenharmony_ci
4947e41f4b71Sopenharmony_cishowActionMenu(options: promptAction.ActionMenuOptions, callback: [promptAction.ActionMenuSuccessResponse](js-apis-promptAction.md#actionmenusuccessresponse)):void
4948e41f4b71Sopenharmony_ci
4949e41f4b71Sopenharmony_ciShows an action menu in the given settings. This API uses an asynchronous callback to return the result.
4950e41f4b71Sopenharmony_ci
4951e41f4b71Sopenharmony_ciThis API is deprecated since API version 11. You are advised to use [showActionMenu](#showactionmenu11) instead.
4952e41f4b71Sopenharmony_ci
4953e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
4954e41f4b71Sopenharmony_ci
4955e41f4b71Sopenharmony_ci**Parameters**
4956e41f4b71Sopenharmony_ci
4957e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description              |
4958e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------ |
4959e41f4b71Sopenharmony_ci| options  | [promptAction.ActionMenuOptions](js-apis-promptAction.md#actionmenuoptions) | Yes  | Action menu options.    |
4960e41f4b71Sopenharmony_ci| callback | [promptAction.ActionMenuSuccessResponse](js-apis-promptAction.md#actionmenusuccessresponse) | Yes  | Callback used to return the action menu response result. |
4961e41f4b71Sopenharmony_ci
4962e41f4b71Sopenharmony_ci**Error codes**
4963e41f4b71Sopenharmony_ci
4964e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
4965e41f4b71Sopenharmony_ci
4966e41f4b71Sopenharmony_ci| ID | Error Message                              |
4967e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
4968e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
4969e41f4b71Sopenharmony_ci| 100001 | Internal error. |
4970e41f4b71Sopenharmony_ci
4971e41f4b71Sopenharmony_ci**Example**
4972e41f4b71Sopenharmony_ci
4973e41f4b71Sopenharmony_ci```ts
4974e41f4b71Sopenharmony_ciimport { PromptAction,promptAction  } from '@kit.ArkUI';
4975e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
4976e41f4b71Sopenharmony_ci
4977e41f4b71Sopenharmony_cilet promptActionF: PromptAction = uiContext.getPromptAction();
4978e41f4b71Sopenharmony_citry {
4979e41f4b71Sopenharmony_ci  promptActionF.showActionMenu({
4980e41f4b71Sopenharmony_ci    title: 'Title Info',
4981e41f4b71Sopenharmony_ci    buttons: [
4982e41f4b71Sopenharmony_ci      {
4983e41f4b71Sopenharmony_ci        text: 'item1',
4984e41f4b71Sopenharmony_ci        color: '#666666'
4985e41f4b71Sopenharmony_ci      },
4986e41f4b71Sopenharmony_ci      {
4987e41f4b71Sopenharmony_ci        text: 'item2',
4988e41f4b71Sopenharmony_ci        color: '#000000'
4989e41f4b71Sopenharmony_ci      }
4990e41f4b71Sopenharmony_ci    ]
4991e41f4b71Sopenharmony_ci  }, { index:0 });
4992e41f4b71Sopenharmony_ci} catch (error) {
4993e41f4b71Sopenharmony_ci  let message = (error as BusinessError).message;
4994e41f4b71Sopenharmony_ci  let code = (error as BusinessError).code;
4995e41f4b71Sopenharmony_ci  console.error(`showActionMenu args error code is ${code}, message is ${message}`);
4996e41f4b71Sopenharmony_ci};
4997e41f4b71Sopenharmony_ci```
4998e41f4b71Sopenharmony_ci
4999e41f4b71Sopenharmony_ci### showActionMenu
5000e41f4b71Sopenharmony_ci
5001e41f4b71Sopenharmony_cishowActionMenu(options: promptAction.ActionMenuOptions): Promise&lt;promptAction.ActionMenuSuccessResponse&gt;
5002e41f4b71Sopenharmony_ci
5003e41f4b71Sopenharmony_ciShows an action menu. This API uses a promise to return the result.
5004e41f4b71Sopenharmony_ci
5005e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
5006e41f4b71Sopenharmony_ci
5007e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5008e41f4b71Sopenharmony_ci
5009e41f4b71Sopenharmony_ci**Parameters**
5010e41f4b71Sopenharmony_ci
5011e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description     |
5012e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------- |
5013e41f4b71Sopenharmony_ci| options | [promptAction.ActionMenuOptions](js-apis-promptAction.md#actionmenuoptions) | Yes   | Action menu options. |
5014e41f4b71Sopenharmony_ci
5015e41f4b71Sopenharmony_ci**Return value**
5016e41f4b71Sopenharmony_ci
5017e41f4b71Sopenharmony_ci| Type                                      | Description     |
5018e41f4b71Sopenharmony_ci| ---------------------------------------- | ------- |
5019e41f4b71Sopenharmony_ci| Promise&lt;[promptAction.ActionMenuSuccessResponse](js-apis-promptAction.md#actionmenusuccessresponse)&gt; | Promise used to return the action menu response result. |
5020e41f4b71Sopenharmony_ci
5021e41f4b71Sopenharmony_ci**Error codes**
5022e41f4b71Sopenharmony_ci
5023e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
5024e41f4b71Sopenharmony_ci
5025e41f4b71Sopenharmony_ci| ID | Error Message                              |
5026e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
5027e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
5028e41f4b71Sopenharmony_ci| 100001 | Internal error. |
5029e41f4b71Sopenharmony_ci
5030e41f4b71Sopenharmony_ci**Example**
5031e41f4b71Sopenharmony_ci
5032e41f4b71Sopenharmony_ci```ts
5033e41f4b71Sopenharmony_ciimport { PromptAction,promptAction  } from '@kit.ArkUI';
5034e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5035e41f4b71Sopenharmony_ci
5036e41f4b71Sopenharmony_cilet promptAction: PromptAction = uiContext.getPromptAction();
5037e41f4b71Sopenharmony_citry {
5038e41f4b71Sopenharmony_ci  promptAction.showActionMenu({
5039e41f4b71Sopenharmony_ci    title: 'showActionMenu Title Info',
5040e41f4b71Sopenharmony_ci    buttons: [
5041e41f4b71Sopenharmony_ci      {
5042e41f4b71Sopenharmony_ci        text: 'item1',
5043e41f4b71Sopenharmony_ci        color: '#666666'
5044e41f4b71Sopenharmony_ci      },
5045e41f4b71Sopenharmony_ci      {
5046e41f4b71Sopenharmony_ci        text: 'item2',
5047e41f4b71Sopenharmony_ci        color: '#000000'
5048e41f4b71Sopenharmony_ci      },
5049e41f4b71Sopenharmony_ci    ]
5050e41f4b71Sopenharmony_ci  })
5051e41f4b71Sopenharmony_ci    .then(data => {
5052e41f4b71Sopenharmony_ci      console.info('showActionMenu success, click button: ' + data.index);
5053e41f4b71Sopenharmony_ci    })
5054e41f4b71Sopenharmony_ci    .catch((err:Error) => {
5055e41f4b71Sopenharmony_ci      console.error('showActionMenu error: ' + err);
5056e41f4b71Sopenharmony_ci    })
5057e41f4b71Sopenharmony_ci} catch (error) {
5058e41f4b71Sopenharmony_ci  let message = (error as BusinessError).message;
5059e41f4b71Sopenharmony_ci  let code = (error as BusinessError).code;
5060e41f4b71Sopenharmony_ci  console.error(`showActionMenu args error code is ${code}, message is ${message}`);
5061e41f4b71Sopenharmony_ci};
5062e41f4b71Sopenharmony_ci```
5063e41f4b71Sopenharmony_ci
5064e41f4b71Sopenharmony_ci### openCustomDialog<sup>12+</sup>
5065e41f4b71Sopenharmony_ci
5066e41f4b71Sopenharmony_ciopenCustomDialog\<T extends Object>(dialogContent: ComponentContent\<T>, options?: promptAction.BaseDialogOptions): Promise&lt;void&gt;
5067e41f4b71Sopenharmony_ci
5068e41f4b71Sopenharmony_ciOpens a custom dialog box corresponding to **dialogContent**. This API uses a promise to return the result. The dialog box displayed through this API has its content fully following style settings of **dialogContent**. It is displayed in the same way where **customStyle** is set to **true**.
5069e41f4b71Sopenharmony_ci
5070e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5071e41f4b71Sopenharmony_ci
5072e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5073e41f4b71Sopenharmony_ci
5074e41f4b71Sopenharmony_ci**Parameters**
5075e41f4b71Sopenharmony_ci
5076e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description     |
5077e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------- |
5078e41f4b71Sopenharmony_ci| dialogContent | [ComponentContent\<T>](./js-apis-arkui-ComponentContent.md) | Yes | Content of the custom dialog box. |
5079e41f4b71Sopenharmony_ci| options | [promptAction.BaseDialogOptions](js-apis-promptAction.md#basedialogoptions11) | No   |   Dialog box style. |
5080e41f4b71Sopenharmony_ci
5081e41f4b71Sopenharmony_ci**Return value**
5082e41f4b71Sopenharmony_ci
5083e41f4b71Sopenharmony_ci| Type                                      | Description     |
5084e41f4b71Sopenharmony_ci| ---------------------------------------- | ------- |
5085e41f4b71Sopenharmony_ci|   Promise&lt;void&gt;           |    Promise used to return the result. |
5086e41f4b71Sopenharmony_ci
5087e41f4b71Sopenharmony_ci**Error codes**
5088e41f4b71Sopenharmony_ci
5089e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
5090e41f4b71Sopenharmony_ci
5091e41f4b71Sopenharmony_ci| ID | Error Message                              |
5092e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
5093e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
5094e41f4b71Sopenharmony_ci| 103301 | the ComponentContent is incorrect. |
5095e41f4b71Sopenharmony_ci| 103302 | Dialog content already exists.|
5096e41f4b71Sopenharmony_ci
5097e41f4b71Sopenharmony_ci**Example**
5098e41f4b71Sopenharmony_ci
5099e41f4b71Sopenharmony_ci```ts
5100e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5101e41f4b71Sopenharmony_ciimport { ComponentContent } from '@kit.ArkUI';
5102e41f4b71Sopenharmony_ci
5103e41f4b71Sopenharmony_ciclass Params {
5104e41f4b71Sopenharmony_ci  text: string = ""
5105e41f4b71Sopenharmony_ci  constructor(text: string) {
5106e41f4b71Sopenharmony_ci    this.text = text;
5107e41f4b71Sopenharmony_ci  }
5108e41f4b71Sopenharmony_ci}
5109e41f4b71Sopenharmony_ci
5110e41f4b71Sopenharmony_ci@Builder
5111e41f4b71Sopenharmony_cifunction buildText(params: Params) {
5112e41f4b71Sopenharmony_ci  Column() {
5113e41f4b71Sopenharmony_ci    Text(params.text)
5114e41f4b71Sopenharmony_ci      .fontSize(50)
5115e41f4b71Sopenharmony_ci      .fontWeight(FontWeight.Bold)
5116e41f4b71Sopenharmony_ci      .margin({bottom: 36})
5117e41f4b71Sopenharmony_ci  }.backgroundColor('#FFF0F0F0')
5118e41f4b71Sopenharmony_ci}
5119e41f4b71Sopenharmony_ci
5120e41f4b71Sopenharmony_ci@Entry
5121e41f4b71Sopenharmony_ci@Component
5122e41f4b71Sopenharmony_cistruct Index {
5123e41f4b71Sopenharmony_ci  @State message: string = "hello"
5124e41f4b71Sopenharmony_ci
5125e41f4b71Sopenharmony_ci  build() {
5126e41f4b71Sopenharmony_ci    Row() {
5127e41f4b71Sopenharmony_ci      Column() {
5128e41f4b71Sopenharmony_ci        Button("click me")
5129e41f4b71Sopenharmony_ci            .onClick(() => {
5130e41f4b71Sopenharmony_ci                let uiContext = this.getUIContext();
5131e41f4b71Sopenharmony_ci                let promptAction = uiContext.getPromptAction();
5132e41f4b71Sopenharmony_ci                let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message));
5133e41f4b71Sopenharmony_ci                try {
5134e41f4b71Sopenharmony_ci                  promptAction.openCustomDialog(contentNode);
5135e41f4b71Sopenharmony_ci                } catch (error) {
5136e41f4b71Sopenharmony_ci                  let message = (error as BusinessError).message;
5137e41f4b71Sopenharmony_ci                  let code = (error as BusinessError).code;
5138e41f4b71Sopenharmony_ci                  console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);
5139e41f4b71Sopenharmony_ci                };
5140e41f4b71Sopenharmony_ci            })
5141e41f4b71Sopenharmony_ci      }
5142e41f4b71Sopenharmony_ci      .width('100%')
5143e41f4b71Sopenharmony_ci      .height('100%')
5144e41f4b71Sopenharmony_ci    }
5145e41f4b71Sopenharmony_ci    .height('100%')
5146e41f4b71Sopenharmony_ci  }
5147e41f4b71Sopenharmony_ci}
5148e41f4b71Sopenharmony_ci```
5149e41f4b71Sopenharmony_ci
5150e41f4b71Sopenharmony_ci### closeCustomDialog<sup>12+</sup>
5151e41f4b71Sopenharmony_ci
5152e41f4b71Sopenharmony_cicloseCustomDialog\<T extends Object>(dialogContent: ComponentContent\<T>): Promise&lt;void&gt;
5153e41f4b71Sopenharmony_ci
5154e41f4b71Sopenharmony_ciCloses a custom dialog box corresponding to **dialogContent**. This API uses a promise to return the result.
5155e41f4b71Sopenharmony_ci
5156e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5157e41f4b71Sopenharmony_ci
5158e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5159e41f4b71Sopenharmony_ci
5160e41f4b71Sopenharmony_ci**Parameters**
5161e41f4b71Sopenharmony_ci
5162e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description     |
5163e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------- |
5164e41f4b71Sopenharmony_ci| dialogContent | [ComponentContent\<T>](./js-apis-arkui-ComponentContent.md) | Yes | Content of the custom dialog box. |
5165e41f4b71Sopenharmony_ci
5166e41f4b71Sopenharmony_ci**Return value**
5167e41f4b71Sopenharmony_ci
5168e41f4b71Sopenharmony_ci| Type                                      | Description     |
5169e41f4b71Sopenharmony_ci| ---------------------------------------- | ------- |
5170e41f4b71Sopenharmony_ci|   Promise&lt;void&gt;           |    Promise used to return the result. |
5171e41f4b71Sopenharmony_ci
5172e41f4b71Sopenharmony_ci**Error codes**
5173e41f4b71Sopenharmony_ci
5174e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
5175e41f4b71Sopenharmony_ci
5176e41f4b71Sopenharmony_ci| ID | Error Message                              |
5177e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
5178e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
5179e41f4b71Sopenharmony_ci| 103301 | the ComponentContent is incorrect. |
5180e41f4b71Sopenharmony_ci| 103303 | the ComponentContent cannot be found. |
5181e41f4b71Sopenharmony_ci
5182e41f4b71Sopenharmony_ci**Example**
5183e41f4b71Sopenharmony_ci
5184e41f4b71Sopenharmony_ci```ts
5185e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5186e41f4b71Sopenharmony_ciimport { ComponentContent } from '@kit.ArkUI';
5187e41f4b71Sopenharmony_ci
5188e41f4b71Sopenharmony_ciclass Params {
5189e41f4b71Sopenharmony_ci  text: string = ""
5190e41f4b71Sopenharmony_ci  constructor(text: string) {
5191e41f4b71Sopenharmony_ci    this.text = text;
5192e41f4b71Sopenharmony_ci  }
5193e41f4b71Sopenharmony_ci}
5194e41f4b71Sopenharmony_ci
5195e41f4b71Sopenharmony_ci@Builder
5196e41f4b71Sopenharmony_cifunction buildText(params: Params) {
5197e41f4b71Sopenharmony_ci  Column() {
5198e41f4b71Sopenharmony_ci    Text(params.text)
5199e41f4b71Sopenharmony_ci      .fontSize(50)
5200e41f4b71Sopenharmony_ci      .fontWeight(FontWeight.Bold)
5201e41f4b71Sopenharmony_ci      .margin({bottom: 36})
5202e41f4b71Sopenharmony_ci  }.backgroundColor('#FFF0F0F0')
5203e41f4b71Sopenharmony_ci}
5204e41f4b71Sopenharmony_ci
5205e41f4b71Sopenharmony_ci@Entry
5206e41f4b71Sopenharmony_ci@Component
5207e41f4b71Sopenharmony_cistruct Index {
5208e41f4b71Sopenharmony_ci  @State message: string = "hello"
5209e41f4b71Sopenharmony_ci
5210e41f4b71Sopenharmony_ci  build() {
5211e41f4b71Sopenharmony_ci    Row() {
5212e41f4b71Sopenharmony_ci      Column() {
5213e41f4b71Sopenharmony_ci        Button("click me")
5214e41f4b71Sopenharmony_ci            .onClick(() => {
5215e41f4b71Sopenharmony_ci                let uiContext = this.getUIContext();
5216e41f4b71Sopenharmony_ci                let promptAction = uiContext.getPromptAction();
5217e41f4b71Sopenharmony_ci                let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message));
5218e41f4b71Sopenharmony_ci                try {
5219e41f4b71Sopenharmony_ci                  promptAction.openCustomDialog(contentNode);
5220e41f4b71Sopenharmony_ci                } catch (error) {
5221e41f4b71Sopenharmony_ci                  let message = (error as BusinessError).message;
5222e41f4b71Sopenharmony_ci                  let code = (error as BusinessError).code;
5223e41f4b71Sopenharmony_ci                  console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);
5224e41f4b71Sopenharmony_ci                };
5225e41f4b71Sopenharmony_ci
5226e41f4b71Sopenharmony_ci                setTimeout(() => {
5227e41f4b71Sopenharmony_ci                  try {
5228e41f4b71Sopenharmony_ci                    promptAction.closeCustomDialog(contentNode);
5229e41f4b71Sopenharmony_ci                  } catch (error) {
5230e41f4b71Sopenharmony_ci                    let message = (error as BusinessError).message;
5231e41f4b71Sopenharmony_ci                    let code = (error as BusinessError).code;
5232e41f4b71Sopenharmony_ci                    console.error(`closeCustomDialog args error code is ${code}, message is ${message}`);
5233e41f4b71Sopenharmony_ci                  };
5234e41f4b71Sopenharmony_ci                }, 2000);     // The dialog box is closed automatically after 2 seconds.
5235e41f4b71Sopenharmony_ci            })
5236e41f4b71Sopenharmony_ci      }
5237e41f4b71Sopenharmony_ci      .width('100%')
5238e41f4b71Sopenharmony_ci      .height('100%')
5239e41f4b71Sopenharmony_ci    }
5240e41f4b71Sopenharmony_ci    .height('100%')
5241e41f4b71Sopenharmony_ci  }
5242e41f4b71Sopenharmony_ci}
5243e41f4b71Sopenharmony_ci```
5244e41f4b71Sopenharmony_ci
5245e41f4b71Sopenharmony_ci### updateCustomDialog<sup>12+</sup>
5246e41f4b71Sopenharmony_ci
5247e41f4b71Sopenharmony_ciupdateCustomDialog\<T extends Object>(dialogContent: ComponentContent\<T>, options: promptAction.BaseDialogOptions): Promise&lt;void&gt;
5248e41f4b71Sopenharmony_ci
5249e41f4b71Sopenharmony_ciUpdates a custom dialog box corresponding to **dialogContent**. This API uses a promise to return the result.
5250e41f4b71Sopenharmony_ci
5251e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5252e41f4b71Sopenharmony_ci
5253e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5254e41f4b71Sopenharmony_ci
5255e41f4b71Sopenharmony_ci**Parameters**
5256e41f4b71Sopenharmony_ci
5257e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description     |
5258e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------- |
5259e41f4b71Sopenharmony_ci| dialogContent | [ComponentContent\<T>](./js-apis-arkui-ComponentContent.md) | Yes | Content of the custom dialog box. |
5260e41f4b71Sopenharmony_ci| options | [promptAction.BaseDialogOptions](js-apis-promptAction.md#basedialogoptions11) | Yes   |   Dialog box style. Currently, only **alignment**, **offset**, **autoCancel**, and **maskColor** can be updated. |
5261e41f4b71Sopenharmony_ci
5262e41f4b71Sopenharmony_ci**Return value**
5263e41f4b71Sopenharmony_ci
5264e41f4b71Sopenharmony_ci| Type                                      | Description     |
5265e41f4b71Sopenharmony_ci| ---------------------------------------- | ------- |
5266e41f4b71Sopenharmony_ci|   Promise&lt;void&gt;           |    Promise used to return the result. |
5267e41f4b71Sopenharmony_ci
5268e41f4b71Sopenharmony_ci**Error codes**
5269e41f4b71Sopenharmony_ci
5270e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [promptAction Error Codes](errorcode-promptAction.md).
5271e41f4b71Sopenharmony_ci
5272e41f4b71Sopenharmony_ci| ID | Error Message                              |
5273e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
5274e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed.   |
5275e41f4b71Sopenharmony_ci| 103301 | the ComponentContent is incorrect. |
5276e41f4b71Sopenharmony_ci| 103303 | the ComponentContent cannot be found. |
5277e41f4b71Sopenharmony_ci
5278e41f4b71Sopenharmony_ci**Example**
5279e41f4b71Sopenharmony_ci
5280e41f4b71Sopenharmony_ci```ts
5281e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
5282e41f4b71Sopenharmony_ciimport { ComponentContent } from '@kit.ArkUI';
5283e41f4b71Sopenharmony_ci
5284e41f4b71Sopenharmony_ciclass Params {
5285e41f4b71Sopenharmony_ci  text: string = ""
5286e41f4b71Sopenharmony_ci  constructor(text: string) {
5287e41f4b71Sopenharmony_ci    this.text = text;
5288e41f4b71Sopenharmony_ci  }
5289e41f4b71Sopenharmony_ci}
5290e41f4b71Sopenharmony_ci
5291e41f4b71Sopenharmony_ci@Builder
5292e41f4b71Sopenharmony_cifunction buildText(params: Params) {
5293e41f4b71Sopenharmony_ci  Column() {
5294e41f4b71Sopenharmony_ci    Text(params.text)
5295e41f4b71Sopenharmony_ci      .fontSize(50)
5296e41f4b71Sopenharmony_ci      .fontWeight(FontWeight.Bold)
5297e41f4b71Sopenharmony_ci      .margin({bottom: 36})
5298e41f4b71Sopenharmony_ci  }.backgroundColor('#FFF0F0F0')
5299e41f4b71Sopenharmony_ci}
5300e41f4b71Sopenharmony_ci
5301e41f4b71Sopenharmony_ci@Entry
5302e41f4b71Sopenharmony_ci@Component
5303e41f4b71Sopenharmony_cistruct Index {
5304e41f4b71Sopenharmony_ci  @State message: string = "hello"
5305e41f4b71Sopenharmony_ci
5306e41f4b71Sopenharmony_ci  build() {
5307e41f4b71Sopenharmony_ci    Row() {
5308e41f4b71Sopenharmony_ci      Column() {
5309e41f4b71Sopenharmony_ci        Button("click me")
5310e41f4b71Sopenharmony_ci            .onClick(() => {
5311e41f4b71Sopenharmony_ci                let uiContext = this.getUIContext();
5312e41f4b71Sopenharmony_ci                let promptAction = uiContext.getPromptAction();
5313e41f4b71Sopenharmony_ci                let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message));
5314e41f4b71Sopenharmony_ci                try {
5315e41f4b71Sopenharmony_ci                  promptAction.openCustomDialog(contentNode);
5316e41f4b71Sopenharmony_ci                } catch (error) {
5317e41f4b71Sopenharmony_ci                  let message = (error as BusinessError).message;
5318e41f4b71Sopenharmony_ci                  let code = (error as BusinessError).code;
5319e41f4b71Sopenharmony_ci                  console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);
5320e41f4b71Sopenharmony_ci                };
5321e41f4b71Sopenharmony_ci
5322e41f4b71Sopenharmony_ci                setTimeout(() => {
5323e41f4b71Sopenharmony_ci                  try {
5324e41f4b71Sopenharmony_ci                    promptAction.updateCustomDialog(contentNode, { alignment: DialogAlignment.CenterEnd });
5325e41f4b71Sopenharmony_ci                  } catch (error) {
5326e41f4b71Sopenharmony_ci                    let message = (error as BusinessError).message;
5327e41f4b71Sopenharmony_ci                    let code = (error as BusinessError).code;
5328e41f4b71Sopenharmony_ci                    console.error(`updateCustomDialog args error code is ${code}, message is ${message}`);
5329e41f4b71Sopenharmony_ci                  };
5330e41f4b71Sopenharmony_ci                }, 2000);   // The dialog box is relocated automatically after 2 seconds.
5331e41f4b71Sopenharmony_ci            })
5332e41f4b71Sopenharmony_ci      }
5333e41f4b71Sopenharmony_ci      .width('100%')
5334e41f4b71Sopenharmony_ci      .height('100%')
5335e41f4b71Sopenharmony_ci    }
5336e41f4b71Sopenharmony_ci    .height('100%')
5337e41f4b71Sopenharmony_ci  }
5338e41f4b71Sopenharmony_ci}
5339e41f4b71Sopenharmony_ci```
5340e41f4b71Sopenharmony_ci
5341e41f4b71Sopenharmony_ci## DragController<sup>11+</sup>
5342e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getDragController()](js-apis-arkui-UIContext.md#getdragcontroller11) in **UIContext** to obtain a **UIContext** instance, and then call the APIs using the obtained instance.
5343e41f4b71Sopenharmony_ci
5344e41f4b71Sopenharmony_ci### executeDrag<sup>11+</sup>
5345e41f4b71Sopenharmony_ci
5346e41f4b71Sopenharmony_ciexecuteDrag(custom: CustomBuilder | DragItemInfo, dragInfo: dragController.DragInfo, callback: AsyncCallback&lt;dragController.DragEventParam&gt;): void
5347e41f4b71Sopenharmony_ci
5348e41f4b71Sopenharmony_ciExecutes dragging, by passing in the object to be dragged and the dragging information. This API uses a callback to return the drag event result.
5349e41f4b71Sopenharmony_ci
5350e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5351e41f4b71Sopenharmony_ci
5352e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5353e41f4b71Sopenharmony_ci
5354e41f4b71Sopenharmony_ci**Parameters**
5355e41f4b71Sopenharmony_ci
5356e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
5357e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5358e41f4b71Sopenharmony_ci| custom   | [CustomBuilder](arkui-ts/ts-types.md#custombuilder8) \| [DragItemInfo](arkui-ts/ts-universal-events-drag-drop.md#dragiteminfo)  | Yes  | Object to be dragged.<br> **NOTE**<br>The global builder is not supported. If the [\<Image>](arkui-ts/ts-basic-components-image.md) component is used in the builder, enable synchronous loading, that is, set the [syncLoad](arkui-ts/ts-basic-components-image.md#attributes) attribute of the component to **true**. The builder is used only to generate the image displayed during the current dragging. Changes to the builder, if any, apply to the next dragging, but not to the current dragging. |
5359e41f4b71Sopenharmony_ci| dragInfo | [dragController.DragInfo](js-apis-arkui-dragController.md#draginfo) | Yes  | Dragging information.                                                  |
5360e41f4b71Sopenharmony_ci| callback | [AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)&lt;[dragController.DragEventParam](js-apis-arkui-dragController.md#drageventparam12)&gt; | Yes  | Callback used to return the result.<br>- **event**: drag event information that includes only the drag result.<br>- **extraParams**: extra information about the drag event. |
5361e41f4b71Sopenharmony_ci
5362e41f4b71Sopenharmony_ci**Error codes** 
5363e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5364e41f4b71Sopenharmony_ci
5365e41f4b71Sopenharmony_ci| ID | Error Message     |
5366e41f4b71Sopenharmony_ci| -------- | ------------- |
5367e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. |
5368e41f4b71Sopenharmony_ci| 100001   | Internal handling failed. |
5369e41f4b71Sopenharmony_ci
5370e41f4b71Sopenharmony_ci**Example**
5371e41f4b71Sopenharmony_ci
5372e41f4b71Sopenharmony_ci```ts
5373e41f4b71Sopenharmony_ciimport { dragController } from "@kit.ArkUI"
5374e41f4b71Sopenharmony_ciimport { unifiedDataChannel } from '@kit.ArkData';
5375e41f4b71Sopenharmony_ci
5376e41f4b71Sopenharmony_ci@Entry
5377e41f4b71Sopenharmony_ci@Component
5378e41f4b71Sopenharmony_cistruct DragControllerPage {
5379e41f4b71Sopenharmony_ci  @Builder DraggingBuilder() {
5380e41f4b71Sopenharmony_ci    Column() {
5381e41f4b71Sopenharmony_ci      Text("DraggingBuilder")
5382e41f4b71Sopenharmony_ci    }
5383e41f4b71Sopenharmony_ci    .width(100)
5384e41f4b71Sopenharmony_ci    .height(100)
5385e41f4b71Sopenharmony_ci    .backgroundColor(Color.Blue)
5386e41f4b71Sopenharmony_ci  }
5387e41f4b71Sopenharmony_ci
5388e41f4b71Sopenharmony_ci  build() {
5389e41f4b71Sopenharmony_ci    Column() {
5390e41f4b71Sopenharmony_ci      Button('touch to execute drag')
5391e41f4b71Sopenharmony_ci        .onTouch((event?:TouchEvent) => {
5392e41f4b71Sopenharmony_ci          if(event){
5393e41f4b71Sopenharmony_ci            if (event.type == TouchType.Down) {
5394e41f4b71Sopenharmony_ci              let text = new unifiedDataChannel.Text()
5395e41f4b71Sopenharmony_ci              let unifiedData = new unifiedDataChannel.UnifiedData(text)
5396e41f4b71Sopenharmony_ci
5397e41f4b71Sopenharmony_ci              let dragInfo: dragController.DragInfo = {
5398e41f4b71Sopenharmony_ci                pointerId: 0,
5399e41f4b71Sopenharmony_ci                data: unifiedData,
5400e41f4b71Sopenharmony_ci                extraParams: ''
5401e41f4b71Sopenharmony_ci              }
5402e41f4b71Sopenharmony_ci              class tmp{
5403e41f4b71Sopenharmony_ci                event:DragEvent|undefined = undefined
5404e41f4b71Sopenharmony_ci                extraParams:string = ''
5405e41f4b71Sopenharmony_ci              }
5406e41f4b71Sopenharmony_ci              let eve:tmp = new tmp()
5407e41f4b71Sopenharmony_ci              dragController.executeDrag(()=>{this.DraggingBuilder()}, dragInfo, (err, eve) => {
5408e41f4b71Sopenharmony_ci                if(eve.event){
5409e41f4b71Sopenharmony_ci                  if (eve.event.getResult() == DragResult.DRAG_SUCCESSFUL) {
5410e41f4b71Sopenharmony_ci                  // ...
5411e41f4b71Sopenharmony_ci                  } else if (eve.event.getResult() == DragResult.DRAG_FAILED) {
5412e41f4b71Sopenharmony_ci                  // ...
5413e41f4b71Sopenharmony_ci                  }
5414e41f4b71Sopenharmony_ci                }
5415e41f4b71Sopenharmony_ci              })
5416e41f4b71Sopenharmony_ci            }
5417e41f4b71Sopenharmony_ci          }
5418e41f4b71Sopenharmony_ci        })
5419e41f4b71Sopenharmony_ci    }
5420e41f4b71Sopenharmony_ci  }
5421e41f4b71Sopenharmony_ci}
5422e41f4b71Sopenharmony_ci```
5423e41f4b71Sopenharmony_ci
5424e41f4b71Sopenharmony_ci### executeDrag<sup>11+</sup>
5425e41f4b71Sopenharmony_ci
5426e41f4b71Sopenharmony_ciexecuteDrag(custom: CustomBuilder | DragItemInfo, dragInfo: dragController.DragInfo): Promise&lt;dragController.DragEventParam&gt;
5427e41f4b71Sopenharmony_ci
5428e41f4b71Sopenharmony_ciExecutes dragging, by passing in the object to be dragged and the dragging information. This API uses a promise to return the drag event result.
5429e41f4b71Sopenharmony_ci
5430e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5431e41f4b71Sopenharmony_ci
5432e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5433e41f4b71Sopenharmony_ci
5434e41f4b71Sopenharmony_ci**Parameters**
5435e41f4b71Sopenharmony_ci
5436e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                            |
5437e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | -------------------------------- |
5438e41f4b71Sopenharmony_ci| custom   | [CustomBuilder](arkui-ts/ts-types.md#custombuilder8) \| [DragItemInfo](arkui-ts/ts-universal-events-drag-drop.md#dragiteminfo)  | Yes  | Object to be dragged. |
5439e41f4b71Sopenharmony_ci| dragInfo | [dragController.DragInfo](js-apis-arkui-dragController.md#draginfo)                                        | Yes  | Dragging information.                      |
5440e41f4b71Sopenharmony_ci
5441e41f4b71Sopenharmony_ci**Return value**
5442e41f4b71Sopenharmony_ci
5443e41f4b71Sopenharmony_ci| Type                                                        | Description                                                        |
5444e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------------ |
5445e41f4b71Sopenharmony_ci| Promise&lt;[dragController.DragEventParam](js-apis-arkui-dragController.md#drageventparam12)&gt; | Callback used to return the result.<br>- **event**: drag event information that includes only the drag result.<br>- **extraParams**: extra information about the drag event. |
5446e41f4b71Sopenharmony_ci
5447e41f4b71Sopenharmony_ci**Error codes**
5448e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5449e41f4b71Sopenharmony_ci
5450e41f4b71Sopenharmony_ci| ID | Error Message     |
5451e41f4b71Sopenharmony_ci| -------- | ------------- |
5452e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. |
5453e41f4b71Sopenharmony_ci| 100001   | Internal handling failed. |
5454e41f4b71Sopenharmony_ci
5455e41f4b71Sopenharmony_ci**Example**
5456e41f4b71Sopenharmony_ci
5457e41f4b71Sopenharmony_ci```ts
5458e41f4b71Sopenharmony_ciimport { dragController, componentSnapshot } from "@kit.ArkUI"
5459e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
5460e41f4b71Sopenharmony_ciimport { unifiedDataChannel } from '@kit.ArkData';
5461e41f4b71Sopenharmony_ci
5462e41f4b71Sopenharmony_ci@Entry
5463e41f4b71Sopenharmony_ci@Component
5464e41f4b71Sopenharmony_cistruct DragControllerPage {
5465e41f4b71Sopenharmony_ci  @State pixmap: image.PixelMap|null = null
5466e41f4b71Sopenharmony_ci
5467e41f4b71Sopenharmony_ci  @Builder DraggingBuilder() {
5468e41f4b71Sopenharmony_ci    Column() {
5469e41f4b71Sopenharmony_ci      Text("DraggingBuilder")
5470e41f4b71Sopenharmony_ci    }
5471e41f4b71Sopenharmony_ci    .width(100)
5472e41f4b71Sopenharmony_ci    .height(100)
5473e41f4b71Sopenharmony_ci    .backgroundColor(Color.Blue)
5474e41f4b71Sopenharmony_ci  }
5475e41f4b71Sopenharmony_ci
5476e41f4b71Sopenharmony_ci  @Builder PixmapBuilder() {
5477e41f4b71Sopenharmony_ci    Column() {
5478e41f4b71Sopenharmony_ci      Text("PixmapBuilder")
5479e41f4b71Sopenharmony_ci    }
5480e41f4b71Sopenharmony_ci    .width(100)
5481e41f4b71Sopenharmony_ci    .height(100)
5482e41f4b71Sopenharmony_ci    .backgroundColor(Color.Blue)
5483e41f4b71Sopenharmony_ci  }
5484e41f4b71Sopenharmony_ci
5485e41f4b71Sopenharmony_ci  build() {
5486e41f4b71Sopenharmony_ci    Column() {
5487e41f4b71Sopenharmony_ci      Button('touch to execute drag')
5488e41f4b71Sopenharmony_ci        .onTouch((event?:TouchEvent) => {
5489e41f4b71Sopenharmony_ci          if(event){
5490e41f4b71Sopenharmony_ci            if (event.type == TouchType.Down) {
5491e41f4b71Sopenharmony_ci              let text = new unifiedDataChannel.Text()
5492e41f4b71Sopenharmony_ci              let unifiedData = new unifiedDataChannel.UnifiedData(text)
5493e41f4b71Sopenharmony_ci
5494e41f4b71Sopenharmony_ci              let dragInfo: dragController.DragInfo = {
5495e41f4b71Sopenharmony_ci                pointerId: 0,
5496e41f4b71Sopenharmony_ci                data: unifiedData,
5497e41f4b71Sopenharmony_ci                extraParams: ''
5498e41f4b71Sopenharmony_ci              }
5499e41f4b71Sopenharmony_ci              let pb:CustomBuilder = ():void=>{this.PixmapBuilder()}
5500e41f4b71Sopenharmony_ci              componentSnapshot.createFromBuilder(pb).then((pix: image.PixelMap) => {
5501e41f4b71Sopenharmony_ci                this.pixmap = pix;
5502e41f4b71Sopenharmony_ci                let dragItemInfo: DragItemInfo = {
5503e41f4b71Sopenharmony_ci                  pixelMap: this.pixmap,
5504e41f4b71Sopenharmony_ci                  builder: ()=>{this.DraggingBuilder()},
5505e41f4b71Sopenharmony_ci                  extraInfo: "DragItemInfoTest"
5506e41f4b71Sopenharmony_ci                }
5507e41f4b71Sopenharmony_ci
5508e41f4b71Sopenharmony_ci                class tmp{
5509e41f4b71Sopenharmony_ci                  event:DragResult|undefined = undefined
5510e41f4b71Sopenharmony_ci                  extraParams:string = ''
5511e41f4b71Sopenharmony_ci                }
5512e41f4b71Sopenharmony_ci                let eve:tmp = new tmp()
5513e41f4b71Sopenharmony_ci                dragController.executeDrag(dragItemInfo, dragInfo)
5514e41f4b71Sopenharmony_ci                  .then((eve) => {
5515e41f4b71Sopenharmony_ci                    if (eve.event.getResult() == DragResult.DRAG_SUCCESSFUL) {
5516e41f4b71Sopenharmony_ci                      // ...
5517e41f4b71Sopenharmony_ci                    } else if (eve.event.getResult() == DragResult.DRAG_FAILED) {
5518e41f4b71Sopenharmony_ci                      // ...
5519e41f4b71Sopenharmony_ci                    }
5520e41f4b71Sopenharmony_ci                  })
5521e41f4b71Sopenharmony_ci                  .catch((err:Error) => {
5522e41f4b71Sopenharmony_ci                  })
5523e41f4b71Sopenharmony_ci              })
5524e41f4b71Sopenharmony_ci            }
5525e41f4b71Sopenharmony_ci          }
5526e41f4b71Sopenharmony_ci        })
5527e41f4b71Sopenharmony_ci    }
5528e41f4b71Sopenharmony_ci    .width('100%')
5529e41f4b71Sopenharmony_ci    .height('100%')
5530e41f4b71Sopenharmony_ci  }
5531e41f4b71Sopenharmony_ci}
5532e41f4b71Sopenharmony_ci```
5533e41f4b71Sopenharmony_ci
5534e41f4b71Sopenharmony_ci### createDragAction<sup>11+</sup>
5535e41f4b71Sopenharmony_ci
5536e41f4b71Sopenharmony_cicreateDragAction(customArray: Array&lt;CustomBuilder \| DragItemInfo&gt;, dragInfo: dragController.DragInfo): dragController.DragAction
5537e41f4b71Sopenharmony_ci
5538e41f4b71Sopenharmony_ciCreates a **DragAction** object, by explicitly specifying one or more drag previews, drag data, and information about the dragged object. If the drag initiated by a **DragAction** object is not complete, no new **DragAction** object can be created, and calling this API will throw an exception.
5539e41f4b71Sopenharmony_ci
5540e41f4b71Sopenharmony_ci**NOTE**<br>You are advised to control the number of drag previews. If too many previews are passed in, the drag efficiency may be affected.
5541e41f4b71Sopenharmony_ci
5542e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5543e41f4b71Sopenharmony_ci
5544e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5545e41f4b71Sopenharmony_ci
5546e41f4b71Sopenharmony_ci**Parameters**
5547e41f4b71Sopenharmony_ci
5548e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                            |
5549e41f4b71Sopenharmony_ci| --------      | ------------------------------------------------------------ | ---- | -------------------------------- |
5550e41f4b71Sopenharmony_ci| customArray  | Array&lt;[CustomBuilder](arkui-ts/ts-types.md#custombuilder8) \| [DragItemInfo](arkui-ts/ts-universal-events-drag-drop.md#dragiteminfo)&gt;  | Yes  | Object to be dragged. |
5551e41f4b71Sopenharmony_ci| dragInfo | [dragController.DragInfo](js-apis-arkui-dragController.md#draginfo)                                | Yes  | Dragging information.                      |
5552e41f4b71Sopenharmony_ci
5553e41f4b71Sopenharmony_ci**Return value**
5554e41f4b71Sopenharmony_ci
5555e41f4b71Sopenharmony_ci| Type                                                  | Description              |
5556e41f4b71Sopenharmony_ci| ------------------------------------------------------ | ------------------ |
5557e41f4b71Sopenharmony_ci| [dragController.DragAction](js-apis-arkui-dragController.md#dragaction11)| **DragAction** object, which is used to subscribe to drag state change events and start the dragging service. |
5558e41f4b71Sopenharmony_ci
5559e41f4b71Sopenharmony_ci**Error codes**
5560e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
5561e41f4b71Sopenharmony_ci
5562e41f4b71Sopenharmony_ci| ID | Error Message     |
5563e41f4b71Sopenharmony_ci| -------- | ------------- |
5564e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. |
5565e41f4b71Sopenharmony_ci| 100001   | Internal handling failed. |
5566e41f4b71Sopenharmony_ci
5567e41f4b71Sopenharmony_ci**Example**
5568e41f4b71Sopenharmony_ci1. In the **EntryAbility.ets** file, obtain the UI context and save it to LocalStorage.
5569e41f4b71Sopenharmony_ci```ts
5570e41f4b71Sopenharmony_ciimport { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
5571e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
5572e41f4b71Sopenharmony_ciimport { window, UIContext } from '@kit.ArkUI';
5573e41f4b71Sopenharmony_ci
5574e41f4b71Sopenharmony_cilet uiContext: UIContext;
5575e41f4b71Sopenharmony_cilet localStorage: LocalStorage = new LocalStorage('uiContext');
5576e41f4b71Sopenharmony_ci
5577e41f4b71Sopenharmony_ciexport default class EntryAbility extends UIAbility {
5578e41f4b71Sopenharmony_ci  storage: LocalStorage = localStorage;
5579e41f4b71Sopenharmony_ci  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
5580e41f4b71Sopenharmony_ci    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
5581e41f4b71Sopenharmony_ci  }
5582e41f4b71Sopenharmony_ci
5583e41f4b71Sopenharmony_ci  onDestroy(): void {
5584e41f4b71Sopenharmony_ci    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
5585e41f4b71Sopenharmony_ci  }
5586e41f4b71Sopenharmony_ci
5587e41f4b71Sopenharmony_ci  onWindowStageCreate(windowStage: window.WindowStage): void {
5588e41f4b71Sopenharmony_ci    // Main window is created, set main page for this ability
5589e41f4b71Sopenharmony_ci    let storage: LocalStorage = new LocalStorage();
5590e41f4b71Sopenharmony_ci    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
5591e41f4b71Sopenharmony_ci
5592e41f4b71Sopenharmony_ci    windowStage.loadContent('pages/Index', storage, (err, data) => {
5593e41f4b71Sopenharmony_ci      if (err.code) {
5594e41f4b71Sopenharmony_ci        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
5595e41f4b71Sopenharmony_ci        return;
5596e41f4b71Sopenharmony_ci      }
5597e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
5598e41f4b71Sopenharmony_ci      windowStage.getMainWindow((err, data) =>
5599e41f4b71Sopenharmony_ci      {
5600e41f4b71Sopenharmony_ci        if (err.code) {
5601e41f4b71Sopenharmony_ci          console.error('Failed to abtain the main window. Cause:' + err.message);
5602e41f4b71Sopenharmony_ci          return;
5603e41f4b71Sopenharmony_ci        }
5604e41f4b71Sopenharmony_ci        let windowClass: window.Window = data;
5605e41f4b71Sopenharmony_ci        uiContext = windowClass.getUIContext();
5606e41f4b71Sopenharmony_ci        this.storage.setOrCreate<UIContext>('uiContext', uiContext);
5607e41f4b71Sopenharmony_ci        // Obtain a UIContext instance.
5608e41f4b71Sopenharmony_ci      })
5609e41f4b71Sopenharmony_ci    });
5610e41f4b71Sopenharmony_ci  }
5611e41f4b71Sopenharmony_ci
5612e41f4b71Sopenharmony_ci  onWindowStageDestroy(): void {
5613e41f4b71Sopenharmony_ci    // Main window is destroyed, release UI related resources
5614e41f4b71Sopenharmony_ci    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
5615e41f4b71Sopenharmony_ci  }
5616e41f4b71Sopenharmony_ci
5617e41f4b71Sopenharmony_ci  onForeground(): void {
5618e41f4b71Sopenharmony_ci    // Ability has brought to foreground
5619e41f4b71Sopenharmony_ci    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
5620e41f4b71Sopenharmony_ci  }
5621e41f4b71Sopenharmony_ci
5622e41f4b71Sopenharmony_ci  onBackground(): void {
5623e41f4b71Sopenharmony_ci    // Ability has back to background
5624e41f4b71Sopenharmony_ci    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
5625e41f4b71Sopenharmony_ci  }
5626e41f4b71Sopenharmony_ci}
5627e41f4b71Sopenharmony_ci```
5628e41f4b71Sopenharmony_ci2. Call **LocalStorage.getShared()** to obtain the UI context and then use the **DragController** object obtained to perform subsequent operations.
5629e41f4b71Sopenharmony_ci```ts
5630e41f4b71Sopenharmony_ciimport { dragController, componentSnapshot, UIContext, DragController } from "@kit.ArkUI"
5631e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
5632e41f4b71Sopenharmony_ciimport { unifiedDataChannel } from '@kit.ArkData';
5633e41f4b71Sopenharmony_ci
5634e41f4b71Sopenharmony_cilet storages = LocalStorage.getShared();
5635e41f4b71Sopenharmony_ci
5636e41f4b71Sopenharmony_ci@Entry(storages)
5637e41f4b71Sopenharmony_ci@Component
5638e41f4b71Sopenharmony_cistruct DragControllerPage {
5639e41f4b71Sopenharmony_ci  @State pixmap: image.PixelMap|null = null
5640e41f4b71Sopenharmony_ci  private dragAction: dragController.DragAction|null = null;
5641e41f4b71Sopenharmony_ci  customBuilders:Array<CustomBuilder | DragItemInfo> = new Array<CustomBuilder | DragItemInfo>();
5642e41f4b71Sopenharmony_ci  @Builder DraggingBuilder() {
5643e41f4b71Sopenharmony_ci    Column() {
5644e41f4b71Sopenharmony_ci      Text("DraggingBuilder")
5645e41f4b71Sopenharmony_ci    }
5646e41f4b71Sopenharmony_ci    .width(100)
5647e41f4b71Sopenharmony_ci    .height(100)
5648e41f4b71Sopenharmony_ci    .backgroundColor(Color.Blue)
5649e41f4b71Sopenharmony_ci  }
5650e41f4b71Sopenharmony_ci
5651e41f4b71Sopenharmony_ci  build() {
5652e41f4b71Sopenharmony_ci    Column() {
5653e41f4b71Sopenharmony_ci
5654e41f4b71Sopenharmony_ci      Column() {
5655e41f4b71Sopenharmony_ci        Text ("Test")
5656e41f4b71Sopenharmony_ci      }
5657e41f4b71Sopenharmony_ci      .width(100)
5658e41f4b71Sopenharmony_ci      .height(100)
5659e41f4b71Sopenharmony_ci      .backgroundColor(Color.Red)
5660e41f4b71Sopenharmony_ci
5661e41f4b71Sopenharmony_ci      Button('Drag Multiple Objects').onTouch((event?:TouchEvent) => {
5662e41f4b71Sopenharmony_ci        if(event){
5663e41f4b71Sopenharmony_ci          if (event.type == TouchType.Down) {
5664e41f4b71Sopenharmony_ci            console.info("muti drag Down by listener");
5665e41f4b71Sopenharmony_ci            this.customBuilders.push(()=>{this.DraggingBuilder()});
5666e41f4b71Sopenharmony_ci            this.customBuilders.push(()=>{this.DraggingBuilder()});
5667e41f4b71Sopenharmony_ci            this.customBuilders.push(()=>{this.DraggingBuilder()});
5668e41f4b71Sopenharmony_ci            let text = new unifiedDataChannel.Text()
5669e41f4b71Sopenharmony_ci            let unifiedData = new unifiedDataChannel.UnifiedData(text)
5670e41f4b71Sopenharmony_ci            let dragInfo: dragController.DragInfo = {
5671e41f4b71Sopenharmony_ci              pointerId: 0,
5672e41f4b71Sopenharmony_ci              data: unifiedData,
5673e41f4b71Sopenharmony_ci              extraParams: ''
5674e41f4b71Sopenharmony_ci            }
5675e41f4b71Sopenharmony_ci            try{
5676e41f4b71Sopenharmony_ci              let uiContext: UIContext = storages.get<UIContext>('uiContext') as UIContext;
5677e41f4b71Sopenharmony_ci              this.dragAction = uiContext.getDragController().createDragAction(this.customBuilders, dragInfo)
5678e41f4b71Sopenharmony_ci              if(!this.dragAction){
5679e41f4b71Sopenharmony_ci                console.info("listener dragAction is null");
5680e41f4b71Sopenharmony_ci                return
5681e41f4b71Sopenharmony_ci              }
5682e41f4b71Sopenharmony_ci              this.dragAction.on('statusChange', (dragAndDropInfo)=>{
5683e41f4b71Sopenharmony_ci                if (dragAndDropInfo.status == dragController.DragStatus.STARTED) {
5684e41f4b71Sopenharmony_ci                  console.info("drag has start");
5685e41f4b71Sopenharmony_ci                } else if (dragAndDropInfo.status == dragController.DragStatus.ENDED){
5686e41f4b71Sopenharmony_ci                  console.info("drag has end");
5687e41f4b71Sopenharmony_ci                  if (!this.dragAction) {
5688e41f4b71Sopenharmony_ci                    return
5689e41f4b71Sopenharmony_ci                  }
5690e41f4b71Sopenharmony_ci                  this.customBuilders.splice(0, this.customBuilders.length)
5691e41f4b71Sopenharmony_ci                  this.dragAction.off('statusChange')
5692e41f4b71Sopenharmony_ci                }
5693e41f4b71Sopenharmony_ci              })
5694e41f4b71Sopenharmony_ci              this.dragAction.startDrag().then(()=>{}).catch((err:Error)=>{
5695e41f4b71Sopenharmony_ci                console.error("start drag Error:" + err.message);
5696e41f4b71Sopenharmony_ci              })
5697e41f4b71Sopenharmony_ci            } catch(err) {
5698e41f4b71Sopenharmony_ci              console.error("create dragAction Error:" + err.message);
5699e41f4b71Sopenharmony_ci            }
5700e41f4b71Sopenharmony_ci          }
5701e41f4b71Sopenharmony_ci        }
5702e41f4b71Sopenharmony_ci      }).margin({top:20})
5703e41f4b71Sopenharmony_ci    }
5704e41f4b71Sopenharmony_ci  }
5705e41f4b71Sopenharmony_ci}
5706e41f4b71Sopenharmony_ci```
5707e41f4b71Sopenharmony_ci
5708e41f4b71Sopenharmony_ci### setDragEventStrictReportingEnabled<sup>12+</sup>
5709e41f4b71Sopenharmony_ci
5710e41f4b71Sopenharmony_cisetDragEventStrictReportingEnabled(enable: boolean): void
5711e41f4b71Sopenharmony_ci
5712e41f4b71Sopenharmony_ciSets whether the **onDragLeave** callback of the parent component is triggered when an item is dragged from the parent to the child component.
5713e41f4b71Sopenharmony_ci
5714e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5715e41f4b71Sopenharmony_ci
5716e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5717e41f4b71Sopenharmony_ci
5718e41f4b71Sopenharmony_ci**Parameters**
5719e41f4b71Sopenharmony_ci
5720e41f4b71Sopenharmony_ci| Name | Type   | Mandatory | Description                                                        |
5721e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------------------------------ |
5722e41f4b71Sopenharmony_ci| enable | boolean | Yes  | Whether the **onDragLeave** callback of the parent component is triggered when an item is dragged from the parent to the child component. |
5723e41f4b71Sopenharmony_ci
5724e41f4b71Sopenharmony_ci**Example**
5725e41f4b71Sopenharmony_ci
5726e41f4b71Sopenharmony_ci```ts
5727e41f4b71Sopenharmony_ciimport { UIAbility } from '@kit.AbilityKit';
5728e41f4b71Sopenharmony_ciimport { window, UIContext } from '@kit.ArkUI';
5729e41f4b71Sopenharmony_ci
5730e41f4b71Sopenharmony_ci export default class EntryAbility extends UIAbility {
5731e41f4b71Sopenharmony_ci   onWindowStageCreate(windowStage: window.WindowStage): void {
5732e41f4b71Sopenharmony_ci       windowStage.loadContent('pages/Index', (err, data) => {
5733e41f4b71Sopenharmony_ci         if (err.code) {
5734e41f4b71Sopenharmony_ci         return;
5735e41f4b71Sopenharmony_ci       }
5736e41f4b71Sopenharmony_ci       windowStage.getMainWindow((err, data) => {
5737e41f4b71Sopenharmony_ci         if (err.code) {
5738e41f4b71Sopenharmony_ci           return;
5739e41f4b71Sopenharmony_ci         }
5740e41f4b71Sopenharmony_ci         let windowClass: window.Window = data;
5741e41f4b71Sopenharmony_ci         let uiContext: UIContext = windowClass.getUIContext();
5742e41f4b71Sopenharmony_ci         uiContext.getDragController().setDragEventStrictReportingEnabled(true);
5743e41f4b71Sopenharmony_ci     });
5744e41f4b71Sopenharmony_ci   });
5745e41f4b71Sopenharmony_ci }
5746e41f4b71Sopenharmony_ci}
5747e41f4b71Sopenharmony_ci```
5748e41f4b71Sopenharmony_ci
5749e41f4b71Sopenharmony_ci## OverlayManager<sup>12+</sup>
5750e41f4b71Sopenharmony_ci
5751e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getOverlayManager()](#getoverlaymanager12) in **UIContext** to obtain an **OverlayManager** instance, and then call the APIs using the obtained instance.
5752e41f4b71Sopenharmony_ci> **NOTE**
5753e41f4b71Sopenharmony_ci>
5754e41f4b71Sopenharmony_ci> Nodes on the **OverlayManager** are above the **Page** level but below elements such as **Dialog**, **Popup**, **Menu**, **BindSheet**, **BindContentCover**, and **Toast**.
5755e41f4b71Sopenharmony_ci>
5756e41f4b71Sopenharmony_ci> The drawing method inside and outside the safe area of nodes on the **OverlayManager** is consistent with that of the **Page**, and the keyboard avoidance method is also the same as that of the **Page**.
5757e41f4b71Sopenharmony_ci>
5758e41f4b71Sopenharmony_ci> For properties related to the **OverlayManager**, you are advised to use AppStorage for global storage across the application to prevent changes in property values when switching pages, which could lead to service errors.
5759e41f4b71Sopenharmony_ci
5760e41f4b71Sopenharmony_ci### addComponentContent<sup>12+</sup>
5761e41f4b71Sopenharmony_ci
5762e41f4b71Sopenharmony_ciaddComponentContent(content: ComponentContent, index?: number): void
5763e41f4b71Sopenharmony_ci
5764e41f4b71Sopenharmony_ciAdds a specified **ComponentContent** node to the **OverlayManager**.
5765e41f4b71Sopenharmony_ci
5766e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5767e41f4b71Sopenharmony_ci
5768e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5769e41f4b71Sopenharmony_ci
5770e41f4b71Sopenharmony_ci**Parameters**
5771e41f4b71Sopenharmony_ci
5772e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description         |
5773e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ----------- |
5774e41f4b71Sopenharmony_ci| content | [ComponentContent](js-apis-arkui-ComponentContent.md) | Yes   | Content to add to the new node on the **OverlayManager**.<br>**NOTE**<br> By default, new nodes are centered page and stacked according to their stacking level.|
5775e41f4b71Sopenharmony_ci| index | number | No   | Stacking level of the new node on the **OverlayManager**.<br>**NOTE**<br> If the value is greater than or equal to 0, a larger value indicates a higher stacking level; for those that have the same index, the one that is added at a later time has a higher stacking level.<br> If the value is less than 0 or is **null** or **undefined**, the **ComponentContent** node is added at the highest level by default.<br>If the same **ComponentContent** node is added multiple times, only the last added one is retained.<br>
5776e41f4b71Sopenharmony_ci
5777e41f4b71Sopenharmony_ci**Example**
5778e41f4b71Sopenharmony_ci
5779e41f4b71Sopenharmony_ci```ts
5780e41f4b71Sopenharmony_ciimport { ComponentContent, OverlayManager, router } from '@kit.ArkUI';
5781e41f4b71Sopenharmony_ci
5782e41f4b71Sopenharmony_ciclass Params {
5783e41f4b71Sopenharmony_ci  text: string = ""
5784e41f4b71Sopenharmony_ci  offset: Position
5785e41f4b71Sopenharmony_ci  constructor(text: string, offset: Position) {
5786e41f4b71Sopenharmony_ci    this.text = text
5787e41f4b71Sopenharmony_ci    this.offset = offset
5788e41f4b71Sopenharmony_ci  }
5789e41f4b71Sopenharmony_ci}
5790e41f4b71Sopenharmony_ci@Builder
5791e41f4b71Sopenharmony_cifunction builderText(params: Params) {
5792e41f4b71Sopenharmony_ci  Column() {
5793e41f4b71Sopenharmony_ci    Text(params.text)
5794e41f4b71Sopenharmony_ci      .fontSize(30)
5795e41f4b71Sopenharmony_ci      .fontWeight(FontWeight.Bold)
5796e41f4b71Sopenharmony_ci  }.offset(params.offset)
5797e41f4b71Sopenharmony_ci}
5798e41f4b71Sopenharmony_ci
5799e41f4b71Sopenharmony_ci@Entry
5800e41f4b71Sopenharmony_ci@Component
5801e41f4b71Sopenharmony_cistruct OverlayExample {
5802e41f4b71Sopenharmony_ci  @State message: string = 'ComponentContent';
5803e41f4b71Sopenharmony_ci  private uiContext: UIContext = this.getUIContext()
5804e41f4b71Sopenharmony_ci  private overlayNode: OverlayManager = this.uiContext.getOverlayManager()
5805e41f4b71Sopenharmony_ci  @StorageLink('contentArray') contentArray: ComponentContent<Params>[] = []
5806e41f4b71Sopenharmony_ci  @StorageLink('componentContentIndex') componentContentIndex: number = 0
5807e41f4b71Sopenharmony_ci  @StorageLink('arrayIndex') arrayIndex: number = 0
5808e41f4b71Sopenharmony_ci  @StorageLink("componentOffset") componentOffset: Position = {x: 0, y: 80}
5809e41f4b71Sopenharmony_ci
5810e41f4b71Sopenharmony_ci  build() {
5811e41f4b71Sopenharmony_ci    Column() {
5812e41f4b71Sopenharmony_ci      Button("++componentContentIndex: " + this.componentContentIndex).onClick(()=>{
5813e41f4b71Sopenharmony_ci        ++this.componentContentIndex
5814e41f4b71Sopenharmony_ci      })
5815e41f4b71Sopenharmony_ci      Button("--componentContentIndex: " + this.componentContentIndex).onClick(()=>{
5816e41f4b71Sopenharmony_ci        --this.componentContentIndex
5817e41f4b71Sopenharmony_ci      })
5818e41f4b71Sopenharmony_ci      Button("Add ComponentContent" + this.contentArray.length).onClick(()=>{
5819e41f4b71Sopenharmony_ci        let componentContent = new ComponentContent(
5820e41f4b71Sopenharmony_ci          this.uiContext, wrapBuilder<[Params]>(builderText),
5821e41f4b71Sopenharmony_ci          new Params(this.message + (this.contentArray.length), this.componentOffset)
5822e41f4b71Sopenharmony_ci        )
5823e41f4b71Sopenharmony_ci        this.contentArray.push(componentContent)
5824e41f4b71Sopenharmony_ci        this.overlayNode.addComponentContent(componentContent, this.componentContentIndex)
5825e41f4b71Sopenharmony_ci      })
5826e41f4b71Sopenharmony_ci      Button("++arrayIndex: " + this.arrayIndex).onClick(()=>{
5827e41f4b71Sopenharmony_ci        ++this.arrayIndex
5828e41f4b71Sopenharmony_ci      })
5829e41f4b71Sopenharmony_ci      Button("--arrayIndex: " + this.arrayIndex).onClick(()=>{
5830e41f4b71Sopenharmony_ci        --this.arrayIndex
5831e41f4b71Sopenharmony_ci      })
5832e41f4b71Sopenharmony_ci      Button ("Delete ComponentContent" + this.arrayIndex).onClick () = >{
5833e41f4b71Sopenharmony_ci        if (this.arrayIndex >= 0 && this.arrayIndex < this.contentArray.length) {
5834e41f4b71Sopenharmony_ci          let componentContent = this.contentArray.splice(this.arrayIndex, 1)
5835e41f4b71Sopenharmony_ci          this.overlayNode.removeComponentContent(componentContent.pop())
5836e41f4b71Sopenharmony_ci        } else {
5837e41f4b71Sopenharmony_ci          console.info("Invalid arrayIndex.")
5838e41f4b71Sopenharmony_ci        }
5839e41f4b71Sopenharmony_ci      })
5840e41f4b71Sopenharmony_ci      Button("Show ComponentContent" + this.arrayIndex).onClick(()=>{
5841e41f4b71Sopenharmony_ci        if (this.arrayIndex >= 0 && this.arrayIndex < this.contentArray.length) {
5842e41f4b71Sopenharmony_ci          let componentContent = this.contentArray[this.arrayIndex]
5843e41f4b71Sopenharmony_ci          this.overlayNode.showComponentContent(componentContent)
5844e41f4b71Sopenharmony_ci        } else {
5845e41f4b71Sopenharmony_ci          console.info("Invalid arrayIndex.")
5846e41f4b71Sopenharmony_ci        }
5847e41f4b71Sopenharmony_ci      })
5848e41f4b71Sopenharmony_ci      Button("Hide ComponentContent" + this.arrayIndex).onClick(()=>{
5849e41f4b71Sopenharmony_ci        if (this.arrayIndex >= 0 && this.arrayIndex < this.contentArray.length) {
5850e41f4b71Sopenharmony_ci          let componentContent = this.contentArray[this.arrayIndex]
5851e41f4b71Sopenharmony_ci          this.overlayNode.hideComponentContent(componentContent)
5852e41f4b71Sopenharmony_ci        } else {
5853e41f4b71Sopenharmony_ci          console.info("Invalid arrayIndex.")
5854e41f4b71Sopenharmony_ci        }
5855e41f4b71Sopenharmony_ci      })
5856e41f4b71Sopenharmony_ci      Button("Show All ComponentContent").onClick(()=>{
5857e41f4b71Sopenharmony_ci          this.overlayNode.showAllComponentContents()
5858e41f4b71Sopenharmony_ci      })
5859e41f4b71Sopenharmony_ci      Button("Hide All ComponentContent").onClick(()=>{
5860e41f4b71Sopenharmony_ci        this.overlayNode.hideAllComponentContents()
5861e41f4b71Sopenharmony_ci      })
5862e41f4b71Sopenharmony_ci
5863e41f4b71Sopenharmony_ci      Button("Go").onClick(()=>{
5864e41f4b71Sopenharmony_ci        router.pushUrl({
5865e41f4b71Sopenharmony_ci          url: 'pages/Second'
5866e41f4b71Sopenharmony_ci        })
5867e41f4b71Sopenharmony_ci      })
5868e41f4b71Sopenharmony_ci    }
5869e41f4b71Sopenharmony_ci    .width('100%')
5870e41f4b71Sopenharmony_ci    .height('100%')
5871e41f4b71Sopenharmony_ci  }
5872e41f4b71Sopenharmony_ci}
5873e41f4b71Sopenharmony_ci```
5874e41f4b71Sopenharmony_ci
5875e41f4b71Sopenharmony_ci### removeComponentContent<sup>12+</sup>
5876e41f4b71Sopenharmony_ci
5877e41f4b71Sopenharmony_ciremoveComponentContent(content: ComponentContent): void
5878e41f4b71Sopenharmony_ci
5879e41f4b71Sopenharmony_ciRemoves a specified **ComponentContent** node from the **OverlayManager**
5880e41f4b71Sopenharmony_ci
5881e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5882e41f4b71Sopenharmony_ci
5883e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5884e41f4b71Sopenharmony_ci
5885e41f4b71Sopenharmony_ci**Parameters**
5886e41f4b71Sopenharmony_ci
5887e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description         |
5888e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ----------- |
5889e41f4b71Sopenharmony_ci| content | [ComponentContent](js-apis-arkui-ComponentContent.md) | Yes   | Content to remove from the **OverlayManager**. |
5890e41f4b71Sopenharmony_ci
5891e41f4b71Sopenharmony_ci**Example**
5892e41f4b71Sopenharmony_ci
5893e41f4b71Sopenharmony_ciSee [addComponentContent Example](#addcomponentcontent12).
5894e41f4b71Sopenharmony_ci
5895e41f4b71Sopenharmony_ci### showComponentContent<sup>12+</sup>
5896e41f4b71Sopenharmony_ci
5897e41f4b71Sopenharmony_cishowComponentContent(content: ComponentContent): void
5898e41f4b71Sopenharmony_ci
5899e41f4b71Sopenharmony_ciShows a specified **ComponentContent** node on the **OverlayManager**.
5900e41f4b71Sopenharmony_ci
5901e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5902e41f4b71Sopenharmony_ci
5903e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5904e41f4b71Sopenharmony_ci
5905e41f4b71Sopenharmony_ci**Parameters**
5906e41f4b71Sopenharmony_ci
5907e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description         |
5908e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ----------- |
5909e41f4b71Sopenharmony_ci| content | [ComponentContent](js-apis-arkui-ComponentContent.md) | Yes   | Content to show on the **OverlayManager**.|
5910e41f4b71Sopenharmony_ci
5911e41f4b71Sopenharmony_ci**Example**
5912e41f4b71Sopenharmony_ci
5913e41f4b71Sopenharmony_ciSee [addComponentContent Example](#addcomponentcontent12).
5914e41f4b71Sopenharmony_ci
5915e41f4b71Sopenharmony_ci### hideComponentContent<sup>12+</sup>
5916e41f4b71Sopenharmony_ci
5917e41f4b71Sopenharmony_cihideComponentContent(content: ComponentContent): void
5918e41f4b71Sopenharmony_ci
5919e41f4b71Sopenharmony_ciHides a specified **ComponentContent** node on the **OverlayManager**.
5920e41f4b71Sopenharmony_ci
5921e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5922e41f4b71Sopenharmony_ci
5923e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5924e41f4b71Sopenharmony_ci
5925e41f4b71Sopenharmony_ci**Parameters**
5926e41f4b71Sopenharmony_ci
5927e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description         |
5928e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ----------- |
5929e41f4b71Sopenharmony_ci| content | [ComponentContent](js-apis-arkui-ComponentContent.md) | Yes   | Content to hide on the **OverlayManager**. |
5930e41f4b71Sopenharmony_ci
5931e41f4b71Sopenharmony_ci**Example**
5932e41f4b71Sopenharmony_ci
5933e41f4b71Sopenharmony_ciSee [addComponentContent Example](#addcomponentcontent12).
5934e41f4b71Sopenharmony_ci
5935e41f4b71Sopenharmony_ci### showAllComponentContents<sup>12+</sup>
5936e41f4b71Sopenharmony_ci
5937e41f4b71Sopenharmony_cishowAllComponentContents(): void
5938e41f4b71Sopenharmony_ci
5939e41f4b71Sopenharmony_ciShows all **ComponentContent** nodes on the **OverlayManager**.
5940e41f4b71Sopenharmony_ci
5941e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5942e41f4b71Sopenharmony_ci
5943e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5944e41f4b71Sopenharmony_ci
5945e41f4b71Sopenharmony_ci**Example**
5946e41f4b71Sopenharmony_ci
5947e41f4b71Sopenharmony_ciSee [addComponentContent Example](#addcomponentcontent12).
5948e41f4b71Sopenharmony_ci
5949e41f4b71Sopenharmony_ci### hideAllComponentContents<sup>12+</sup>
5950e41f4b71Sopenharmony_ci
5951e41f4b71Sopenharmony_cihideAllComponentContents(): void
5952e41f4b71Sopenharmony_ci
5953e41f4b71Sopenharmony_ciHides all **ComponentContent** nodes on the **OverlayManager**.
5954e41f4b71Sopenharmony_ci
5955e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
5956e41f4b71Sopenharmony_ci
5957e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5958e41f4b71Sopenharmony_ci
5959e41f4b71Sopenharmony_ci**Example**
5960e41f4b71Sopenharmony_ci
5961e41f4b71Sopenharmony_ciSee [addComponentContent Example](#addcomponentcontent12).
5962e41f4b71Sopenharmony_ci
5963e41f4b71Sopenharmony_ci## AtomicServiceBar<sup>11+</sup>
5964e41f4b71Sopenharmony_ci
5965e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getAtomicServiceBar](#getatomicservicebar11) in **UIContext** to obtain an **AtomicServiceBar** instance, and then call the APIs using the obtained instance.
5966e41f4b71Sopenharmony_ci> **NOTE**
5967e41f4b71Sopenharmony_ci>
5968e41f4b71Sopenharmony_ci> Since API version 12, the atomic service menu bar style is changed, and the following APIs are obsolete:
5969e41f4b71Sopenharmony_ci
5970e41f4b71Sopenharmony_ci### setVisible<sup>11+</sup>
5971e41f4b71Sopenharmony_ci
5972e41f4b71Sopenharmony_cisetVisible(visible: boolean): void
5973e41f4b71Sopenharmony_ci
5974e41f4b71Sopenharmony_ciSets whether the atomic service menu bar is visible.
5975e41f4b71Sopenharmony_ci> **NOTE**
5976e41f4b71Sopenharmony_ci>
5977e41f4b71Sopenharmony_ci> The atomic service menu bar is hidden by default and replaced with a floating button since API version 12; it cannot be changed to visible using this API.
5978e41f4b71Sopenharmony_ci
5979e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
5980e41f4b71Sopenharmony_ci
5981e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
5982e41f4b71Sopenharmony_ci
5983e41f4b71Sopenharmony_ci**Parameters**
5984e41f4b71Sopenharmony_ci
5985e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
5986e41f4b71Sopenharmony_ci| ------- | ------- | ------- | ------- |
5987e41f4b71Sopenharmony_ci| visible | boolean | Yes | Whether the atomic service menu bar is visible.|
5988e41f4b71Sopenharmony_ci
5989e41f4b71Sopenharmony_ci
5990e41f4b71Sopenharmony_ci**Example**
5991e41f4b71Sopenharmony_ci
5992e41f4b71Sopenharmony_ci```ts
5993e41f4b71Sopenharmony_ciimport {UIContext, AtomicServiceBar, window } from '@kit.ArkUI';
5994e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
5995e41f4b71Sopenharmony_ci
5996e41f4b71Sopenharmony_cionWindowStageCreate(windowStage: window.WindowStage) {
5997e41f4b71Sopenharmony_ci  // Main window is created, set main page for this ability
5998e41f4b71Sopenharmony_ci  hilog.info(0x0000, 'testTag', 'Ability onWindowStageCreate');
5999e41f4b71Sopenharmony_ci  windowStage.loadContent('pages/Index', (err, data) => {
6000e41f4b71Sopenharmony_ci    let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext();
6001e41f4b71Sopenharmony_ci    let atomicServiceBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar();
6002e41f4b71Sopenharmony_ci    if (atomicServiceBar != undefined) {
6003e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Get AtomServiceBar Successfully.');
6004e41f4b71Sopenharmony_ci      atomicServiceBar.setVisible(false);
6005e41f4b71Sopenharmony_ci    } else {
6006e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Get AtomicServiceBar failed.');
6007e41f4b71Sopenharmony_ci    }
6008e41f4b71Sopenharmony_ci  });
6009e41f4b71Sopenharmony_ci}
6010e41f4b71Sopenharmony_ci```
6011e41f4b71Sopenharmony_ci
6012e41f4b71Sopenharmony_ci### setBackgroundColor<sup>11+</sup>
6013e41f4b71Sopenharmony_ci
6014e41f4b71Sopenharmony_cisetBackgroundColor(color:Nullable<Color | number | string>): void
6015e41f4b71Sopenharmony_ci
6016e41f4b71Sopenharmony_ciSets the background color of the atomic service menu bar.
6017e41f4b71Sopenharmony_ci> **NOTE**
6018e41f4b71Sopenharmony_ci>
6019e41f4b71Sopenharmony_ci> The background of the atomic service menu bar is hidden by default since API version 12; its color cannot be set using this API.
6020e41f4b71Sopenharmony_ci
6021e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6022e41f4b71Sopenharmony_ci
6023e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6024e41f4b71Sopenharmony_ci
6025e41f4b71Sopenharmony_ci**Parameters**
6026e41f4b71Sopenharmony_ci
6027e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
6028e41f4b71Sopenharmony_ci| ------ | ------ | ------ | ------ |
6029e41f4b71Sopenharmony_ci| color | Nullable\<[Color](arkui-ts/ts-appendix-enums.md#color) \| number \| string> | Yes | Background color of the atomic service menu bar. The value **undefined** means to use the default color.|
6030e41f4b71Sopenharmony_ci
6031e41f4b71Sopenharmony_ci**Example**
6032e41f4b71Sopenharmony_ci
6033e41f4b71Sopenharmony_ci```ts
6034e41f4b71Sopenharmony_ciimport {UIContext, AtomicServiceBar,window } from '@kit.ArkUI';
6035e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
6036e41f4b71Sopenharmony_cionWindowStageCreate(windowStage: window.WindowStage) {
6037e41f4b71Sopenharmony_ci  // Main window is created, set main page for this ability
6038e41f4b71Sopenharmony_ci  hilog.info(0x0000, 'testTag', 'Ability onWindowStageCreate');
6039e41f4b71Sopenharmony_ci  windowStage.loadContent('pages/Index', (err, data) => {
6040e41f4b71Sopenharmony_ci    let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext();
6041e41f4b71Sopenharmony_ci    let atomicServiceBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar();
6042e41f4b71Sopenharmony_ci    if (atomicServiceBar != undefined) {
6043e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Get AtomServiceBar Successfully.');
6044e41f4b71Sopenharmony_ci      atomicServiceBar.setBackgroundColor(0x88888888);
6045e41f4b71Sopenharmony_ci    } else {
6046e41f4b71Sopenharmony_ci      hilog.error(0x0000, 'testTag', 'Get AtomicServiceBar failed.');
6047e41f4b71Sopenharmony_ci    }
6048e41f4b71Sopenharmony_ci  });
6049e41f4b71Sopenharmony_ci}
6050e41f4b71Sopenharmony_ci```
6051e41f4b71Sopenharmony_ci
6052e41f4b71Sopenharmony_ci### setTitleContent<sup>11+</sup>
6053e41f4b71Sopenharmony_ci
6054e41f4b71Sopenharmony_cisetTitleContent(content:string): void
6055e41f4b71Sopenharmony_ci
6056e41f4b71Sopenharmony_ciSets the title content of the atomic service menu bar.
6057e41f4b71Sopenharmony_ci> **NOTE**
6058e41f4b71Sopenharmony_ci>
6059e41f4b71Sopenharmony_ci> The title of the atomic service menu bar is hidden by default since API version 12; its content cannot be set using this API.
6060e41f4b71Sopenharmony_ci
6061e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6062e41f4b71Sopenharmony_ci
6063e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6064e41f4b71Sopenharmony_ci
6065e41f4b71Sopenharmony_ci**Parameters**
6066e41f4b71Sopenharmony_ci
6067e41f4b71Sopenharmony_ci|Name|Type|Mandatory|Description |
6068e41f4b71Sopenharmony_ci| ------- | ------- | ------- | ------- |
6069e41f4b71Sopenharmony_ci| content | string | Yes | Title content of the atomic service menu bar.|
6070e41f4b71Sopenharmony_ci
6071e41f4b71Sopenharmony_ci**Example**
6072e41f4b71Sopenharmony_ci
6073e41f4b71Sopenharmony_ci```ts
6074e41f4b71Sopenharmony_ciimport {UIContext, AtomicServiceBar,window } from '@kit.ArkUI';
6075e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
6076e41f4b71Sopenharmony_ci
6077e41f4b71Sopenharmony_cionWindowStageCreate(windowStage: window.WindowStage) {
6078e41f4b71Sopenharmony_ci  // Main window is created, set main page for this ability
6079e41f4b71Sopenharmony_ci  hilog.info(0x0000, 'testTag', 'Ability onWindowStageCreate');
6080e41f4b71Sopenharmony_ci  windowStage.loadContent('pages/Index', (err, data) => {
6081e41f4b71Sopenharmony_ci    let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext();
6082e41f4b71Sopenharmony_ci    let atomicServiceBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar();
6083e41f4b71Sopenharmony_ci    if (atomicServiceBar != undefined) {
6084e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Get AtomServiceBar Successfully.');
6085e41f4b71Sopenharmony_ci      atomicServiceBar.setTitleContent('text2');
6086e41f4b71Sopenharmony_ci    } else {
6087e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Get AtomicServiceBar failed.');
6088e41f4b71Sopenharmony_ci    }
6089e41f4b71Sopenharmony_ci  });
6090e41f4b71Sopenharmony_ci}
6091e41f4b71Sopenharmony_ci```
6092e41f4b71Sopenharmony_ci
6093e41f4b71Sopenharmony_ci### setTitleFontStyle<sup>11+</sup>
6094e41f4b71Sopenharmony_ci
6095e41f4b71Sopenharmony_cisetTitleFontStyle(font:FontStyle):void
6096e41f4b71Sopenharmony_ci
6097e41f4b71Sopenharmony_ciSets the font style of the atomic service menu bar.
6098e41f4b71Sopenharmony_ci> **NOTE**
6099e41f4b71Sopenharmony_ci>
6100e41f4b71Sopenharmony_ci> The title of the atomic service menu bar is hidden by default since API version 12; its font style cannot be set using this API.
6101e41f4b71Sopenharmony_ci
6102e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6103e41f4b71Sopenharmony_ci
6104e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6105e41f4b71Sopenharmony_ci
6106e41f4b71Sopenharmony_ci**Parameters**
6107e41f4b71Sopenharmony_ci
6108e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
6109e41f4b71Sopenharmony_ci| ------ | ------ | ------ | ------ |
6110e41f4b71Sopenharmony_ci| font | [FontStyle](arkui-ts/ts-appendix-enums.md#fontstyle) | Yes | Font style of the atomic service menu bar. |
6111e41f4b71Sopenharmony_ci
6112e41f4b71Sopenharmony_ci**Example**
6113e41f4b71Sopenharmony_ci
6114e41f4b71Sopenharmony_ci```ts
6115e41f4b71Sopenharmony_ciimport {UIContext, Font, AtomicServiceBar } from '@kit.ArkUI';
6116e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
6117e41f4b71Sopenharmony_ci
6118e41f4b71Sopenharmony_cionWindowStageCreate(windowStage: window.WindowStage) {
6119e41f4b71Sopenharmony_ci  // Main window is created, set main page for this ability
6120e41f4b71Sopenharmony_ci  hilog.info(0x0000, 'testTag', 'Ability onWindowStageCreate');
6121e41f4b71Sopenharmony_ci  windowStage.loadContent('pages/Index', (err, data) => {
6122e41f4b71Sopenharmony_ci    let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext();
6123e41f4b71Sopenharmony_ci    let atomicServiceBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar();
6124e41f4b71Sopenharmony_ci    if (atomicServiceBar != undefined) {
6125e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Get AtomServiceBar Successfully.');
6126e41f4b71Sopenharmony_ci      atomicServiceBar.setTitleFontStyle(FontStyle.Normal);
6127e41f4b71Sopenharmony_ci    } else {
6128e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Get AtomicServiceBar failed.');
6129e41f4b71Sopenharmony_ci    }
6130e41f4b71Sopenharmony_ci  });
6131e41f4b71Sopenharmony_ci}
6132e41f4b71Sopenharmony_ci```
6133e41f4b71Sopenharmony_ci
6134e41f4b71Sopenharmony_ci### setIconColor<sup>11+</sup>
6135e41f4b71Sopenharmony_ci
6136e41f4b71Sopenharmony_cisetIconColor(color:Nullable<Color | number | string>): void
6137e41f4b71Sopenharmony_ci
6138e41f4b71Sopenharmony_ciSets the color of the atomic service icon.
6139e41f4b71Sopenharmony_ci> **NOTE**
6140e41f4b71Sopenharmony_ci>
6141e41f4b71Sopenharmony_ci> The atomic service menu bar is hidden by default and replaced with a floating button since API version 12; the icon color cannot be changed using this API.
6142e41f4b71Sopenharmony_ci
6143e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6144e41f4b71Sopenharmony_ci
6145e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6146e41f4b71Sopenharmony_ci
6147e41f4b71Sopenharmony_ci**Parameters**
6148e41f4b71Sopenharmony_ci
6149e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
6150e41f4b71Sopenharmony_ci| ------- | ------- | ------- | ------- |
6151e41f4b71Sopenharmony_ci| color | Nullable\<[Color](arkui-ts/ts-appendix-enums.md#color) \| number \| string> | Yes | Color of the atomic service icon. The value **undefined** means to use the default color. |
6152e41f4b71Sopenharmony_ci
6153e41f4b71Sopenharmony_ci
6154e41f4b71Sopenharmony_ci**Example**
6155e41f4b71Sopenharmony_ci
6156e41f4b71Sopenharmony_ci```ts
6157e41f4b71Sopenharmony_ciimport {UIContext, Font, window } from '@kit.ArkUI';
6158e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
6159e41f4b71Sopenharmony_ci
6160e41f4b71Sopenharmony_cionWindowStageCreate(windowStage: window.WindowStage) {
6161e41f4b71Sopenharmony_ci  // Main window is created, set main page for this ability
6162e41f4b71Sopenharmony_ci  hilog.info(0x0000, 'testTag', 'Ability onWindowStageCreate');
6163e41f4b71Sopenharmony_ci  windowStage.loadContent('pages/Index', (err, data) => {
6164e41f4b71Sopenharmony_ci    let uiContext: UIContext = windowStage.getMainWindowSync().getUIContext();
6165e41f4b71Sopenharmony_ci    let atomicServiceBar: Nullable<AtomicServiceBar> = uiContext.getAtomicServiceBar();
6166e41f4b71Sopenharmony_ci    if (atomicServiceBar != undefined) {
6167e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Get AtomServiceBar Successfully.');
6168e41f4b71Sopenharmony_ci      atomicServiceBar.setIconColor(0x12345678);
6169e41f4b71Sopenharmony_ci    } else {
6170e41f4b71Sopenharmony_ci      hilog.info(0x0000, 'testTag', 'Get AtomicServiceBar failed.');
6171e41f4b71Sopenharmony_ci    }
6172e41f4b71Sopenharmony_ci  });
6173e41f4b71Sopenharmony_ci}
6174e41f4b71Sopenharmony_ci```
6175e41f4b71Sopenharmony_ci## KeyboardAvoidMode<sup>11+</sup>
6176e41f4b71Sopenharmony_ci
6177e41f4b71Sopenharmony_ciEnumerates the avoidance modes for the virtual keyboard.
6178e41f4b71Sopenharmony_ci
6179e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
6180e41f4b71Sopenharmony_ci
6181e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6182e41f4b71Sopenharmony_ci
6183e41f4b71Sopenharmony_ci| Name  | Value  | Description      |
6184e41f4b71Sopenharmony_ci| ------ | ---- | ---------- |
6185e41f4b71Sopenharmony_ci| OFFSET | 0    | Avoid the virtual keyboard through offset. |
6186e41f4b71Sopenharmony_ci| RESIZE | 1    | Avoid the virtual keyboard through resizing. |
6187e41f4b71Sopenharmony_ci
6188e41f4b71Sopenharmony_ci
6189e41f4b71Sopenharmony_ci## FocusController<sup>12+</sup>
6190e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getFocusController()](js-apis-arkui-UIContext.md#getFocusController12) in **UIContext** to obtain a **UIContext** instance, and then call the APIs using the obtained instance.
6191e41f4b71Sopenharmony_ci
6192e41f4b71Sopenharmony_ci### clearFocus<sup>12+</sup>
6193e41f4b71Sopenharmony_ci
6194e41f4b71Sopenharmony_ciclearFocus(): void
6195e41f4b71Sopenharmony_ci
6196e41f4b71Sopenharmony_ciClears the focus and forcibly moves the focus to the root container node of the page, causing other nodes in the focus chain to lose focus.
6197e41f4b71Sopenharmony_ci
6198e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6199e41f4b71Sopenharmony_ci
6200e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6201e41f4b71Sopenharmony_ci
6202e41f4b71Sopenharmony_ci**Example**
6203e41f4b71Sopenharmony_ci
6204e41f4b71Sopenharmony_ci```ts
6205e41f4b71Sopenharmony_ci@Entry
6206e41f4b71Sopenharmony_ci@Component
6207e41f4b71Sopenharmony_cistruct ClearFocusExample {
6208e41f4b71Sopenharmony_ci  @State inputValue: string = ''
6209e41f4b71Sopenharmony_ci  @State btColor: Color = Color.Blue
6210e41f4b71Sopenharmony_ci
6211e41f4b71Sopenharmony_ci  build() {
6212e41f4b71Sopenharmony_ci    Column({ space: 20 }) {
6213e41f4b71Sopenharmony_ci      Column({ space: 5 }) {
6214e41f4b71Sopenharmony_ci        Button('button1')
6215e41f4b71Sopenharmony_ci          .width(200)
6216e41f4b71Sopenharmony_ci          .height(70)
6217e41f4b71Sopenharmony_ci          .fontColor(Color.White)
6218e41f4b71Sopenharmony_ci          .focusOnTouch(true)
6219e41f4b71Sopenharmony_ci          .backgroundColor(Color.Blue)
6220e41f4b71Sopenharmony_ci        Button('button2')
6221e41f4b71Sopenharmony_ci          .width(200)
6222e41f4b71Sopenharmony_ci          .height(70)
6223e41f4b71Sopenharmony_ci          .fontColor(Color.White)
6224e41f4b71Sopenharmony_ci          .focusOnTouch(true)
6225e41f4b71Sopenharmony_ci          .backgroundColor(this.btColor)
6226e41f4b71Sopenharmony_ci          .defaultFocus(true)
6227e41f4b71Sopenharmony_ci          .onFocus(() => {
6228e41f4b71Sopenharmony_ci            this.btColor = Color.Red
6229e41f4b71Sopenharmony_ci          })
6230e41f4b71Sopenharmony_ci          .onBlur(() => {
6231e41f4b71Sopenharmony_ci            this.btColor = Color.Blue
6232e41f4b71Sopenharmony_ci          })
6233e41f4b71Sopenharmony_ci        Button('clearFocus')
6234e41f4b71Sopenharmony_ci          .width(200)
6235e41f4b71Sopenharmony_ci          .height(70)
6236e41f4b71Sopenharmony_ci          .fontColor(Color.White)
6237e41f4b71Sopenharmony_ci          .backgroundColor(Color.Blue)
6238e41f4b71Sopenharmony_ci          .onClick(() => {
6239e41f4b71Sopenharmony_ci            this.getUIContext().getFocusController().clearFocus()
6240e41f4b71Sopenharmony_ci          })
6241e41f4b71Sopenharmony_ci      }
6242e41f4b71Sopenharmony_ci    }
6243e41f4b71Sopenharmony_ci    .width('100%')
6244e41f4b71Sopenharmony_ci    .height('100%')
6245e41f4b71Sopenharmony_ci  }
6246e41f4b71Sopenharmony_ci}
6247e41f4b71Sopenharmony_ci```
6248e41f4b71Sopenharmony_ci
6249e41f4b71Sopenharmony_ci### requestFocus<sup>12+</sup>
6250e41f4b71Sopenharmony_ci
6251e41f4b71Sopenharmony_cirequestFocus(key: string): void
6252e41f4b71Sopenharmony_ci
6253e41f4b71Sopenharmony_ciSets focus on the specified entity node in the component tree based on the component ID.
6254e41f4b71Sopenharmony_ci
6255e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6256e41f4b71Sopenharmony_ci
6257e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6258e41f4b71Sopenharmony_ci
6259e41f4b71Sopenharmony_ci**Parameters**
6260e41f4b71Sopenharmony_ci
6261e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description |
6262e41f4b71Sopenharmony_ci| ------- | ------- | ------- | ------- |
6263e41f4b71Sopenharmony_ci| key | string | Yes | [Component ID](arkui-ts/ts-universal-attributes-component-id.md) of the target node.|
6264e41f4b71Sopenharmony_ci
6265e41f4b71Sopenharmony_ci**Error codes**
6266e41f4b71Sopenharmony_ci
6267e41f4b71Sopenharmony_ciFor details about the error codes, see [Focus Error Codes](errorcode-focus.md).
6268e41f4b71Sopenharmony_ci
6269e41f4b71Sopenharmony_ci| ID | Error Message                                    |
6270e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- |
6271e41f4b71Sopenharmony_ci| 150001 | This component is not focusable. |
6272e41f4b71Sopenharmony_ci| 150002 | This component has an unfocusable ancestor.      |
6273e41f4b71Sopenharmony_ci| 150003 | The component doesn't exist, is currently invisible, or has been disabled. |
6274e41f4b71Sopenharmony_ci
6275e41f4b71Sopenharmony_ci**Example**
6276e41f4b71Sopenharmony_ci
6277e41f4b71Sopenharmony_ci```ts
6278e41f4b71Sopenharmony_ci@Entry
6279e41f4b71Sopenharmony_ci@Component
6280e41f4b71Sopenharmony_cistruct RequestExample {
6281e41f4b71Sopenharmony_ci  @State btColor: Color = Color.Blue
6282e41f4b71Sopenharmony_ci
6283e41f4b71Sopenharmony_ci  build() {
6284e41f4b71Sopenharmony_ci    Column({ space: 20 }) {
6285e41f4b71Sopenharmony_ci      Column({ space: 5 }) {
6286e41f4b71Sopenharmony_ci        Button('Button')
6287e41f4b71Sopenharmony_ci          .width(200)
6288e41f4b71Sopenharmony_ci          .height(70)
6289e41f4b71Sopenharmony_ci          .fontColor(Color.White)
6290e41f4b71Sopenharmony_ci          .focusOnTouch(true)
6291e41f4b71Sopenharmony_ci          .backgroundColor(this.btColor)
6292e41f4b71Sopenharmony_ci          .onFocus(() => {
6293e41f4b71Sopenharmony_ci            this.btColor = Color.Red
6294e41f4b71Sopenharmony_ci          })
6295e41f4b71Sopenharmony_ci          .onBlur(() => {
6296e41f4b71Sopenharmony_ci            this.btColor = Color.Blue
6297e41f4b71Sopenharmony_ci          })
6298e41f4b71Sopenharmony_ci          .id("testButton")
6299e41f4b71Sopenharmony_ci
6300e41f4b71Sopenharmony_ci        Divider()
6301e41f4b71Sopenharmony_ci          .vertical(false)
6302e41f4b71Sopenharmony_ci          .width("80%")
6303e41f4b71Sopenharmony_ci          .backgroundColor(Color.Black)
6304e41f4b71Sopenharmony_ci          .height(10)
6305e41f4b71Sopenharmony_ci
6306e41f4b71Sopenharmony_ci        Button('requestFocus')
6307e41f4b71Sopenharmony_ci          .width(200)
6308e41f4b71Sopenharmony_ci          .height(70)
6309e41f4b71Sopenharmony_ci          .onClick(() => {
6310e41f4b71Sopenharmony_ci            this.getUIContext().getFocusController().requestFocus("testButton")
6311e41f4b71Sopenharmony_ci          })
6312e41f4b71Sopenharmony_ci
6313e41f4b71Sopenharmony_ci        Button('requestFocus fail')
6314e41f4b71Sopenharmony_ci          .width(200)
6315e41f4b71Sopenharmony_ci          .height(70)
6316e41f4b71Sopenharmony_ci          .onClick(() => {
6317e41f4b71Sopenharmony_ci            try {
6318e41f4b71Sopenharmony_ci              this.getUIContext().getFocusController().requestFocus("eee")
6319e41f4b71Sopenharmony_ci            } catch (error) {
6320e41f4b71Sopenharmony_ci              console.error('requestFocus failed code is ' + error.code + ' message is ' + error.message)
6321e41f4b71Sopenharmony_ci            }
6322e41f4b71Sopenharmony_ci          })
6323e41f4b71Sopenharmony_ci      }
6324e41f4b71Sopenharmony_ci    }
6325e41f4b71Sopenharmony_ci    .width('100%')
6326e41f4b71Sopenharmony_ci    .height('100%')
6327e41f4b71Sopenharmony_ci  }
6328e41f4b71Sopenharmony_ci}
6329e41f4b71Sopenharmony_ci```
6330e41f4b71Sopenharmony_ci
6331e41f4b71Sopenharmony_ci## CursorController<sup>12+</sup>
6332e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getCursorController()](js-apis-arkui-UIContext.md#getcursorcontroller12) in **UIContext** to obtain a **CursorController** instance, and then call the APIs using the obtained instance.
6333e41f4b71Sopenharmony_ci
6334e41f4b71Sopenharmony_ci### restoreDefault<sup>12+</sup>
6335e41f4b71Sopenharmony_ci
6336e41f4b71Sopenharmony_cirestoreDefault(): void
6337e41f4b71Sopenharmony_ci
6338e41f4b71Sopenharmony_ciRestores the default cursor style.
6339e41f4b71Sopenharmony_ci
6340e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6341e41f4b71Sopenharmony_ci
6342e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6343e41f4b71Sopenharmony_ci
6344e41f4b71Sopenharmony_ci**Example**
6345e41f4b71Sopenharmony_ciIn this example, the **restoreDefault** API of **CursorController** is used to restore the cursor style when the cursor moves out of the green frame.
6346e41f4b71Sopenharmony_ci
6347e41f4b71Sopenharmony_ci```ts
6348e41f4b71Sopenharmony_ciimport { pointer } from '@kit.InputKit';
6349e41f4b71Sopenharmony_ciimport { UIContext, CursorController } from '@kit.ArkUI';
6350e41f4b71Sopenharmony_ci
6351e41f4b71Sopenharmony_ci@Entry
6352e41f4b71Sopenharmony_ci@Component
6353e41f4b71Sopenharmony_cistruct CursorControlExample {
6354e41f4b71Sopenharmony_ci  @State text: string = ''
6355e41f4b71Sopenharmony_ci  cursorCustom: CursorController = this.getUIContext().getCursorController();
6356e41f4b71Sopenharmony_ci
6357e41f4b71Sopenharmony_ci  build() {
6358e41f4b71Sopenharmony_ci    Column() {
6359e41f4b71Sopenharmony_ci      Row().height(200).width(200).backgroundColor(Color.Green).position({x: 150 ,y:70})
6360e41f4b71Sopenharmony_ci        .onHover((flag) => {
6361e41f4b71Sopenharmony_ci          if (flag) {
6362e41f4b71Sopenharmony_ci            this.cursorCustom.setCursor(pointer.PointerStyle.EAST)
6363e41f4b71Sopenharmony_ci          } else {
6364e41f4b71Sopenharmony_ci            console.info("restoreDefault");
6365e41f4b71Sopenharmony_ci            this.cursorCustom.restoreDefault();
6366e41f4b71Sopenharmony_ci          }
6367e41f4b71Sopenharmony_ci        })
6368e41f4b71Sopenharmony_ci    }.width('100%')
6369e41f4b71Sopenharmony_ci  }
6370e41f4b71Sopenharmony_ci}
6371e41f4b71Sopenharmony_ci```
6372e41f4b71Sopenharmony_ci![cursor-restoreDefault](figures/cursor-restoreDefault.gif)
6373e41f4b71Sopenharmony_ci
6374e41f4b71Sopenharmony_ci### setCursor<sup>12+</sup>
6375e41f4b71Sopenharmony_ci
6376e41f4b71Sopenharmony_cisetCursor(value: PointerStyle): void
6377e41f4b71Sopenharmony_ci
6378e41f4b71Sopenharmony_ciSets the cursor style.
6379e41f4b71Sopenharmony_ci
6380e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6381e41f4b71Sopenharmony_ci
6382e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6383e41f4b71Sopenharmony_ci
6384e41f4b71Sopenharmony_ci**Parameters**
6385e41f4b71Sopenharmony_ci
6386e41f4b71Sopenharmony_ci| Name    | Type                                      | Mandatory  | Description     |
6387e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | ---- | ------- |
6388e41f4b71Sopenharmony_ci| value | [PointerStyle](../apis-input-kit/js-apis-pointer.md#pointerstyle) | Yes   | Cursor style. |
6389e41f4b71Sopenharmony_ci
6390e41f4b71Sopenharmony_ci**Example**
6391e41f4b71Sopenharmony_ciIn this example, the **setCursor** API of **CursorController** is used to set the cursor style to **PointerStyle.WEST** when the cursor moves into the blue frame.
6392e41f4b71Sopenharmony_ci
6393e41f4b71Sopenharmony_ci```ts
6394e41f4b71Sopenharmony_ciimport { pointer } from '@kit.InputKit';
6395e41f4b71Sopenharmony_ciimport { UIContext, CursorController } from '@kit.ArkUI';
6396e41f4b71Sopenharmony_ci
6397e41f4b71Sopenharmony_ci@Entry
6398e41f4b71Sopenharmony_ci@Component
6399e41f4b71Sopenharmony_cistruct CursorControlExample {
6400e41f4b71Sopenharmony_ci  @State text: string = ''
6401e41f4b71Sopenharmony_ci  cursorCustom: CursorController = this.getUIContext().getCursorController();
6402e41f4b71Sopenharmony_ci
6403e41f4b71Sopenharmony_ci  build() {
6404e41f4b71Sopenharmony_ci    Column() {
6405e41f4b71Sopenharmony_ci      Row().height(200).width(200).backgroundColor(Color.Blue).position({x: 100 ,y:70})
6406e41f4b71Sopenharmony_ci        .onHover((flag) => {
6407e41f4b71Sopenharmony_ci          if (flag) {
6408e41f4b71Sopenharmony_ci            this.cursorCustom.setCursor(pointer.PointerStyle.WEST)
6409e41f4b71Sopenharmony_ci          } else {
6410e41f4b71Sopenharmony_ci            this.cursorCustom.restoreDefault();
6411e41f4b71Sopenharmony_ci          }
6412e41f4b71Sopenharmony_ci        })
6413e41f4b71Sopenharmony_ci    }.width('100%')
6414e41f4b71Sopenharmony_ci  }
6415e41f4b71Sopenharmony_ci}
6416e41f4b71Sopenharmony_ci```
6417e41f4b71Sopenharmony_ci![cursor-setCursor](figures/cursor-setCursor.gif)
6418e41f4b71Sopenharmony_ci
6419e41f4b71Sopenharmony_ci## ContextMenuController<sup>12+</sup>
6420e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getContextMenuController()](js-apis-arkui-UIContext.md#getcontextmenucontroller12) in **UIContext** to obtain a **ContextMenuController** instance, and then call the APIs using the obtained instance.
6421e41f4b71Sopenharmony_ci
6422e41f4b71Sopenharmony_ci### close<sup>12+</sup>
6423e41f4b71Sopenharmony_ci
6424e41f4b71Sopenharmony_ciclose(): void
6425e41f4b71Sopenharmony_ci
6426e41f4b71Sopenharmony_ciCloses this menu.
6427e41f4b71Sopenharmony_ci
6428e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6429e41f4b71Sopenharmony_ci
6430e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6431e41f4b71Sopenharmony_ci
6432e41f4b71Sopenharmony_ci**Example**
6433e41f4b71Sopenharmony_ciThis example triggers the **close** API of **ContextMenuController** by a time to close the menu.
6434e41f4b71Sopenharmony_ci
6435e41f4b71Sopenharmony_ci```ts
6436e41f4b71Sopenharmony_ciimport { ContextMenuController } from '@kit.ArkUI';
6437e41f4b71Sopenharmony_ci
6438e41f4b71Sopenharmony_ci@Entry
6439e41f4b71Sopenharmony_ci@Component
6440e41f4b71Sopenharmony_cistruct Index {
6441e41f4b71Sopenharmony_ci  menu: ContextMenuController = this.getUIContext().getContextMenuController();
6442e41f4b71Sopenharmony_ci
6443e41f4b71Sopenharmony_ci  @Builder MenuBuilder() {
6444e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
6445e41f4b71Sopenharmony_ci      Button('Test ContextMenu1 Close')
6446e41f4b71Sopenharmony_ci      Divider().strokeWidth(2).margin(5).color(Color.Black)
6447e41f4b71Sopenharmony_ci      Button('Test ContextMenu2')
6448e41f4b71Sopenharmony_ci      Divider().strokeWidth(2).margin(5).color(Color.Black)
6449e41f4b71Sopenharmony_ci      Button('Test ContextMenu3')
6450e41f4b71Sopenharmony_ci    }
6451e41f4b71Sopenharmony_ci    .width(200)
6452e41f4b71Sopenharmony_ci    .height(160)
6453e41f4b71Sopenharmony_ci  }
6454e41f4b71Sopenharmony_ci
6455e41f4b71Sopenharmony_ci  build() {
6456e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
6457e41f4b71Sopenharmony_ci      Button("Start Timer").onClick(()=>
6458e41f4b71Sopenharmony_ci      {
6459e41f4b71Sopenharmony_ci        setTimeout(() => {
6460e41f4b71Sopenharmony_ci          this.menu.close();
6461e41f4b71Sopenharmony_ci        }, 10000);
6462e41f4b71Sopenharmony_ci      })
6463e41f4b71Sopenharmony_ci
6464e41f4b71Sopenharmony_ci      Column() {
6465e41f4b71Sopenharmony_ci        Text("Test ContextMenu close")
6466e41f4b71Sopenharmony_ci          .fontSize(20)
6467e41f4b71Sopenharmony_ci          .width('100%')
6468e41f4b71Sopenharmony_ci          .height(500)
6469e41f4b71Sopenharmony_ci          .backgroundColor(0xAFEEEE)
6470e41f4b71Sopenharmony_ci          .textAlign(TextAlign.Center)
6471e41f4b71Sopenharmony_ci      }
6472e41f4b71Sopenharmony_ci      .bindContextMenu(this.MenuBuilder, ResponseType.LongPress)
6473e41f4b71Sopenharmony_ci    }
6474e41f4b71Sopenharmony_ci    .width('100%')
6475e41f4b71Sopenharmony_ci    .height('100%')
6476e41f4b71Sopenharmony_ci  }
6477e41f4b71Sopenharmony_ci}
6478e41f4b71Sopenharmony_ci```
6479e41f4b71Sopenharmony_ci
6480e41f4b71Sopenharmony_ci![contextMenuController_close](figures/contextMenuController_close.gif)
6481e41f4b71Sopenharmony_ci
6482e41f4b71Sopenharmony_ci## MeasureUtils<sup>12+</sup>
6483e41f4b71Sopenharmony_ci
6484e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getMeasureUtils()](js-apis-arkui-UIContext.md#getmeasureutils12) in **UIContext** to obtain a **MeasureUtils** instance, and then call the APIs using the obtained instance.
6485e41f4b71Sopenharmony_ci
6486e41f4b71Sopenharmony_ci### measureText<sup>12+</sup>
6487e41f4b71Sopenharmony_ci
6488e41f4b71Sopenharmony_cimeasureText(options: MeasureOptions): number
6489e41f4b71Sopenharmony_ci
6490e41f4b71Sopenharmony_ciMeasures the width of the given single-line text.
6491e41f4b71Sopenharmony_ci
6492e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6493e41f4b71Sopenharmony_ci
6494e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6495e41f4b71Sopenharmony_ci
6496e41f4b71Sopenharmony_ci**Parameters**
6497e41f4b71Sopenharmony_ci
6498e41f4b71Sopenharmony_ci| Name    | Type                             | Mandatory  | Description       |
6499e41f4b71Sopenharmony_ci| ------- | ------------------------------- | ---- | --------- |
6500e41f4b71Sopenharmony_ci| options | [MeasureOptions](js-apis-measure.md#measureoptions) | Yes   | Options of the target text. |
6501e41f4b71Sopenharmony_ci
6502e41f4b71Sopenharmony_ci**Return value**
6503e41f4b71Sopenharmony_ci
6504e41f4b71Sopenharmony_ci| Type         | Description      |
6505e41f4b71Sopenharmony_ci| ------------  | --------- |
6506e41f4b71Sopenharmony_ci| number        | Text width.<br>**NOTE**<br>Unit: px |
6507e41f4b71Sopenharmony_ci
6508e41f4b71Sopenharmony_ci
6509e41f4b71Sopenharmony_ci**Example**
6510e41f4b71Sopenharmony_ciThis example uses the **measureText** API of **MeasureUtils** to obtain the width of the **"Hello World"** text.
6511e41f4b71Sopenharmony_ci
6512e41f4b71Sopenharmony_ci```ts
6513e41f4b71Sopenharmony_ciimport { MeasureUtils } from '@kit.ArkUI';
6514e41f4b71Sopenharmony_ci
6515e41f4b71Sopenharmony_ci@Entry
6516e41f4b71Sopenharmony_ci@Component
6517e41f4b71Sopenharmony_cistruct Index {
6518e41f4b71Sopenharmony_ci  @State uiContext: UIContext = this.getUIContext();
6519e41f4b71Sopenharmony_ci  @State uiContextMeasure: MeasureUtils = this.uiContext.getMeasureUtils();
6520e41f4b71Sopenharmony_ci  @State textWidth: number = this.uiContextMeasure.measureText({
6521e41f4b71Sopenharmony_ci    textContent: "Hello word",
6522e41f4b71Sopenharmony_ci    fontSize: '50px'
6523e41f4b71Sopenharmony_ci  })
6524e41f4b71Sopenharmony_ci
6525e41f4b71Sopenharmony_ci  build() {
6526e41f4b71Sopenharmony_ci    Row() {
6527e41f4b71Sopenharmony_ci      Column() {
6528e41f4b71Sopenharmony_ci        Text(`The width of 'Hello World': ${this.textWidth}`)
6529e41f4b71Sopenharmony_ci      }
6530e41f4b71Sopenharmony_ci      .width('100%')
6531e41f4b71Sopenharmony_ci    }
6532e41f4b71Sopenharmony_ci    .height('100%')
6533e41f4b71Sopenharmony_ci  }
6534e41f4b71Sopenharmony_ci}
6535e41f4b71Sopenharmony_ci```
6536e41f4b71Sopenharmony_ci
6537e41f4b71Sopenharmony_ci### measureTextSize<sup>12+</sup>
6538e41f4b71Sopenharmony_ci
6539e41f4b71Sopenharmony_cimeasureTextSize(options: MeasureOptions): SizeOptions
6540e41f4b71Sopenharmony_ci
6541e41f4b71Sopenharmony_ciMeasures the width and height of the given single-line text.
6542e41f4b71Sopenharmony_ci
6543e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6544e41f4b71Sopenharmony_ci
6545e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6546e41f4b71Sopenharmony_ci
6547e41f4b71Sopenharmony_ci**Parameters**
6548e41f4b71Sopenharmony_ci
6549e41f4b71Sopenharmony_ci| Name    | Type                             | Mandatory  | Description       |
6550e41f4b71Sopenharmony_ci| ------- | ------------------------------- | ---- | --------- |
6551e41f4b71Sopenharmony_ci| options | [MeasureOptions](js-apis-measure.md#measureoptions) | Yes   | Options of the target text. |
6552e41f4b71Sopenharmony_ci
6553e41f4b71Sopenharmony_ci**Return value**
6554e41f4b71Sopenharmony_ci
6555e41f4b71Sopenharmony_ci| Type         | Description      |
6556e41f4b71Sopenharmony_ci| ------------  | --------- |
6557e41f4b71Sopenharmony_ci| [SizeOption](arkui-ts/ts-types.md#sizeoptions)   | Width and height of the text.<br>**NOTE**<br> The return values for text width and height are both in px. |
6558e41f4b71Sopenharmony_ci
6559e41f4b71Sopenharmony_ci
6560e41f4b71Sopenharmony_ci**Example**
6561e41f4b71Sopenharmony_ciThis example uses the **measureTextSize** API of **MeasureUtils** to obtain the width and height of the **"Hello World"** text.
6562e41f4b71Sopenharmony_ci
6563e41f4b71Sopenharmony_ci```ts
6564e41f4b71Sopenharmony_ciimport { MeasureUtils } from '@kit.ArkUI';
6565e41f4b71Sopenharmony_ci
6566e41f4b71Sopenharmony_ci@Entry
6567e41f4b71Sopenharmony_ci@Component
6568e41f4b71Sopenharmony_cistruct Index {
6569e41f4b71Sopenharmony_ci  @State uiContext: UIContext = this.getUIContext();
6570e41f4b71Sopenharmony_ci  @State uiContextMeasure: MeasureUtils = this.uiContext.getMeasureUtils();
6571e41f4b71Sopenharmony_ci  textSize : SizeOptions = this.uiContextMeasure.measureTextSize({
6572e41f4b71Sopenharmony_ci    textContent: "Hello word",
6573e41f4b71Sopenharmony_ci    fontSize: '50px'
6574e41f4b71Sopenharmony_ci  })
6575e41f4b71Sopenharmony_ci  build() {
6576e41f4b71Sopenharmony_ci    Row() {
6577e41f4b71Sopenharmony_ci      Column() {
6578e41f4b71Sopenharmony_ci        Text(`The width of 'Hello World': ${this.textSize.width}`)
6579e41f4b71Sopenharmony_ci        Text(`The height of 'Hello World': ${this.textSize.height}`)
6580e41f4b71Sopenharmony_ci      }
6581e41f4b71Sopenharmony_ci      .width('100%')
6582e41f4b71Sopenharmony_ci    }
6583e41f4b71Sopenharmony_ci    .height('100%')
6584e41f4b71Sopenharmony_ci  }
6585e41f4b71Sopenharmony_ci}
6586e41f4b71Sopenharmony_ci```
6587e41f4b71Sopenharmony_ci
6588e41f4b71Sopenharmony_ci## ComponentSnapshot<sup>12+</sup>
6589e41f4b71Sopenharmony_ci
6590e41f4b71Sopenharmony_ciIn the following API examples, you must first use [getComponentSnapshot()](js-apis-arkui-UIContext.md#getcomponentsnapshot12) in **UIContext** to obtain a **ComponentSnapshot** instance, and then call the APIs using the obtained instance.
6591e41f4b71Sopenharmony_ci
6592e41f4b71Sopenharmony_ci### get<sup>12+</sup>
6593e41f4b71Sopenharmony_ci
6594e41f4b71Sopenharmony_ciget(id: string, callback: AsyncCallback<image.PixelMap>, options?: componentSnapshot.SnapshotOptions): void
6595e41f4b71Sopenharmony_ci
6596e41f4b71Sopenharmony_ciObtains the snapshot of a component that has been loaded. This API uses an asynchronous callback to return the result.
6597e41f4b71Sopenharmony_ci
6598e41f4b71Sopenharmony_ci> **NOTE** 
6599e41f4b71Sopenharmony_ci>
6600e41f4b71Sopenharmony_ci> The snapshot captures content rendered in the last frame. If a snapshot is taken at the same time as the component triggers an update, the updated rendering content will not be captured in the snapshot; instead, the snapshot will return the rendering content from the previous frame.
6601e41f4b71Sopenharmony_ci
6602e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6603e41f4b71Sopenharmony_ci
6604e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6605e41f4b71Sopenharmony_ci
6606e41f4b71Sopenharmony_ci**Parameters**
6607e41f4b71Sopenharmony_ci
6608e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
6609e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6610e41f4b71Sopenharmony_ci| id       | string                                                       | Yes  | [ID](arkui-ts/ts-universal-attributes-component-id.md) of the target component. |
6611e41f4b71Sopenharmony_ci| callback | [AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)&lt;image.[PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)&gt; | Yes  | Callback used to return the result.                                        |
6612e41f4b71Sopenharmony_ci| options<sup>12+</sup>       | [SnapshotOptions](js-apis-arkui-componentSnapshot.md#snapshotoptions12)                              | No   | Custom settings of the snapshot. |
6613e41f4b71Sopenharmony_ci
6614e41f4b71Sopenharmony_ci**Example**
6615e41f4b71Sopenharmony_ci
6616e41f4b71Sopenharmony_ci```ts
6617e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
6618e41f4b71Sopenharmony_ciimport { UIContext } from '@kit.ArkUI';
6619e41f4b71Sopenharmony_ci
6620e41f4b71Sopenharmony_ci@Entry
6621e41f4b71Sopenharmony_ci@Component
6622e41f4b71Sopenharmony_cistruct SnapshotExample {
6623e41f4b71Sopenharmony_ci  @State pixmap: image.PixelMap | undefined = undefined
6624e41f4b71Sopenharmony_ci  uiContext: UIContext = this.getUIContext();
6625e41f4b71Sopenharmony_ci  build() {
6626e41f4b71Sopenharmony_ci    Column() {
6627e41f4b71Sopenharmony_ci      Row() {
6628e41f4b71Sopenharmony_ci        Image(this.pixmap).width(150).height(150).border({ color: Color.Black, width: 2 }).margin(5)
6629e41f4b71Sopenharmony_ci        Image($r('app.media.img')).autoResize(true).width(150).height(150).margin(5).id("root")
6630e41f4b71Sopenharmony_ci      }
6631e41f4b71Sopenharmony_ci      Button("click to generate UI snapshot")
6632e41f4b71Sopenharmony_ci        .onClick(() => {
6633e41f4b71Sopenharmony_ci          this.uiContext.getComponentSnapshot().get("root", (error: Error, pixmap: image.PixelMap) => {
6634e41f4b71Sopenharmony_ci            if (error) {
6635e41f4b71Sopenharmony_ci              console.error("error: " + JSON.stringify(error))
6636e41f4b71Sopenharmony_ci              return;
6637e41f4b71Sopenharmony_ci            }
6638e41f4b71Sopenharmony_ci            this.pixmap = pixmap
6639e41f4b71Sopenharmony_ci          }, {scale : 2, waitUntilRenderFinished : true})
6640e41f4b71Sopenharmony_ci        }).margin(10)
6641e41f4b71Sopenharmony_ci    }
6642e41f4b71Sopenharmony_ci    .width('100%')
6643e41f4b71Sopenharmony_ci    .height('100%')
6644e41f4b71Sopenharmony_ci    .alignItems(HorizontalAlign.Center)
6645e41f4b71Sopenharmony_ci  }
6646e41f4b71Sopenharmony_ci}
6647e41f4b71Sopenharmony_ci```
6648e41f4b71Sopenharmony_ci
6649e41f4b71Sopenharmony_ci### get<sup>12+</sup>
6650e41f4b71Sopenharmony_ci
6651e41f4b71Sopenharmony_ciget(id: string, options?: componentSnapshot.SnapshotOptions): Promise<image.PixelMap>
6652e41f4b71Sopenharmony_ci
6653e41f4b71Sopenharmony_ciObtains the snapshot of a component that has been loaded. This API uses a promise to return the result.
6654e41f4b71Sopenharmony_ci
6655e41f4b71Sopenharmony_ci> **NOTE**
6656e41f4b71Sopenharmony_ci>
6657e41f4b71Sopenharmony_ci> The snapshot captures content rendered in the last frame. If a snapshot is taken at the same time as the component triggers an update, the updated rendering content will not be captured in the snapshot; instead, the snapshot will return the rendering content from the previous frame.
6658e41f4b71Sopenharmony_ci
6659e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6660e41f4b71Sopenharmony_ci
6661e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6662e41f4b71Sopenharmony_ci
6663e41f4b71Sopenharmony_ci**Parameters**
6664e41f4b71Sopenharmony_ci
6665e41f4b71Sopenharmony_ci| Name | Type  | Mandatory | Description                                                        |
6666e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------------------------------------------------------ |
6667e41f4b71Sopenharmony_ci| id     | string | Yes  | [ID](arkui-ts/ts-universal-attributes-component-id.md) of the target component. |
6668e41f4b71Sopenharmony_ci| options<sup>12+</sup>       | [SnapshotOptions](js-apis-arkui-componentSnapshot.md#snapshotoptions12)                              | No   | Custom settings of the snapshot. |
6669e41f4b71Sopenharmony_ci
6670e41f4b71Sopenharmony_ci**Return value**
6671e41f4b71Sopenharmony_ci
6672e41f4b71Sopenharmony_ci| Type                                                        | Description            |
6673e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ---------------- |
6674e41f4b71Sopenharmony_ci| Promise&lt;image.[PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)&gt; | Promise used to return the result. |
6675e41f4b71Sopenharmony_ci
6676e41f4b71Sopenharmony_ci**Example**
6677e41f4b71Sopenharmony_ci
6678e41f4b71Sopenharmony_ci```ts
6679e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
6680e41f4b71Sopenharmony_ciimport { UIContext } from '@kit.ArkUI';
6681e41f4b71Sopenharmony_ci
6682e41f4b71Sopenharmony_ci@Entry
6683e41f4b71Sopenharmony_ci@Component
6684e41f4b71Sopenharmony_cistruct SnapshotExample {
6685e41f4b71Sopenharmony_ci  @State pixmap: image.PixelMap | undefined = undefined
6686e41f4b71Sopenharmony_ci  uiContext: UIContext = this.getUIContext();
6687e41f4b71Sopenharmony_ci
6688e41f4b71Sopenharmony_ci  build() {
6689e41f4b71Sopenharmony_ci    Column() {
6690e41f4b71Sopenharmony_ci      Row() {
6691e41f4b71Sopenharmony_ci        Image(this.pixmap).width(150).height(150).border({ color: Color.Black, width: 2 }).margin(5)
6692e41f4b71Sopenharmony_ci        Image($r('app.media.icon')).autoResize(true).width(150).height(150).margin(5).id("root")
6693e41f4b71Sopenharmony_ci      }
6694e41f4b71Sopenharmony_ci      Button("click to generate UI snapshot")
6695e41f4b71Sopenharmony_ci        .onClick(() => {
6696e41f4b71Sopenharmony_ci          this.uiContext.getComponentSnapshot()
6697e41f4b71Sopenharmony_ci            .get("root", {scale : 2, waitUntilRenderFinished : true})
6698e41f4b71Sopenharmony_ci            .then((pixmap: image.PixelMap) => {
6699e41f4b71Sopenharmony_ci              this.pixmap = pixmap
6700e41f4b71Sopenharmony_ci            })
6701e41f4b71Sopenharmony_ci            .catch((err: Error) => {
6702e41f4b71Sopenharmony_ci              console.error("error: " + err)
6703e41f4b71Sopenharmony_ci            })
6704e41f4b71Sopenharmony_ci        }).margin(10)
6705e41f4b71Sopenharmony_ci    }
6706e41f4b71Sopenharmony_ci    .width('100%')
6707e41f4b71Sopenharmony_ci    .height('100%')
6708e41f4b71Sopenharmony_ci    .alignItems(HorizontalAlign.Center)
6709e41f4b71Sopenharmony_ci  }
6710e41f4b71Sopenharmony_ci}
6711e41f4b71Sopenharmony_ci```
6712e41f4b71Sopenharmony_ci
6713e41f4b71Sopenharmony_ci### createFromBuilder<sup>12+</sup>
6714e41f4b71Sopenharmony_ci
6715e41f4b71Sopenharmony_cicreateFromBuilder(builder: CustomBuilder, callback: AsyncCallback<image.PixelMap>, delay?: number, checkImageStatus?: boolean, options?: componentSnapshot.SnapshotOptions): void
6716e41f4b71Sopenharmony_ci
6717e41f4b71Sopenharmony_ciRenders a custom component from [CustomBuilder](arkui-ts/ts-types.md#custombuilder8) in the background of the application and outputs its snapshot. This API uses an asynchronous callback to return the result.
6718e41f4b71Sopenharmony_ci> **NOTE** 
6719e41f4b71Sopenharmony_ci>
6720e41f4b71Sopenharmony_ci> Due to the need to wait for the component to be built and rendered, there is a delay of up to 500 ms in the callback for offscreen snapshot capturing.
6721e41f4b71Sopenharmony_ci>
6722e41f4b71Sopenharmony_ci> If a component is on a time-consuming task, for example, an [Image](arkui-ts/ts-basic-components-image.md) or [Web](../apis-arkweb/ts-basic-components-web.md) component that is loading online images, its loading may be still in progress when this API is called. In this case, the output snapshot does not represent the component in the way it looks when the loading is successfully completed.
6723e41f4b71Sopenharmony_ci
6724e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6725e41f4b71Sopenharmony_ci
6726e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6727e41f4b71Sopenharmony_ci
6728e41f4b71Sopenharmony_ci**Parameters**
6729e41f4b71Sopenharmony_ci
6730e41f4b71Sopenharmony_ci| Name  | Type                                                        | Mandatory | Description                                                        |
6731e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6732e41f4b71Sopenharmony_ci| builder  | [CustomBuilder](arkui-ts/ts-types.md#custombuilder8)         | Yes  | Builder for the custom component.<br>**NOTE**<br>The global builder is not supported.     |
6733e41f4b71Sopenharmony_ci| callback | [AsyncCallback](../apis-basic-services-kit/js-apis-base.md#asynccallback)&lt;image.[PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)&gt; | Yes  | Callback used to return the result. The coordinates and size of the offscreen component's drawing area can be obtained through the callback. |
6734e41f4b71Sopenharmony_ci| delay<sup>12+</sup>   | number | No   | Delay time for triggering the screenshot command. When the layout includes an **Image** component, it is necessary to set a delay time to allow the system to decode the image resources. The decoding time is subject to the resource size. In light of this, whenever possible, use pixel map resources that do not require decoding.<br> When pixel map resources are used or when **syncload** to **true** for the **Image** component, you can set **delay** to **0** to forcibly capture snapshots without waiting. This delay time does not refer to the time from the API call to the return: As the system needs to temporarily construct the passed-in **builder** offscreen, the return time is usually longer than this delay.<br>**NOTE**<br>In the **builder** passed in, state variables should not be used to control the construction of child components. If they are used, they should not change when the API is called, so as to avoid unexpected snapshot results.<br> Default value: **300**<br> Unit: ms|
6735e41f4b71Sopenharmony_ci| checkImageStatus<sup>12+</sup>  | boolean | No   | Whether to check the image decoding status before taking a snapshot. If the value is **true**, the system checks whether all **Image** components have been decoded before taking the snapshot. If the check is not completed, the system aborts the snapshot and returns an exception.<br>Default value: **false**|
6736e41f4b71Sopenharmony_ci| options<sup>12+</sup>       | [SnapshotOptions](js-apis-arkui-componentSnapshot.md#snapshotoptions12)           | No   | Custom settings of the snapshot. |
6737e41f4b71Sopenharmony_ci
6738e41f4b71Sopenharmony_ci**Example**
6739e41f4b71Sopenharmony_ci
6740e41f4b71Sopenharmony_ci```ts
6741e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
6742e41f4b71Sopenharmony_ciimport { UIContext } from '@kit.ArkUI';
6743e41f4b71Sopenharmony_ci
6744e41f4b71Sopenharmony_ci@Entry
6745e41f4b71Sopenharmony_ci@Component
6746e41f4b71Sopenharmony_cistruct ComponentSnapshotExample {
6747e41f4b71Sopenharmony_ci  @State pixmap: image.PixelMap | undefined = undefined
6748e41f4b71Sopenharmony_ci  uiContext: UIContext = this.getUIContext();
6749e41f4b71Sopenharmony_ci  @Builder
6750e41f4b71Sopenharmony_ci  RandomBuilder() {
6751e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
6752e41f4b71Sopenharmony_ci      Text('Test menu item 1')
6753e41f4b71Sopenharmony_ci        .fontSize(20)
6754e41f4b71Sopenharmony_ci        .width(100)
6755e41f4b71Sopenharmony_ci        .height(50)
6756e41f4b71Sopenharmony_ci        .textAlign(TextAlign.Center)
6757e41f4b71Sopenharmony_ci      Divider().height(10)
6758e41f4b71Sopenharmony_ci      Text('Test menu item 2')
6759e41f4b71Sopenharmony_ci        .fontSize(20)
6760e41f4b71Sopenharmony_ci        .width(100)
6761e41f4b71Sopenharmony_ci        .height(50)
6762e41f4b71Sopenharmony_ci        .textAlign(TextAlign.Center)
6763e41f4b71Sopenharmony_ci    }
6764e41f4b71Sopenharmony_ci    .width(100)
6765e41f4b71Sopenharmony_ci    .id("builder")
6766e41f4b71Sopenharmony_ci  }
6767e41f4b71Sopenharmony_ci
6768e41f4b71Sopenharmony_ci  build() {
6769e41f4b71Sopenharmony_ci    Column() {
6770e41f4b71Sopenharmony_ci      Button("click to generate UI snapshot")
6771e41f4b71Sopenharmony_ci        .onClick(() => {
6772e41f4b71Sopenharmony_ci          this.uiContext.getComponentSnapshot().createFromBuilder(() => {
6773e41f4b71Sopenharmony_ci            this.RandomBuilder()
6774e41f4b71Sopenharmony_ci          },
6775e41f4b71Sopenharmony_ci            (error: Error, pixmap: image.PixelMap) => {
6776e41f4b71Sopenharmony_ci              if (error) {
6777e41f4b71Sopenharmony_ci                console.error("error: " + JSON.stringify(error))
6778e41f4b71Sopenharmony_ci                return;
6779e41f4b71Sopenharmony_ci              }
6780e41f4b71Sopenharmony_ci              this.pixmap = pixmap
6781e41f4b71Sopenharmony_ci            }, 320, true, {scale : 2, waitUntilRenderFinished : true})
6782e41f4b71Sopenharmony_ci        })
6783e41f4b71Sopenharmony_ci      Image(this.pixmap)
6784e41f4b71Sopenharmony_ci        .margin(10)
6785e41f4b71Sopenharmony_ci        .height(200)
6786e41f4b71Sopenharmony_ci        .width(200)
6787e41f4b71Sopenharmony_ci        .border({ color: Color.Black, width: 2 })
6788e41f4b71Sopenharmony_ci    }.width('100%').margin({ left: 10, top: 5, bottom: 5 }).height(300)
6789e41f4b71Sopenharmony_ci  }
6790e41f4b71Sopenharmony_ci}
6791e41f4b71Sopenharmony_ci```
6792e41f4b71Sopenharmony_ci
6793e41f4b71Sopenharmony_ci### createFromBuilder<sup>12+</sup>
6794e41f4b71Sopenharmony_ci
6795e41f4b71Sopenharmony_cicreateFromBuilder(builder: CustomBuilder, delay?: number, checkImageStatus?: boolean, options?: componentSnapshot.SnapshotOptions): Promise<image.PixelMap>
6796e41f4b71Sopenharmony_ci
6797e41f4b71Sopenharmony_ciRenders a custom component from [CustomBuilder](arkui-ts/ts-types.md#custombuilder8) in the background of the application and outputs its snapshot. This API uses a promise to return the result.
6798e41f4b71Sopenharmony_ci
6799e41f4b71Sopenharmony_ci> **NOTE** 
6800e41f4b71Sopenharmony_ci>
6801e41f4b71Sopenharmony_ci> Due to the need to wait for the component to be built and rendered, there is a delay of up to 500 ms in the callback for offscreen snapshot capturing.
6802e41f4b71Sopenharmony_ci>
6803e41f4b71Sopenharmony_ci> If a component is on a time-consuming task, for example, an [Image](arkui-ts/ts-basic-components-image.md) or [Web](../apis-arkweb/ts-basic-components-web.md) component that is loading online images, its loading may be still in progress when this API is called. In this case, the output snapshot does not represent the component in the way it looks when the loading is successfully completed.
6804e41f4b71Sopenharmony_ci
6805e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6806e41f4b71Sopenharmony_ci
6807e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6808e41f4b71Sopenharmony_ci
6809e41f4b71Sopenharmony_ci**Parameters**
6810e41f4b71Sopenharmony_ci
6811e41f4b71Sopenharmony_ci| Name | Type                                                | Mandatory | Description                                                   |
6812e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------- | ---- | ------------------------------------------------------- |
6813e41f4b71Sopenharmony_ci| builder | [CustomBuilder](arkui-ts/ts-types.md#custombuilder8) | Yes  | Builder for the custom component.<br>**NOTE**<br>The global builder is not supported. |
6814e41f4b71Sopenharmony_ci
6815e41f4b71Sopenharmony_ci**Return value**
6816e41f4b71Sopenharmony_ci
6817e41f4b71Sopenharmony_ci| Type                                                        | Description            |
6818e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ---------------- |
6819e41f4b71Sopenharmony_ci| Promise&lt;image.[PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)&gt; | Promise used to return the result. |
6820e41f4b71Sopenharmony_ci| delay<sup>12+</sup>   | number | No   | Delay time for triggering the screenshot command. When the layout includes an image component, it is necessary to set a delay time to allow the system to decode the image resources. The decoding time is subject to the resource size. In light of this, whenever possible, use pixel map resources that do not require decoding.<br> When pixel map resources are used or when **syncload** to **true** for the **Image** component, you can set **delay** to **0** to forcibly capture snapshots without waiting. This delay time does not refer to the time from the API call to the return: As the system needs to temporarily construct the passed-in **builder** offscreen, the return time is usually longer than this delay.<br>**NOTE**<br>In the **builder** passed in, state variables should not be used to control the construction of child components. If they are used, they should not change when the API is called, so as to avoid unexpected snapshot results.<br> Default value: **300**<br> Unit: ms|
6821e41f4b71Sopenharmony_ci| checkImageStatus<sup>12+</sup>  | boolean | No   | Whether to check the image decoding status before taking a snapshot. If the value is **true**, the system checks whether all **Image** components have been decoded before taking the snapshot. If the check is not completed, the system aborts the snapshot and returns an exception.<br>Default value: **false**|
6822e41f4b71Sopenharmony_ci| options<sup>12+</sup>       | [SnapshotOptions](js-apis-arkui-componentSnapshot.md#snapshotoptions12)           | No   | Custom settings of the snapshot. |
6823e41f4b71Sopenharmony_ci
6824e41f4b71Sopenharmony_ci**Example**
6825e41f4b71Sopenharmony_ci
6826e41f4b71Sopenharmony_ci```ts
6827e41f4b71Sopenharmony_ciimport { image } from '@kit.ImageKit';
6828e41f4b71Sopenharmony_ciimport { UIContext } from '@kit.ArkUI';
6829e41f4b71Sopenharmony_ci
6830e41f4b71Sopenharmony_ci@Entry
6831e41f4b71Sopenharmony_ci@Component
6832e41f4b71Sopenharmony_cistruct ComponentSnapshotExample {
6833e41f4b71Sopenharmony_ci  @State pixmap: image.PixelMap | undefined = undefined
6834e41f4b71Sopenharmony_ci  uiContext: UIContext = this.getUIContext();
6835e41f4b71Sopenharmony_ci  @Builder
6836e41f4b71Sopenharmony_ci  RandomBuilder() {
6837e41f4b71Sopenharmony_ci    Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) {
6838e41f4b71Sopenharmony_ci      Text('Test menu item 1')
6839e41f4b71Sopenharmony_ci        .fontSize(20)
6840e41f4b71Sopenharmony_ci        .width(100)
6841e41f4b71Sopenharmony_ci        .height(50)
6842e41f4b71Sopenharmony_ci        .textAlign(TextAlign.Center)
6843e41f4b71Sopenharmony_ci      Divider().height(10)
6844e41f4b71Sopenharmony_ci      Text('Test menu item 2')
6845e41f4b71Sopenharmony_ci        .fontSize(20)
6846e41f4b71Sopenharmony_ci        .width(100)
6847e41f4b71Sopenharmony_ci        .height(50)
6848e41f4b71Sopenharmony_ci        .textAlign(TextAlign.Center)
6849e41f4b71Sopenharmony_ci    }
6850e41f4b71Sopenharmony_ci    .width(100)
6851e41f4b71Sopenharmony_ci    .id("builder")
6852e41f4b71Sopenharmony_ci  }
6853e41f4b71Sopenharmony_ci  build() {
6854e41f4b71Sopenharmony_ci    Column() {
6855e41f4b71Sopenharmony_ci      Button("click to generate UI snapshot")
6856e41f4b71Sopenharmony_ci        .onClick(() => {
6857e41f4b71Sopenharmony_ci          this.uiContext.getComponentSnapshot()
6858e41f4b71Sopenharmony_ci            .createFromBuilder(() => {
6859e41f4b71Sopenharmony_ci              this.RandomBuilder()
6860e41f4b71Sopenharmony_ci            }, 320, true, {scale : 2, waitUntilRenderFinished : true})
6861e41f4b71Sopenharmony_ci            .then((pixmap: image.PixelMap) => {
6862e41f4b71Sopenharmony_ci              this.pixmap = pixmap
6863e41f4b71Sopenharmony_ci            })
6864e41f4b71Sopenharmony_ci            .catch((err: Error) => {
6865e41f4b71Sopenharmony_ci              console.error("error: " + err)
6866e41f4b71Sopenharmony_ci            })
6867e41f4b71Sopenharmony_ci        })
6868e41f4b71Sopenharmony_ci      Image(this.pixmap)
6869e41f4b71Sopenharmony_ci        .margin(10)
6870e41f4b71Sopenharmony_ci        .height(200)
6871e41f4b71Sopenharmony_ci        .width(200)
6872e41f4b71Sopenharmony_ci        .border({ color: Color.Black, width: 2 })
6873e41f4b71Sopenharmony_ci    }.width('100%').margin({ left: 10, top: 5, bottom: 5 }).height(300)
6874e41f4b71Sopenharmony_ci  }
6875e41f4b71Sopenharmony_ci}
6876e41f4b71Sopenharmony_ci```
6877e41f4b71Sopenharmony_ci
6878e41f4b71Sopenharmony_ci## FrameCallback<sup>12+</sup>
6879e41f4b71Sopenharmony_ci
6880e41f4b71Sopenharmony_ciImplements the API for setting the task that needs to be executed during the next frame rendering. It must be used together with [postFrameCallback](#postframecallback12) and [postDelayedFrameCallback](#postdelayedframecallback12) in [UIContext](#uicontext). Inherit this class and override the [onFrame](#onframe12) method to implement specific service logic.
6881e41f4b71Sopenharmony_ci
6882e41f4b71Sopenharmony_ci### onFrame<sup>12+</sup>
6883e41f4b71Sopenharmony_ci
6884e41f4b71Sopenharmony_ciCalled when the next frame is rendered.
6885e41f4b71Sopenharmony_ci
6886e41f4b71Sopenharmony_cionFrame(frameTimeInNano: number): void
6887e41f4b71Sopenharmony_ci
6888e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6889e41f4b71Sopenharmony_ci
6890e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6891e41f4b71Sopenharmony_ci
6892e41f4b71Sopenharmony_ci**Parameters**
6893e41f4b71Sopenharmony_ci
6894e41f4b71Sopenharmony_ci| Name | Type                                                | Mandatory | Description                                                   |
6895e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------------- | ---- | ------------------------------------------------------- |
6896e41f4b71Sopenharmony_ci| frameTimeInNano | number | Yes  | Time when the rendering of the next frame starts, in nanoseconds. |
6897e41f4b71Sopenharmony_ci
6898e41f4b71Sopenharmony_ci**Example**
6899e41f4b71Sopenharmony_ci
6900e41f4b71Sopenharmony_ci```ts
6901e41f4b71Sopenharmony_ciimport {FrameCallback } from '@kit.ArkUI';
6902e41f4b71Sopenharmony_ci
6903e41f4b71Sopenharmony_ciclass MyFrameCallback extends FrameCallback {
6904e41f4b71Sopenharmony_ci  private tag: string;
6905e41f4b71Sopenharmony_ci
6906e41f4b71Sopenharmony_ci  constructor(tag: string) {
6907e41f4b71Sopenharmony_ci    super()
6908e41f4b71Sopenharmony_ci    this.tag = tag;
6909e41f4b71Sopenharmony_ci  }
6910e41f4b71Sopenharmony_ci
6911e41f4b71Sopenharmony_ci  onFrame(frameTimeNanos: number) {
6912e41f4b71Sopenharmony_ci    console.info('MyFrameCallback ' + this.tag + ' ' + frameTimeNanos.toString());
6913e41f4b71Sopenharmony_ci  }
6914e41f4b71Sopenharmony_ci}
6915e41f4b71Sopenharmony_ci
6916e41f4b71Sopenharmony_ci@Entry
6917e41f4b71Sopenharmony_ci@Component
6918e41f4b71Sopenharmony_cistruct Index {
6919e41f4b71Sopenharmony_ci  build() {
6920e41f4b71Sopenharmony_ci    Row() {
6921e41f4b71Sopenharmony_ci      Column() {
6922e41f4b71Sopenharmony_ci        Button('Invoke postFrameCallback')
6923e41f4b71Sopenharmony_ci          .onClick(() => {
6924e41f4b71Sopenharmony_ci            this.getUIContext().postFrameCallback(new MyFrameCallback("normTask"));
6925e41f4b71Sopenharmony_ci          })
6926e41f4b71Sopenharmony_ci        Button('Invoke postDelayedFrameCallback')
6927e41f4b71Sopenharmony_ci          .onClick(() => {
6928e41f4b71Sopenharmony_ci            this.getUIContext().postDelayedFrameCallback(new MyFrameCallback("delayTask"), 5);
6929e41f4b71Sopenharmony_ci          })
6930e41f4b71Sopenharmony_ci      }
6931e41f4b71Sopenharmony_ci      .width('100%')
6932e41f4b71Sopenharmony_ci    }
6933e41f4b71Sopenharmony_ci    .height('100%')
6934e41f4b71Sopenharmony_ci  }
6935e41f4b71Sopenharmony_ci}
6936e41f4b71Sopenharmony_ci```
6937e41f4b71Sopenharmony_ci
6938e41f4b71Sopenharmony_ci## DynamicSyncScene<sup>12+</sup>
6939e41f4b71Sopenharmony_ci
6940e41f4b71Sopenharmony_ciIn the following API examples, you must first use **requireDynamicSyncScene()** in **UIContext** to obtain a **DynamicSyncScene** instance, and then call the APIs using the obtained instance.
6941e41f4b71Sopenharmony_ci
6942e41f4b71Sopenharmony_ci### setFrameRateRange<sup>12+</sup>
6943e41f4b71Sopenharmony_ci
6944e41f4b71Sopenharmony_cisetFrameRateRange(range: ExpectedFrameRateRange): void
6945e41f4b71Sopenharmony_ci
6946e41f4b71Sopenharmony_ciSets the expected frame rate range.
6947e41f4b71Sopenharmony_ci
6948e41f4b71Sopenharmony_ciThe final result may not necessarily be the set frame rate range, as the system will make a comprehensive decision based on its capabilities, striving to meet what you have set.
6949e41f4b71Sopenharmony_ci
6950e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
6951e41f4b71Sopenharmony_ci
6952e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
6953e41f4b71Sopenharmony_ci
6954e41f4b71Sopenharmony_ci**Parameters**
6955e41f4b71Sopenharmony_ci
6956e41f4b71Sopenharmony_ci| Name     | Type        | Mandatory  | Description  |
6957e41f4b71Sopenharmony_ci| -------- | ---------- | ---- | ---- |
6958e41f4b71Sopenharmony_ci| range | [ExpectedFrameRateRange](../apis-arkui/arkui-ts/ts-explicit-animation.md#expectedframeraterange11)| Yes   | Expected frame rate range.<br>Default value: **{min:0, max:120, expected: 120}** |
6959e41f4b71Sopenharmony_ci
6960e41f4b71Sopenharmony_ci**Example**
6961e41f4b71Sopenharmony_ci
6962e41f4b71Sopenharmony_ci```ts
6963e41f4b71Sopenharmony_ciimport { SwiperDynamicSyncSceneType, SwiperDynamicSyncScene } from '@kit.ArkUI'
6964e41f4b71Sopenharmony_ci
6965e41f4b71Sopenharmony_ci@Entry
6966e41f4b71Sopenharmony_ci@Component
6967e41f4b71Sopenharmony_cistruct Frame {
6968e41f4b71Sopenharmony_ci  @State ANIMATION:ExpectedFrameRateRange = {min:0, max:120, expected: 90}
6969e41f4b71Sopenharmony_ci  @State GESTURE:ExpectedFrameRateRange = {min:0, max:120, expected: 30}
6970e41f4b71Sopenharmony_ci  private scenes: SwiperDynamicSyncScene[] = []
6971e41f4b71Sopenharmony_ci
6972e41f4b71Sopenharmony_ci  build() {
6973e41f4b71Sopenharmony_ci    Column() {
6974e41f4b71Sopenharmony_ci      Text("Animation"+ JSON.stringify(this.ANIMATION))
6975e41f4b71Sopenharmony_ci      Text("Responsive"+ JSON.stringify(this.GESTURE))
6976e41f4b71Sopenharmony_ci      Row(){
6977e41f4b71Sopenharmony_ci        Swiper() {
6978e41f4b71Sopenharmony_ci          Text("one")
6979e41f4b71Sopenharmony_ci          Text("two")
6980e41f4b71Sopenharmony_ci          Text("three")
6981e41f4b71Sopenharmony_ci        }
6982e41f4b71Sopenharmony_ci        .width('100%')
6983e41f4b71Sopenharmony_ci        .height('300vp')
6984e41f4b71Sopenharmony_ci        .id("dynamicSwiper")
6985e41f4b71Sopenharmony_ci        .backgroundColor(Color.Blue)
6986e41f4b71Sopenharmony_ci        .autoPlay(true)
6987e41f4b71Sopenharmony_ci        .onAppear(()=>{
6988e41f4b71Sopenharmony_ci          this.scenes = this.getUIContext().requireDynamicSyncScene("dynamicSwiper") as SwiperDynamicSyncScene[]
6989e41f4b71Sopenharmony_ci        })
6990e41f4b71Sopenharmony_ci      }
6991e41f4b71Sopenharmony_ci
6992e41f4b71Sopenharmony_ci      Button("set frame")
6993e41f4b71Sopenharmony_ci        .onClick(()=>{
6994e41f4b71Sopenharmony_ci          this.scenes.forEach((scenes: SwiperDynamicSyncScene) => {
6995e41f4b71Sopenharmony_ci
6996e41f4b71Sopenharmony_ci            if (scenes.type == SwiperDynamicSyncSceneType.ANIMATION) {
6997e41f4b71Sopenharmony_ci              scenes.setFrameRateRange(this.ANIMATION)
6998e41f4b71Sopenharmony_ci            }
6999e41f4b71Sopenharmony_ci
7000e41f4b71Sopenharmony_ci            if (scenes.type == SwiperDynamicSyncSceneType.GESTURE) {
7001e41f4b71Sopenharmony_ci              scenes.setFrameRateRange(this.GESTURE)
7002e41f4b71Sopenharmony_ci            }
7003e41f4b71Sopenharmony_ci          });
7004e41f4b71Sopenharmony_ci        })
7005e41f4b71Sopenharmony_ci    }
7006e41f4b71Sopenharmony_ci  }
7007e41f4b71Sopenharmony_ci}
7008e41f4b71Sopenharmony_ci```
7009e41f4b71Sopenharmony_ci
7010e41f4b71Sopenharmony_ci### getFrameRateRange<sup>12+</sup>
7011e41f4b71Sopenharmony_ci
7012e41f4b71Sopenharmony_cigetFrameRateRange(): ExpectedFrameRateRange
7013e41f4b71Sopenharmony_ci
7014e41f4b71Sopenharmony_ciObtains the expected frame rate range.
7015e41f4b71Sopenharmony_ci
7016e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7017e41f4b71Sopenharmony_ci
7018e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
7019e41f4b71Sopenharmony_ci
7020e41f4b71Sopenharmony_ci**Return value**
7021e41f4b71Sopenharmony_ci
7022e41f4b71Sopenharmony_ci| Type                 | Description     |
7023e41f4b71Sopenharmony_ci| ------------------- | ------- |
7024e41f4b71Sopenharmony_ci| [ExpectedFrameRateRange](../apis-arkui/arkui-ts/ts-explicit-animation.md#expectedframeraterange11) | Expected frame rate range.|
7025e41f4b71Sopenharmony_ci
7026e41f4b71Sopenharmony_ci**Example**
7027e41f4b71Sopenharmony_ci
7028e41f4b71Sopenharmony_ci```ts
7029e41f4b71Sopenharmony_ciimport { SwiperDynamicSyncSceneType, SwiperDynamicSyncScene } from '@kit.ArkUI'
7030e41f4b71Sopenharmony_ci
7031e41f4b71Sopenharmony_ci@Entry
7032e41f4b71Sopenharmony_ci@Component
7033e41f4b71Sopenharmony_cistruct Frame {
7034e41f4b71Sopenharmony_ci  @State ANIMATION:ExpectedFrameRateRange = {min:0, max:120, expected: 90}
7035e41f4b71Sopenharmony_ci  @State GESTURE:ExpectedFrameRateRange = {min:0, max:120, expected: 30}
7036e41f4b71Sopenharmony_ci  private scenes: SwiperDynamicSyncScene[] = []
7037e41f4b71Sopenharmony_ci
7038e41f4b71Sopenharmony_ci  build() {
7039e41f4b71Sopenharmony_ci    Column() {
7040e41f4b71Sopenharmony_ci      Text("Animation"+ JSON.stringify(this.ANIMATION))
7041e41f4b71Sopenharmony_ci      Text("Responsive"+ JSON.stringify(this.GESTURE))
7042e41f4b71Sopenharmony_ci      Row(){
7043e41f4b71Sopenharmony_ci        Swiper() {
7044e41f4b71Sopenharmony_ci          Text("one")
7045e41f4b71Sopenharmony_ci          Text("two")
7046e41f4b71Sopenharmony_ci          Text("three")
7047e41f4b71Sopenharmony_ci        }
7048e41f4b71Sopenharmony_ci        .width('100%')
7049e41f4b71Sopenharmony_ci        .height('300vp')
7050e41f4b71Sopenharmony_ci        .id("dynamicSwiper")
7051e41f4b71Sopenharmony_ci        .backgroundColor(Color.Blue)
7052e41f4b71Sopenharmony_ci        .autoPlay(true)
7053e41f4b71Sopenharmony_ci        .onAppear(()=>{
7054e41f4b71Sopenharmony_ci          this.scenes = this.getUIContext().requireDynamicSyncScene("dynamicSwiper") as SwiperDynamicSyncScene[]
7055e41f4b71Sopenharmony_ci        })
7056e41f4b71Sopenharmony_ci      }
7057e41f4b71Sopenharmony_ci
7058e41f4b71Sopenharmony_ci      Button("set frame")
7059e41f4b71Sopenharmony_ci        .onClick(()=>{
7060e41f4b71Sopenharmony_ci          this.scenes.forEach((scenes: SwiperDynamicSyncScene) => {
7061e41f4b71Sopenharmony_ci
7062e41f4b71Sopenharmony_ci            if (scenes.type == SwiperDynamicSyncSceneType.ANIMATION) {
7063e41f4b71Sopenharmony_ci              scenes.setFrameRateRange(this.ANIMATION)
7064e41f4b71Sopenharmony_ci              scenes.getFrameRateRange()
7065e41f4b71Sopenharmony_ci            }
7066e41f4b71Sopenharmony_ci
7067e41f4b71Sopenharmony_ci            if (scenes.type == SwiperDynamicSyncSceneType.GESTURE) {
7068e41f4b71Sopenharmony_ci              scenes.setFrameRateRange(this.GESTURE)
7069e41f4b71Sopenharmony_ci              scenes.getFrameRateRange()
7070e41f4b71Sopenharmony_ci            }
7071e41f4b71Sopenharmony_ci          });
7072e41f4b71Sopenharmony_ci        })
7073e41f4b71Sopenharmony_ci      }
7074e41f4b71Sopenharmony_ci  }
7075e41f4b71Sopenharmony_ci}
7076e41f4b71Sopenharmony_ci```
7077e41f4b71Sopenharmony_ci## SwiperDynamicSyncScene<sup>12+</sup>
7078e41f4b71Sopenharmony_ci
7079e41f4b71Sopenharmony_ciInherits [DynamicSyncScene](#dynamicsyncscene12) and represents the dynamic sync scene of the **Swiper** component.
7080e41f4b71Sopenharmony_ci
7081e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7082e41f4b71Sopenharmony_ci
7083e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
7084e41f4b71Sopenharmony_ci
7085e41f4b71Sopenharmony_ci| Name      | Type                                                     | Read Only | Optional | Description                               |
7086e41f4b71Sopenharmony_ci| --------- | --------------------------------------------------------- | ---- | ---- | ---------------------------------- |
7087e41f4b71Sopenharmony_ci| type      | [SwiperDynamicSyncSceneType](#swiperdynamicsyncscenetype12) | Yes  | No  | Dynamic sync scene of the **Swiper** component.            |
7088e41f4b71Sopenharmony_ci
7089e41f4b71Sopenharmony_ci## SwiperDynamicSyncSceneType<sup>12+</sup>
7090e41f4b71Sopenharmony_ci
7091e41f4b71Sopenharmony_ciEnumerates the dynamic sync scene types.
7092e41f4b71Sopenharmony_ci
7093e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
7094e41f4b71Sopenharmony_ci
7095e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
7096e41f4b71Sopenharmony_ci
7097e41f4b71Sopenharmony_ci| Name    | Value  | Description                  |
7098e41f4b71Sopenharmony_ci| -------- | ---- | ---------------------- |
7099e41f4b71Sopenharmony_ci| GESTURE | 0   | Gesture operation. |
7100e41f4b71Sopenharmony_ci| ANIMATION | 1   | Animation transition. |
7101