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