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