# ArkUI Component Development (ArkTS) ## Can custom dialog boxes be defined and used in .ts files? Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) Unfortunately not. Custom dialog boxes require ArkTS syntax for definition and initialization. Therefore, they can be defined and used only in .ets files. **Reference** [Custom Dialog Box](../reference/arkui-ts/ts-methods-custom-dialog-box.md) ## How do I transfer variables in a custom dialog box to a page? Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) **Symptom** The variable defined in a custom dialog box needs to be transferred to the page when the dialog box is closed or the variable changes. **Solution** - Method 1: Define the variable as a state variable of the custom dialog box. - Method 2: During initialization of the custom dialog box, pass to it a method, which is triggered in the custom dialog box and accepts the variable in the custom dialog box as a parameter. - Method 3: Use AppStorage or LocalStorage to manage page state and implement state sharing between the custom dialog box and page. **Example** - Method 1: ``` @CustomDialog struct CustomDialog01 { @Link inputValue: string controller: CustomDialogController build() { Column() { Text('Change text').fontSize(20).margin({ top: 10, bottom: 10 }) TextInput({ placeholder: '', text: this.inputValue }).height(60).width('90%') .onChange((value: string) => { this.inputValue = value }) } } } @Entry @Component struct DialogDemo01 { @State inputValue: string = 'click me' dialogController: CustomDialogController = new CustomDialogController({ builder: CustomDialog01({ inputValue: $inputValue }) }) build() { Column() { Button(this.inputValue) .onClick(() => { this.dialogController.open() }).backgroundColor(0x317aff) }.width('100%').margin({ top: 5 }) } } ``` - Method 2: ``` @CustomDialog struct CustomDialog02 { private inputValue: string changeInputValue: (val: string) => void controller: CustomDialogController build() { Column() { Text('Change text').fontSize(20).margin({ top: 10, bottom: 10 }) TextInput({ placeholder: '', text: this.inputValue }).height(60).width('90%') .onChange((value: string) => { this.changeInputValue(value) }) } } } @Entry @Component struct DialogDemo02 { @State inputValue: string = 'click me' dialogController: CustomDialogController = new CustomDialogController({ builder: CustomDialog02({ inputValue: this.inputValue, changeInputValue: (val: string) => { this.inputValue = val } }) }) build() { Column() { Button(this.inputValue) .onClick(() => { this.dialogController.open() }).backgroundColor(0x317aff) }.width('100%').margin({ top: 5 }) } } ``` - Method 3: ``` let storage = LocalStorage.GetShared() @CustomDialog struct CustomDialog03 { @LocalStorageLink('inputVal') inputValue: string = '' controller: CustomDialogController build() { Column() { Text('Change text').fontSize(20).margin({ top: 10, bottom: 10 }) TextInput({ placeholder: '', text: this.inputValue }).height(60).width('90%') .onChange((value: string) => { this.inputValue = value; }) } } } @Entry(storage) @Component struct DialogDemo03 { @LocalStorageLink('inputVal') inputValue: string = '' dialogController: CustomDialogController = new CustomDialogController({ builder: CustomDialog03() }) build() { Column() { Button(this.inputValue) .onClick(() => { this.dialogController.open() }).backgroundColor(0x317aff) }.width('100%').margin({ top: 5 }) } } ``` ## How do I obtain the width and height of a component? Applicable to: OpenHarmony 3.2 Beta 5 (API version 9) **Symptom** The width and height of a component need to be obtained to calculate the size and offset of the layout area. **Solution** - Method 1: Use the **onAreaChange** event of the component, which is triggered when the component is initialized or the component size changes. - Manner 2: Use the callback in the click or touch event, which provides the area information of the target element. **Reference** [Component Area Change Event](../reference/arkui-ts/ts-universal-component-area-change-event.md), [Click Event](../reference/arkui-ts/ts-universal-events-click.md), [Touch Event](../reference/arkui-ts/ts-universal-events-touch.md) ## How do I clear the content of the \ and \