• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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 = `
17
18@Component
19struct CustomContainer {
20    header: string = "";
21    menuInfo: () => any;
22    footer: string = "";
23    @BuilderParam child: () => any;
24
25    build() {
26        Column() {
27            this.child()
28            Text(this.header)
29            Text(this.footer)
30        }
31    }
32}
33
34@Entry
35@Component
36struct CustomContainerUser {
37    @Builder specificChild(label:string) {
38        Column() {
39            Text("My content1")
40            Text(label)
41        }
42    }
43
44    build() {
45        Column() {
46            CustomContainer({
47                header: "Header",
48                footer: "Footer",
49                menuInfo: this.specificChild("menuInfo"),
50                child: this.specificChild("child")
51            })
52        }
53    }
54}
55`
56exports.expectResult =
57`"use strict";
58class CustomContainer extends View {
59    constructor(compilerAssignedUniqueChildId, parent, params) {
60        super(compilerAssignedUniqueChildId, parent);
61        this.header = "";
62        this.menuInfo = undefined;
63        this.footer = "";
64        this.updateWithValueParams(params);
65    }
66    updateWithValueParams(params) {
67        if (params.header !== undefined) {
68            this.header = params.header;
69        }
70        if (params.menuInfo !== undefined) {
71            this.menuInfo = params.menuInfo;
72        }
73        if (params.footer !== undefined) {
74            this.footer = params.footer;
75        }
76        this.child = params.child;
77    }
78    aboutToBeDeleted() {
79        SubscriberManager.Get().delete(this.id());
80    }
81    render() {
82        Column.create();
83        this.child();
84        Text.create(this.header);
85        Text.pop();
86        Text.create(this.footer);
87        Text.pop();
88        Column.pop();
89    }
90}
91class CustomContainerUser extends View {
92    constructor(compilerAssignedUniqueChildId, parent, params) {
93        super(compilerAssignedUniqueChildId, parent);
94        this.updateWithValueParams(params);
95    }
96    updateWithValueParams(params) {
97    }
98    aboutToBeDeleted() {
99        SubscriberManager.Get().delete(this.id());
100    }
101    specificChild(label) {
102        Column.create();
103        Text.create("My content1");
104        Text.pop();
105        Text.create(label);
106        Text.pop();
107        Column.pop();
108    }
109    render() {
110        Column.create();
111        let earlierCreatedChild_3 = this.findChildById("3");
112        if (earlierCreatedChild_3 == undefined) {
113            View.create(new CustomContainer("3", this, {
114                header: "Header",
115                footer: "Footer",
116                menuInfo: this.specificChild("menuInfo"),
117                child: () => {
118                    this.specificChild("child");
119                }
120            }));
121        }
122        else {
123            earlierCreatedChild_3.updateWithValueParams({
124                header: "Header",
125                footer: "Footer",
126                menuInfo: this.specificChild("menuInfo"),
127                child: () => {
128                    this.specificChild("child");
129                }
130            });
131            View.create(earlierCreatedChild_3);
132        }
133        Column.pop();
134    }
135}
136loadDocument(new CustomContainerUser("1", undefined, {}));
137`
138