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