1e41f4b71Sopenharmony_ci# Custom Dialog Box (CustomDialog)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciA custom dialog box is a dialog box you customize by using APIs of the **CustomDialogController** class. It can be used for user interactions, showing an ad, prize, alert, software update message, and more. For details, see [Custom Dialog Box](../reference/apis-arkui/arkui-ts/ts-methods-custom-dialog-box.md).
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci## Creating a Custom Dialog Box
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci1. Use the \@CustomDialog decorator to create a custom dialog box.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci2. Set the content for the \@CustomDialog decorated dialog box.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci   ```ts
14e41f4b71Sopenharmony_ci   @CustomDialog
15e41f4b71Sopenharmony_ci   struct CustomDialogExample {
16e41f4b71Sopenharmony_ci     controller: CustomDialogController = new CustomDialogController({
17e41f4b71Sopenharmony_ci       builder: CustomDialogExample({}),
18e41f4b71Sopenharmony_ci     })
19e41f4b71Sopenharmony_ci   
20e41f4b71Sopenharmony_ci     build() {
21e41f4b71Sopenharmony_ci       Column() {
22e41f4b71Sopenharmony_ci         Text ('I am content')
23e41f4b71Sopenharmony_ci           .fontSize(20)
24e41f4b71Sopenharmony_ci           .margin({ top: 10, bottom: 10 })
25e41f4b71Sopenharmony_ci       }
26e41f4b71Sopenharmony_ci     }
27e41f4b71Sopenharmony_ci   }
28e41f4b71Sopenharmony_ci   ```
29e41f4b71Sopenharmony_ci   
30e41f4b71Sopenharmony_ci3. Create a builder that is bound to the decorator.
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci   ```ts
33e41f4b71Sopenharmony_ci    @Entry
34e41f4b71Sopenharmony_ci    @Component
35e41f4b71Sopenharmony_ci    struct CustomDialogUser {
36e41f4b71Sopenharmony_ci      dialogController: CustomDialogController = new CustomDialogController({
37e41f4b71Sopenharmony_ci        builder: CustomDialogExample(),
38e41f4b71Sopenharmony_ci      })
39e41f4b71Sopenharmony_ci    }
40e41f4b71Sopenharmony_ci   ```
41e41f4b71Sopenharmony_ci   
42e41f4b71Sopenharmony_ci4. Click the component bound to the **onClick** event to display the dialog box.
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci   ```ts
45e41f4b71Sopenharmony_ci   @Entry
46e41f4b71Sopenharmony_ci   @Component
47e41f4b71Sopenharmony_ci   struct CustomDialogUser {
48e41f4b71Sopenharmony_ci     dialogController: CustomDialogController = new CustomDialogController({
49e41f4b71Sopenharmony_ci       builder: CustomDialogExample(),
50e41f4b71Sopenharmony_ci     })
51e41f4b71Sopenharmony_ci   
52e41f4b71Sopenharmony_ci     build() {
53e41f4b71Sopenharmony_ci       Column() {
54e41f4b71Sopenharmony_ci         Button('click me')
55e41f4b71Sopenharmony_ci           .onClick(() => {
56e41f4b71Sopenharmony_ci             this.dialogController.open()
57e41f4b71Sopenharmony_ci           })
58e41f4b71Sopenharmony_ci       }.width('100%').margin({ top: 5 })
59e41f4b71Sopenharmony_ci     }
60e41f4b71Sopenharmony_ci   }
61e41f4b71Sopenharmony_ci   ```
62e41f4b71Sopenharmony_ci   
63e41f4b71Sopenharmony_ci   ![en-us_image_0000001562700493](figures/en-us_image_0000001562700493.png)
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci## Interaction with Custom Dialog Box
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ciCustom dialog boxes can be used for data interactions to complete a series of response operations.
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci1. Add buttons in the \@CustomDialog decorator structure and add data functions.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci   ```ts
74e41f4b71Sopenharmony_ci   @CustomDialog
75e41f4b71Sopenharmony_ci   struct CustomDialogExample {
76e41f4b71Sopenharmony_ci     cancel?: () => void
77e41f4b71Sopenharmony_ci     confirm?: () => void
78e41f4b71Sopenharmony_ci     controller: CustomDialogController
79e41f4b71Sopenharmony_ci   
80e41f4b71Sopenharmony_ci     build() {
81e41f4b71Sopenharmony_ci       Column() {
82e41f4b71Sopenharmony_ci         Text('I am content') .fontSize(20).margin({ top: 10, bottom: 10 })
83e41f4b71Sopenharmony_ci         Flex({ justifyContent: FlexAlign.SpaceAround }) {
84e41f4b71Sopenharmony_ci           Button('cancel')
85e41f4b71Sopenharmony_ci             .onClick(() => {
86e41f4b71Sopenharmony_ci               this.controller.close()
87e41f4b71Sopenharmony_ci               if (this.cancel) {
88e41f4b71Sopenharmony_ci                 this.cancel()
89e41f4b71Sopenharmony_ci               }
90e41f4b71Sopenharmony_ci             }).backgroundColor(0xffffff).fontColor(Color.Black)
91e41f4b71Sopenharmony_ci           Button('confirm')
92e41f4b71Sopenharmony_ci             .onClick(() => {
93e41f4b71Sopenharmony_ci               this.controller.close()
94e41f4b71Sopenharmony_ci               if (this.confirm) {
95e41f4b71Sopenharmony_ci                 this.confirm()
96e41f4b71Sopenharmony_ci               }
97e41f4b71Sopenharmony_ci             }).backgroundColor(0xffffff).fontColor(Color.Red)
98e41f4b71Sopenharmony_ci         }.margin({ bottom: 10 })
99e41f4b71Sopenharmony_ci       }
100e41f4b71Sopenharmony_ci     }
101e41f4b71Sopenharmony_ci   }
102e41f4b71Sopenharmony_ci   ```
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci2. Receive the page in the builder and create corresponding function operations.
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci     ```ts
107e41f4b71Sopenharmony_ci   @Entry
108e41f4b71Sopenharmony_ci   @Component
109e41f4b71Sopenharmony_ci   struct CustomDialogUser {
110e41f4b71Sopenharmony_ci       dialogController: CustomDialogController = new CustomDialogController({
111e41f4b71Sopenharmony_ci         builder: CustomDialogExample({
112e41f4b71Sopenharmony_ci           cancel: ()=> { this.onCancel() },
113e41f4b71Sopenharmony_ci           confirm: ()=> { this.onAccept() },
114e41f4b71Sopenharmony_ci         }),
115e41f4b71Sopenharmony_ci       })
116e41f4b71Sopenharmony_ci   
117e41f4b71Sopenharmony_ci       onCancel() {
118e41f4b71Sopenharmony_ci         console.info('Callback when the first button is clicked')
119e41f4b71Sopenharmony_ci       }
120e41f4b71Sopenharmony_ci   
121e41f4b71Sopenharmony_ci       onAccept() {
122e41f4b71Sopenharmony_ci         console.info('Callback when the second button is clicked')
123e41f4b71Sopenharmony_ci       }
124e41f4b71Sopenharmony_ci   
125e41f4b71Sopenharmony_ci       build() {
126e41f4b71Sopenharmony_ci         Column() {
127e41f4b71Sopenharmony_ci           Button('click me')
128e41f4b71Sopenharmony_ci             .onClick(() => {
129e41f4b71Sopenharmony_ci               this.dialogController.open()
130e41f4b71Sopenharmony_ci             })
131e41f4b71Sopenharmony_ci         }.width('100%').margin({ top: 5 })
132e41f4b71Sopenharmony_ci       }
133e41f4b71Sopenharmony_ci     }
134e41f4b71Sopenharmony_ci   ```
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci      ![en-us_image_0000001511421320](figures/en-us_image_0000001511421320.png)
137e41f4b71Sopenharmony_ci   
138e41f4b71Sopenharmony_ci   3. Use the button in the dialog box to implement route redirection and obtain the parameters passed in from the redirection target page.
139e41f4b71Sopenharmony_ci   
140e41f4b71Sopenharmony_ci   ```ts
141e41f4b71Sopenharmony_ci   // Index.ets
142e41f4b71Sopenharmony_ci   import { router } from '@kit.ArkUI';
143e41f4b71Sopenharmony_ci   
144e41f4b71Sopenharmony_ci   @CustomDialog
145e41f4b71Sopenharmony_ci   struct CustomDialogExample {
146e41f4b71Sopenharmony_ci     @Link textValue: string
147e41f4b71Sopenharmony_ci     controller?: CustomDialogController
148e41f4b71Sopenharmony_ci     cancel: () => void = () => {
149e41f4b71Sopenharmony_ci     }
150e41f4b71Sopenharmony_ci     confirm: () => void = () => {
151e41f4b71Sopenharmony_ci     }
152e41f4b71Sopenharmony_ci   
153e41f4b71Sopenharmony_ci     build() {
154e41f4b71Sopenharmony_ci       Column({ space: 20 }) {
155e41f4b71Sopenharmony_ci         if (this.textValue != '') {
156e41f4b71Sopenharmony_ci           Text(`Content of the second page: ${this.textValue}`)
157e41f4b71Sopenharmony_ci             .fontSize(20)
158e41f4b71Sopenharmony_ci         } else {
159e41f4b71Sopenharmony_ci           Text('Obtain the content of the second page?')
160e41f4b71Sopenharmony_ci             .fontSize(20)
161e41f4b71Sopenharmony_ci         }
162e41f4b71Sopenharmony_ci         Flex({ justifyContent: FlexAlign.SpaceAround }) {
163e41f4b71Sopenharmony_ci           Button('Cancel')
164e41f4b71Sopenharmony_ci             .onClick(() => {
165e41f4b71Sopenharmony_ci               if (this.controller != undefined) {
166e41f4b71Sopenharmony_ci                 this.controller.close()
167e41f4b71Sopenharmony_ci                 this.cancel()
168e41f4b71Sopenharmony_ci               }
169e41f4b71Sopenharmony_ci             }).backgroundColor(0xffffff).fontColor(Color.Black)
170e41f4b71Sopenharmony_ci           Button('Obtain')
171e41f4b71Sopenharmony_ci             .onClick(() => {
172e41f4b71Sopenharmony_ci               if (this.controller != undefined && this.textValue != '') {
173e41f4b71Sopenharmony_ci                 this.controller.close()
174e41f4b71Sopenharmony_ci               } else if (this.controller != undefined) {
175e41f4b71Sopenharmony_ci                 router.pushUrl({
176e41f4b71Sopenharmony_ci                   url: 'pages/Index2'
177e41f4b71Sopenharmony_ci                 })
178e41f4b71Sopenharmony_ci                 this.controller.close()
179e41f4b71Sopenharmony_ci               }
180e41f4b71Sopenharmony_ci             }).backgroundColor(0xffffff).fontColor(Color.Red)
181e41f4b71Sopenharmony_ci         }.margin({ bottom: 10 })
182e41f4b71Sopenharmony_ci       }.borderRadius(10).padding({ top: 20 })
183e41f4b71Sopenharmony_ci     }
184e41f4b71Sopenharmony_ci   }
185e41f4b71Sopenharmony_ci   
186e41f4b71Sopenharmony_ci   @Entry
187e41f4b71Sopenharmony_ci   @Component
188e41f4b71Sopenharmony_ci   struct CustomDialogUser {
189e41f4b71Sopenharmony_ci     @State textValue: string = ''
190e41f4b71Sopenharmony_ci     dialogController: CustomDialogController | null = new CustomDialogController({
191e41f4b71Sopenharmony_ci       builder: CustomDialogExample({
192e41f4b71Sopenharmony_ci         cancel: () => {
193e41f4b71Sopenharmony_ci           this.onCancel()
194e41f4b71Sopenharmony_ci         },
195e41f4b71Sopenharmony_ci         confirm: () => {
196e41f4b71Sopenharmony_ci           this.onAccept()
197e41f4b71Sopenharmony_ci         },
198e41f4b71Sopenharmony_ci         textValue: $textValue
199e41f4b71Sopenharmony_ci       })
200e41f4b71Sopenharmony_ci     })
201e41f4b71Sopenharmony_ci   
202e41f4b71Sopenharmony_ci     // Set dialogController to null when the custom component is about to be destroyed.
203e41f4b71Sopenharmony_ci     aboutToDisappear() {
204e41f4b71Sopenharmony_ci       this.dialogController = null // Set dialogController to null.
205e41f4b71Sopenharmony_ci     }
206e41f4b71Sopenharmony_ci   
207e41f4b71Sopenharmony_ci     onPageShow() {
208e41f4b71Sopenharmony_ci       const params = router.getParams() as Record<string, string>; // Obtain the passed parameter object.
209e41f4b71Sopenharmony_ci       if (params) {
210e41f4b71Sopenharmony_ci         this.dialogController?.open()
211e41f4b71Sopenharmony_ci         this.textValue = params.info as string; // Obtain the value of the id attribute.
212e41f4b71Sopenharmony_ci       }
213e41f4b71Sopenharmony_ci     }
214e41f4b71Sopenharmony_ci   
215e41f4b71Sopenharmony_ci     onCancel() {
216e41f4b71Sopenharmony_ci       console.info('Callback when the first button is clicked')
217e41f4b71Sopenharmony_ci     }
218e41f4b71Sopenharmony_ci   
219e41f4b71Sopenharmony_ci     onAccept() {
220e41f4b71Sopenharmony_ci       console.info('Callback when the second button is clicked')
221e41f4b71Sopenharmony_ci     }
222e41f4b71Sopenharmony_ci   
223e41f4b71Sopenharmony_ci     exitApp() {
224e41f4b71Sopenharmony_ci       console.info('Click the callback in the blank area')
225e41f4b71Sopenharmony_ci     }
226e41f4b71Sopenharmony_ci   
227e41f4b71Sopenharmony_ci     build() {
228e41f4b71Sopenharmony_ci       Column() {
229e41f4b71Sopenharmony_ci         Button('click me')
230e41f4b71Sopenharmony_ci           .onClick(() => {
231e41f4b71Sopenharmony_ci             if (this.dialogController != null) {
232e41f4b71Sopenharmony_ci               this.dialogController.open()
233e41f4b71Sopenharmony_ci             }
234e41f4b71Sopenharmony_ci           }).backgroundColor(0x317aff)
235e41f4b71Sopenharmony_ci       }.width('100%').margin({ top: 5 })
236e41f4b71Sopenharmony_ci     }
237e41f4b71Sopenharmony_ci   }
238e41f4b71Sopenharmony_ci   ```
239e41f4b71Sopenharmony_ci   
240e41f4b71Sopenharmony_ci   ```ts
241e41f4b71Sopenharmony_ci   // Index2.ets
242e41f4b71Sopenharmony_ci   import { router } from '@kit.ArkUI';
243e41f4b71Sopenharmony_ci   
244e41f4b71Sopenharmony_ci   @Entry
245e41f4b71Sopenharmony_ci   @Component
246e41f4b71Sopenharmony_ci   struct Index2 {
247e41f4b71Sopenharmony_ci     @State message: string =' Back';
248e41f4b71Sopenharmony_ci     build() {
249e41f4b71Sopenharmony_ci       Column() {
250e41f4b71Sopenharmony_ci         Button(this.message)
251e41f4b71Sopenharmony_ci           .fontSize(50)
252e41f4b71Sopenharmony_ci           .fontWeight(FontWeight.Bold).onClick(() => {
253e41f4b71Sopenharmony_ci           router.back({
254e41f4b71Sopenharmony_ci             url: 'pages/Index',
255e41f4b71Sopenharmony_ci             params: {
256e41f4b71Sopenharmony_ci               info: 'Hello World'
257e41f4b71Sopenharmony_ci             }
258e41f4b71Sopenharmony_ci           });
259e41f4b71Sopenharmony_ci         })
260e41f4b71Sopenharmony_ci       }.width('100%').height('100%').margin({ top: 20 })
261e41f4b71Sopenharmony_ci     }
262e41f4b71Sopenharmony_ci   }
263e41f4b71Sopenharmony_ci   ```
264e41f4b71Sopenharmony_ci   
265e41f4b71Sopenharmony_ci   ![DialogRouter](figures/DialogRouter.gif)
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_ci## Defining the Custom Dialog Box Animation
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ciYou can define the custom dialog box animation, including its duration and speed, through **openAnimation**.
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ci```ts
272e41f4b71Sopenharmony_ci@CustomDialog
273e41f4b71Sopenharmony_cistruct CustomDialogExample {
274e41f4b71Sopenharmony_ci  controller?: CustomDialogController
275e41f4b71Sopenharmony_ci
276e41f4b71Sopenharmony_ci  build() {
277e41f4b71Sopenharmony_ci    Column() {
278e41f4b71Sopenharmony_ci      Text('Whether to change a text?').fontSize(16).margin({ bottom: 10 })
279e41f4b71Sopenharmony_ci    }
280e41f4b71Sopenharmony_ci  }
281e41f4b71Sopenharmony_ci}
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ci@Entry
284e41f4b71Sopenharmony_ci@Component
285e41f4b71Sopenharmony_cistruct CustomDialogUser {
286e41f4b71Sopenharmony_ci  @State textValue: string = ''
287e41f4b71Sopenharmony_ci  @State inputValue: string = 'click me'
288e41f4b71Sopenharmony_ci  dialogController: CustomDialogController | null = new CustomDialogController({
289e41f4b71Sopenharmony_ci    builder: CustomDialogExample(),
290e41f4b71Sopenharmony_ci    openAnimation: {
291e41f4b71Sopenharmony_ci      duration: 1200,
292e41f4b71Sopenharmony_ci      curve: Curve.Friction,
293e41f4b71Sopenharmony_ci      delay: 500,
294e41f4b71Sopenharmony_ci      playMode: PlayMode.Alternate,
295e41f4b71Sopenharmony_ci      onFinish: () => {
296e41f4b71Sopenharmony_ci        console.info('play end')
297e41f4b71Sopenharmony_ci      }
298e41f4b71Sopenharmony_ci    },
299e41f4b71Sopenharmony_ci    autoCancel: true,
300e41f4b71Sopenharmony_ci    alignment: DialogAlignment.Bottom,
301e41f4b71Sopenharmony_ci    offset: { dx: 0, dy: -20 },
302e41f4b71Sopenharmony_ci    gridCount: 4,
303e41f4b71Sopenharmony_ci    customStyle: false,
304e41f4b71Sopenharmony_ci    backgroundColor: 0xd9ffffff,
305e41f4b71Sopenharmony_ci    cornerRadius: 10,
306e41f4b71Sopenharmony_ci  })
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_ci  // Set dialogController to null when the custom component is about to be destroyed.
309e41f4b71Sopenharmony_ci  aboutToDisappear() {
310e41f4b71Sopenharmony_ci    this.dialogController = null // Set dialogController to null.
311e41f4b71Sopenharmony_ci  }
312e41f4b71Sopenharmony_ci
313e41f4b71Sopenharmony_ci  build() {
314e41f4b71Sopenharmony_ci    Column() {
315e41f4b71Sopenharmony_ci      Button(this.inputValue)
316e41f4b71Sopenharmony_ci        .onClick(() => {
317e41f4b71Sopenharmony_ci          if (this.dialogController != null) {
318e41f4b71Sopenharmony_ci            this.dialogController.open()
319e41f4b71Sopenharmony_ci          }
320e41f4b71Sopenharmony_ci        }).backgroundColor(0x317aff)
321e41f4b71Sopenharmony_ci    }.width('100%').margin({ top: 5 })
322e41f4b71Sopenharmony_ci  }
323e41f4b71Sopenharmony_ci}
324e41f4b71Sopenharmony_ci```
325e41f4b71Sopenharmony_ci
326e41f4b71Sopenharmony_ci![openAnimator](figures/openAnimator.gif)
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci## Nesting a Custom Dialog Box
329e41f4b71Sopenharmony_ci
330e41f4b71Sopenharmony_ciTo nest a dialog box (dialog 2) within another dialog box (dialog 1), it is recommended that you define dialog 2 at the parent component of dialog 1 and open dialog 2 through the callback sent by the parent component to dialog 1.
331e41f4b71Sopenharmony_ci
332e41f4b71Sopenharmony_ci```ts
333e41f4b71Sopenharmony_ci@CustomDialog
334e41f4b71Sopenharmony_cistruct CustomDialogExampleTwo {
335e41f4b71Sopenharmony_ci  controllerTwo?: CustomDialogController
336e41f4b71Sopenharmony_ci  @State message: string = "I'm the second dialog box."
337e41f4b71Sopenharmony_ci  @State showIf: boolean = false;
338e41f4b71Sopenharmony_ci  build() {
339e41f4b71Sopenharmony_ci    Column() {
340e41f4b71Sopenharmony_ci      if (this.showIf) {
341e41f4b71Sopenharmony_ci        Text("Text")
342e41f4b71Sopenharmony_ci          .fontSize(30)
343e41f4b71Sopenharmony_ci          .height(100)
344e41f4b71Sopenharmony_ci      }
345e41f4b71Sopenharmony_ci      Text(this.message)
346e41f4b71Sopenharmony_ci        .fontSize(30)
347e41f4b71Sopenharmony_ci        .height(100)
348e41f4b71Sopenharmony_ci      Button("Create Text")
349e41f4b71Sopenharmony_ci        .onClick(()=>{
350e41f4b71Sopenharmony_ci          this.showIf = true;
351e41f4b71Sopenharmony_ci        })
352e41f4b71Sopenharmony_ci      Button ('Close Second Dialog Box')
353e41f4b71Sopenharmony_ci        .onClick(() => {
354e41f4b71Sopenharmony_ci          if (this.controllerTwo != undefined) {
355e41f4b71Sopenharmony_ci            this.controllerTwo.close()
356e41f4b71Sopenharmony_ci          }
357e41f4b71Sopenharmony_ci        })
358e41f4b71Sopenharmony_ci        .margin(20)
359e41f4b71Sopenharmony_ci    }
360e41f4b71Sopenharmony_ci  }
361e41f4b71Sopenharmony_ci}
362e41f4b71Sopenharmony_ci@CustomDialog
363e41f4b71Sopenharmony_cistruct CustomDialogExample {
364e41f4b71Sopenharmony_ci  openSecondBox?: ()=>void
365e41f4b71Sopenharmony_ci  controller?: CustomDialogController
366e41f4b71Sopenharmony_ci
367e41f4b71Sopenharmony_ci  build() {
368e41f4b71Sopenharmony_ci    Column() {
369e41f4b71Sopenharmony_ci      Button ('Open Second Dialog Box and close this box')
370e41f4b71Sopenharmony_ci        .onClick(() => {
371e41f4b71Sopenharmony_ci          this.controller!.close();
372e41f4b71Sopenharmony_ci          this.openSecondBox!();
373e41f4b71Sopenharmony_ci        })
374e41f4b71Sopenharmony_ci        .margin(20)
375e41f4b71Sopenharmony_ci    }.borderRadius(10)
376e41f4b71Sopenharmony_ci  }
377e41f4b71Sopenharmony_ci}
378e41f4b71Sopenharmony_ci@Entry
379e41f4b71Sopenharmony_ci@Component
380e41f4b71Sopenharmony_cistruct CustomDialogUser {
381e41f4b71Sopenharmony_ci  @State inputValue: string = 'Click Me'
382e41f4b71Sopenharmony_ci  dialogController: CustomDialogController | null = new CustomDialogController({
383e41f4b71Sopenharmony_ci    builder: CustomDialogExample({
384e41f4b71Sopenharmony_ci      openSecondBox: ()=>{
385e41f4b71Sopenharmony_ci        if (this.dialogControllerTwo != null) {
386e41f4b71Sopenharmony_ci          this.dialogControllerTwo.open()
387e41f4b71Sopenharmony_ci        }
388e41f4b71Sopenharmony_ci      }
389e41f4b71Sopenharmony_ci    }),
390e41f4b71Sopenharmony_ci    cancel: this.exitApp,
391e41f4b71Sopenharmony_ci    autoCancel: true,
392e41f4b71Sopenharmony_ci    alignment: DialogAlignment.Bottom,
393e41f4b71Sopenharmony_ci    offset: { dx: 0, dy: -20 },
394e41f4b71Sopenharmony_ci    gridCount: 4,
395e41f4b71Sopenharmony_ci    customStyle: false
396e41f4b71Sopenharmony_ci  })
397e41f4b71Sopenharmony_ci  dialogControllerTwo: CustomDialogController | null = new CustomDialogController({
398e41f4b71Sopenharmony_ci    builder: CustomDialogExampleTwo(),
399e41f4b71Sopenharmony_ci    alignment: DialogAlignment.Bottom,
400e41f4b71Sopenharmony_ci    offset: { dx: 0, dy: -25 } })
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci  aboutToDisappear() {
403e41f4b71Sopenharmony_ci    this.dialogController = null
404e41f4b71Sopenharmony_ci    this.dialogControllerTwo = null
405e41f4b71Sopenharmony_ci  }
406e41f4b71Sopenharmony_ci
407e41f4b71Sopenharmony_ci  onCancel() {
408e41f4b71Sopenharmony_ci    console.info('Callback when the first button is clicked')
409e41f4b71Sopenharmony_ci  }
410e41f4b71Sopenharmony_ci
411e41f4b71Sopenharmony_ci  onAccept() {
412e41f4b71Sopenharmony_ci    console.info('Callback when the second button is clicked')
413e41f4b71Sopenharmony_ci  }
414e41f4b71Sopenharmony_ci
415e41f4b71Sopenharmony_ci  exitApp() {
416e41f4b71Sopenharmony_ci    console.info('Click the callback in the blank area')
417e41f4b71Sopenharmony_ci  }
418e41f4b71Sopenharmony_ci  build() {
419e41f4b71Sopenharmony_ci    Column() {
420e41f4b71Sopenharmony_ci      Button(this.inputValue)
421e41f4b71Sopenharmony_ci        .onClick(() => {
422e41f4b71Sopenharmony_ci          if (this.dialogController != null) {
423e41f4b71Sopenharmony_ci            this.dialogController.open()
424e41f4b71Sopenharmony_ci          }
425e41f4b71Sopenharmony_ci        }).backgroundColor(0x317aff)
426e41f4b71Sopenharmony_ci    }.width('100%').margin({ top: 5 })
427e41f4b71Sopenharmony_ci  }
428e41f4b71Sopenharmony_ci}
429e41f4b71Sopenharmony_ci```
430e41f4b71Sopenharmony_ci![nested_dialog](figures/nested_dialog.gif)
431e41f4b71Sopenharmony_ci
432e41f4b71Sopenharmony_ciIf you define dialog 2 at dialog 1 instead, due to the parent-child relationship between custom dialog boxes on the state management side, you will not be able to create any component in dialog 2 once dialog 1 is destroyed (closed).
433e41f4b71Sopenharmony_ci
434