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 }); 65if (!("finalizeConstruction" in ViewPU.prototype)) { 66 Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { }); 67} 68const import_CustomDialog_1 = require("./test/pages/import@CustomDialog"); 69class CustomDialogUser extends ViewPU { 70 constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { 71 super(parent, __localStorage, elmtId, extraInfo); 72 if (typeof paramsLambda === "function") { 73 this.paramsGenerator_ = paramsLambda; 74 } 75 this.__textValue = new ObservedPropertySimplePU('', this, "textValue"); 76 this.__inputValue = new ObservedPropertySimplePU('click me', this, "inputValue"); 77 this.dialogController = new CustomDialogController({ 78 builder: () => { 79 let jsDialog = new import_CustomDialog_1.CustomDialogExample1(this, { 80 cancel: this.onCancel, 81 confirm: this.onAccept, 82 textValue: this.__textValue, 83 inputValue: this.__inputValue 84 }, undefined, -1, () => { }, { page: "import@CustomDialog.ets", line: 10, col: 14 }); 85 jsDialog.setController(this.dialogController); 86 ViewPU.create(jsDialog); 87 let paramsLambda = () => { 88 return { 89 cancel: this.onCancel, 90 confirm: this.onAccept, 91 textValue: this.__textValue, 92 inputValue: this.__inputValue 93 }; 94 }; 95 jsDialog.paramsGenerator_ = paramsLambda; 96 }, 97 cancel: this.existApp, 98 autoCancel: true, 99 alignment: DialogAlignment.Default, 100 offset: { dx: 0, dy: -20 }, 101 gridCount: 4, 102 customStyle: false 103 }, this); 104 this.setInitiallyProvidedValue(params); 105 this.finalizeConstruction(); 106 } 107 setInitiallyProvidedValue(params) { 108 if (params.textValue !== undefined) { 109 this.textValue = params.textValue; 110 } 111 if (params.inputValue !== undefined) { 112 this.inputValue = params.inputValue; 113 } 114 if (params.dialogController !== undefined) { 115 this.dialogController = params.dialogController; 116 } 117 } 118 updateStateVars(params) { 119 } 120 purgeVariableDependenciesOnElmtId(rmElmtId) { 121 this.__textValue.purgeDependencyOnElmtId(rmElmtId); 122 this.__inputValue.purgeDependencyOnElmtId(rmElmtId); 123 } 124 aboutToBeDeleted() { 125 this.__textValue.aboutToBeDeleted(); 126 this.__inputValue.aboutToBeDeleted(); 127 SubscriberManager.Get().delete(this.id__()); 128 this.aboutToBeDeletedInternal(); 129 } 130 get textValue() { 131 return this.__textValue.get(); 132 } 133 set textValue(newValue) { 134 this.__textValue.set(newValue); 135 } 136 get inputValue() { 137 return this.__inputValue.get(); 138 } 139 set inputValue(newValue) { 140 this.__inputValue.set(newValue); 141 } 142 onCancel() { 143 console.info('Callback when the first button is clicked'); 144 } 145 onAccept() { 146 console.info('Callback when the second button is clicked'); 147 } 148 existApp() { 149 console.info('Click the callback in the blank area'); 150 } 151 initialRender() { 152 this.observeComponentCreation2((elmtId, isInitialRender) => { 153 Column.create(); 154 Column.width('100%'); 155 Column.margin({ top: 5 }); 156 }, Column); 157 this.observeComponentCreation2((elmtId, isInitialRender) => { 158 Button.createWithLabel(this.inputValue); 159 Button.onClick(() => { 160 this.dialogController.open(); 161 }); 162 Button.backgroundColor(0x317aff); 163 }, Button); 164 Button.pop(); 165 Column.pop(); 166 } 167 rerender() { 168 this.updateDirtyElements(); 169 } 170} 171ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); 172loadDocument(new CustomDialogUser(undefined, {})); 173ViewStackProcessor.StopGetAccessRecording(); 174` 175