• 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@Component
18struct CustomContainer {
19    header: string = "";
20    footer: string = "";
21    @BuilderParam child: () => any;
22
23    build() {
24        Column() {
25            Text(this.header)
26            this.child()
27            Text(this.footer)
28        }
29    }
30}
31
32@Builder function specificParam() {
33    Column() {
34        Text("label1")
35        Text("label2")
36    }
37}
38
39@Entry
40@Component
41struct CustomContainerUser {
42    build() {
43        Column() {
44            CustomContainer({header: "Header", footer: "Footer"}){
45                Column() {
46                    Text("content1")
47                        .width(50)
48                    Text("content2")
49                }
50                specificParam()
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.footer = "";
63        this.updateWithValueParams(params);
64    }
65    updateWithValueParams(params) {
66        if (params.header !== undefined) {
67            this.header = params.header;
68        }
69        if (params.footer !== undefined) {
70            this.footer = params.footer;
71        }
72        this.child = params.child;
73    }
74    aboutToBeDeleted() {
75        SubscriberManager.Get().delete(this.id());
76    }
77    render() {
78        Column.create();
79        Text.create(this.header);
80        Text.pop();
81        this.child();
82        Text.create(this.footer);
83        Text.pop();
84        Column.pop();
85    }
86}
87function specificParam() {
88    Column.create();
89    Text.create("label1");
90    Text.pop();
91    Text.create("label2");
92    Text.pop();
93    Column.pop();
94}
95class CustomContainerUser extends View {
96    constructor(compilerAssignedUniqueChildId, parent, params) {
97        super(compilerAssignedUniqueChildId, parent);
98        this.updateWithValueParams(params);
99    }
100    updateWithValueParams(params) {
101    }
102    aboutToBeDeleted() {
103        SubscriberManager.Get().delete(this.id());
104    }
105    render() {
106        Column.create();
107        let earlierCreatedChild_2 = this.findChildById("2");
108        if (earlierCreatedChild_2 == undefined) {
109            View.create(new CustomContainer("2", this, {
110                header: "Header", footer: "Footer",
111                child: () => {
112                    Column.create();
113                    Text.create("content1");
114                    Text.width(50);
115                    Text.pop();
116                    Text.create("content2");
117                    Text.pop();
118                    Column.pop();
119                    specificParam();
120                }
121            }));
122        }
123        else {
124            earlierCreatedChild_2.updateWithValueParams({
125                header: "Header", footer: "Footer",
126                child: () => {
127                    Column.create();
128                    Text.create("content1");
129                    Text.width(50);
130                    Text.pop();
131                    Text.create("content2");
132                    Text.pop();
133                    Column.pop();
134                    specificParam();
135                }
136            });
137            View.create(earlierCreatedChild_2);
138        }
139        Column.pop();
140    }
141}
142loadDocument(new CustomContainerUser("1", undefined, {}));
143`
144