/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ exports.source = ` import { CustomDialogExample1 as CustomDialogExample } from './test/pages/import@CustomDialog' @Entry @Component struct CustomDialogUser { @State textValue: string = '' @State inputValue: string = 'click me' dialogController: CustomDialogController = new CustomDialogController({ builder: CustomDialogExample({ cancel: this.onCancel, confirm: this.onAccept, textValue: $textValue, inputValue: $inputValue }), cancel: this.existApp, autoCancel: true, alignment: DialogAlignment.Default, offset: { dx: 0, dy: -20 }, gridCount: 4, customStyle: false }) onCancel() { console.info('Callback when the first button is clicked') } onAccept() { console.info('Callback when the second button is clicked') } existApp() { console.info('Click the callback in the blank area') } build() { Column() { Button(this.inputValue) .onClick(() => { this.dialogController.open() }).backgroundColor(0x317aff) }.width('100%').margin({ top: 5 }) } } ` exports.expectResult = `"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const import_CustomDialog_1 = require("./test/pages/import@CustomDialog"); class CustomDialogUser extends ViewPU { constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined) { super(parent, __localStorage, elmtId); if (typeof paramsLambda === "function") { this.paramsGenerator_ = paramsLambda; } this.__textValue = new ObservedPropertySimplePU('', this, "textValue"); this.__inputValue = new ObservedPropertySimplePU('click me', this, "inputValue"); this.dialogController = new CustomDialogController({ builder: () => { let paramsLambda = () => { return { cancel: this.onCancel, confirm: this.onAccept, textValue: this.__textValue, inputValue: this.__inputValue }; }; let jsDialog = new import_CustomDialog_1.CustomDialogExample1(this, { cancel: this.onCancel, confirm: this.onAccept, textValue: this.__textValue, inputValue: this.__inputValue }, undefined, -1, paramsLambda); jsDialog.setController(this.dialogController); ViewPU.create(jsDialog); }, cancel: this.existApp, autoCancel: true, alignment: DialogAlignment.Default, offset: { dx: 0, dy: -20 }, gridCount: 4, customStyle: false }, this); this.setInitiallyProvidedValue(params); } setInitiallyProvidedValue(params) { if (params.textValue !== undefined) { this.textValue = params.textValue; } if (params.inputValue !== undefined) { this.inputValue = params.inputValue; } if (params.dialogController !== undefined) { this.dialogController = params.dialogController; } } updateStateVars(params) { } purgeVariableDependenciesOnElmtId(rmElmtId) { this.__textValue.purgeDependencyOnElmtId(rmElmtId); this.__inputValue.purgeDependencyOnElmtId(rmElmtId); } aboutToBeDeleted() { this.__textValue.aboutToBeDeleted(); this.__inputValue.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id__()); this.aboutToBeDeletedInternal(); } get textValue() { return this.__textValue.get(); } set textValue(newValue) { this.__textValue.set(newValue); } get inputValue() { return this.__inputValue.get(); } set inputValue(newValue) { this.__inputValue.set(newValue); } onCancel() { console.info('Callback when the first button is clicked'); } onAccept() { console.info('Callback when the second button is clicked'); } existApp() { console.info('Click the callback in the blank area'); } initialRender() { this.observeComponentCreation2((elmtId, isInitialRender) => { Column.create(); Column.width('100%'); Column.margin({ top: 5 }); }, Column); this.observeComponentCreation2((elmtId, isInitialRender) => { Button.createWithLabel(this.inputValue); Button.onClick(() => { this.dialogController.open(); }); Button.backgroundColor(0x317aff); }, Button); Button.pop(); Column.pop(); } rerender() { this.updateDirtyElements(); } } ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); loadDocument(new CustomDialogUser(undefined, {})); ViewStackProcessor.StopGetAccessRecording(); `