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@Entry 18@Component 19struct HomePreviewComponent { 20 private value1: string = "hello world 1" 21 private value2: string = "hello world 2" 22 private value3: string = "hello world 3" 23 24 build() { 25 Column() { 26 Row() { 27 Text(this.value1) 28 Text(this.value2) 29 Text(this.value3) 30 } 31 Row() { 32 Button() { 33 Text(this.value1) 34 .fontSize(20) 35 } 36 .width(100) 37 .height(20) 38 Text(this.value2) 39 .fontSize(100) 40 Text(this.value3) 41 } 42 .width(20) 43 } 44 .height(500) 45 } 46} 47 48@Preview 49@Component 50struct HomePreviewComponent_Preview { 51 build() { 52 Column() { 53 HomePreviewComponent(); 54 } 55 } 56} 57` 58 59exports.expectResult = 60`"use strict"; 61class HomePreviewComponent extends View { 62 constructor(compilerAssignedUniqueChildId, parent, params) { 63 super(compilerAssignedUniqueChildId, parent); 64 this.value1 = "hello world 1"; 65 this.value2 = "hello world 2"; 66 this.value3 = "hello world 3"; 67 this.updateWithValueParams(params); 68 } 69 updateWithValueParams(params) { 70 if (params.value1 !== undefined) { 71 this.value1 = params.value1; 72 } 73 if (params.value2 !== undefined) { 74 this.value2 = params.value2; 75 } 76 if (params.value3 !== undefined) { 77 this.value3 = params.value3; 78 } 79 } 80 aboutToBeDeleted() { 81 SubscriberManager.Get().delete(this.id()); 82 } 83 render() { 84 Column.create(); 85 Column.height(500); 86 Row.create(); 87 Text.create(this.value1); 88 Text.pop(); 89 Text.create(this.value2); 90 Text.pop(); 91 Text.create(this.value3); 92 Text.pop(); 93 Row.pop(); 94 Row.create(); 95 Row.width(20); 96 Button.createWithChild(); 97 Button.width(100); 98 Button.height(20); 99 Text.create(this.value1); 100 Text.fontSize(20); 101 Text.pop(); 102 Button.pop(); 103 Text.create(this.value2); 104 Text.fontSize(100); 105 Text.pop(); 106 Text.create(this.value3); 107 Text.pop(); 108 Row.pop(); 109 Column.pop(); 110 } 111} 112class HomePreviewComponent_Preview extends View { 113 constructor(compilerAssignedUniqueChildId, parent, params) { 114 super(compilerAssignedUniqueChildId, parent); 115 this.updateWithValueParams(params); 116 } 117 updateWithValueParams(params) { 118 } 119 aboutToBeDeleted() { 120 SubscriberManager.Get().delete(this.id()); 121 } 122 render() { 123 Column.create(); 124 let earlierCreatedChild_2 = this.findChildById("2"); 125 if (earlierCreatedChild_2 == undefined) { 126 View.create(new HomePreviewComponent("2", this, {})); 127 } 128 else { 129 earlierCreatedChild_2.updateWithValueParams({}); 130 if (!earlierCreatedChild_2.needsUpdate()) { 131 earlierCreatedChild_2.markStatic(); 132 } 133 View.create(earlierCreatedChild_2); 134 } 135 Column.pop(); 136 } 137} 138loadDocument(new HomePreviewComponent("1", undefined, {})); 139` 140