1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16exports.source = ` 17import { CustomDialogExample1 as CustomDialogExample } from './test/pages/import@CustomDialog' 18 19@Entry 20@Component 21struct CustomDialogUser { 22 @State textValue: string = '' 23 @State inputValue: string = 'click me' 24 dialogController: CustomDialogController = new CustomDialogController({ 25 builder: CustomDialogExample({ 26 cancel: this.onCancel, 27 confirm: this.onAccept, 28 textValue: $textValue, 29 inputValue: $inputValue 30 }), 31 cancel: this.existApp, 32 autoCancel: true, 33 alignment: DialogAlignment.Default, 34 offset: { dx: 0, dy: -20 }, 35 gridCount: 4, 36 customStyle: false 37 }) 38 39 onCancel() { 40 console.info('Callback when the first button is clicked') 41 } 42 43 onAccept() { 44 console.info('Callback when the second button is clicked') 45 } 46 47 existApp() { 48 console.info('Click the callback in the blank area') 49 } 50 51 build() { 52 Column() { 53 Button(this.inputValue) 54 .onClick(() => { 55 this.dialogController.open() 56 }).backgroundColor(0x317aff) 57 }.width('100%').margin({ top: 5 }) 58 } 59} 60` 61 62exports.expectResult = 63`"use strict"; 64Object.defineProperty(exports, "__esModule", { value: true }); 65let __generate__Id = 0; 66function generateId() { 67 return "import@CustomDialog_" + ++__generate__Id; 68} 69const import_CustomDialog_1 = require("./test/pages/import@CustomDialog"); 70class CustomDialogUser extends View { 71 constructor(compilerAssignedUniqueChildId, parent, params, localStorage) { 72 super(compilerAssignedUniqueChildId, parent, localStorage); 73 this.__textValue = new ObservedPropertySimple('', this, "textValue"); 74 this.__inputValue = new ObservedPropertySimple('click me', this, "inputValue"); 75 this.dialogController = new CustomDialogController({ 76 builder: () => { 77 let jsDialog = new import_CustomDialog_1.CustomDialogExample1("2", this, { 78 cancel: this.onCancel, 79 confirm: this.onAccept, 80 textValue: this.__textValue, 81 inputValue: this.__inputValue 82 }); 83 jsDialog.setController(this.dialogController); 84 View.create(jsDialog); 85 }, 86 cancel: this.existApp, 87 autoCancel: true, 88 alignment: DialogAlignment.Default, 89 offset: { dx: 0, dy: -20 }, 90 gridCount: 4, 91 customStyle: false 92 }, this); 93 this.updateWithValueParams(params); 94 } 95 updateWithValueParams(params) { 96 if (params.textValue !== undefined) { 97 this.textValue = params.textValue; 98 } 99 if (params.inputValue !== undefined) { 100 this.inputValue = params.inputValue; 101 } 102 if (params.dialogController !== undefined) { 103 this.dialogController = params.dialogController; 104 } 105 } 106 aboutToBeDeleted() { 107 this.__textValue.aboutToBeDeleted(); 108 this.__inputValue.aboutToBeDeleted(); 109 SubscriberManager.Get().delete(this.id()); 110 } 111 get textValue() { 112 return this.__textValue.get(); 113 } 114 set textValue(newValue) { 115 this.__textValue.set(newValue); 116 } 117 get inputValue() { 118 return this.__inputValue.get(); 119 } 120 set inputValue(newValue) { 121 this.__inputValue.set(newValue); 122 } 123 onCancel() { 124 console.info('Callback when the first button is clicked'); 125 } 126 onAccept() { 127 console.info('Callback when the second button is clicked'); 128 } 129 existApp() { 130 console.info('Click the callback in the blank area'); 131 } 132 render() { 133 Column.create(); 134 Column.width('100%'); 135 Column.margin({ top: 5 }); 136 Button.createWithLabel(this.inputValue); 137 Button.onClick(() => { 138 this.dialogController.open(); 139 }); 140 Button.backgroundColor(0x317aff); 141 Button.pop(); 142 Column.pop(); 143 } 144} 145loadDocument(new CustomDialogUser("1", undefined, {})); 146` 147