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 ListComponent { 20 @State dialogVis : boolean = false 21 build() { 22 Stack() { 23 MyAlertDialog({dialogVis: $dialogVis}) 24 } 25 } 26} 27 28@Component 29struct MyAlertDialog { 30 @Link @Watch("onDialogVisUpdated") dialogVis : boolean; 31 onDialogVisUpdated(propName: string) : void { 32 animateTo({}, () => {}) 33 } 34 build() { 35 Stack() { 36 DialogView({dialogShow: $dialogVis}) 37 } 38 } 39} 40 41@Component 42struct DialogView { 43 @Link dialogShow: boolean 44 build() { 45 Column() {} 46 } 47} 48` 49 50exports.expectResult = 51`"use strict"; 52class ListComponent extends View { 53 constructor(compilerAssignedUniqueChildId, parent, params) { 54 super(compilerAssignedUniqueChildId, parent); 55 this.__dialogVis = new ObservedPropertySimple(false, this, "dialogVis"); 56 this.updateWithValueParams(params); 57 } 58 updateWithValueParams(params) { 59 if (params.dialogVis !== undefined) { 60 this.dialogVis = params.dialogVis; 61 } 62 } 63 aboutToBeDeleted() { 64 this.__dialogVis.aboutToBeDeleted(); 65 SubscriberManager.Get().delete(this.id()); 66 } 67 get dialogVis() { 68 return this.__dialogVis.get(); 69 } 70 set dialogVis(newValue) { 71 this.__dialogVis.set(newValue); 72 } 73 render() { 74 Stack.create(); 75 let earlierCreatedChild_2 = this.findChildById("2"); 76 if (earlierCreatedChild_2 == undefined) { 77 View.create(new MyAlertDialog("2", this, { dialogVis: this.__dialogVis })); 78 } 79 else { 80 earlierCreatedChild_2.updateWithValueParams({}); 81 View.create(earlierCreatedChild_2); 82 } 83 Stack.pop(); 84 } 85} 86class MyAlertDialog extends View { 87 constructor(compilerAssignedUniqueChildId, parent, params) { 88 super(compilerAssignedUniqueChildId, parent); 89 this.__dialogVis = new SynchedPropertySimpleTwoWay(params.dialogVis, this, "dialogVis"); 90 this.updateWithValueParams(params); 91 this.declareWatch("dialogVis", this.onDialogVisUpdated); 92 } 93 updateWithValueParams(params) { 94 } 95 aboutToBeDeleted() { 96 this.__dialogVis.aboutToBeDeleted(); 97 SubscriberManager.Get().delete(this.id()); 98 } 99 get dialogVis() { 100 return this.__dialogVis.get(); 101 } 102 set dialogVis(newValue) { 103 this.__dialogVis.set(newValue); 104 } 105 onDialogVisUpdated(propName) { 106 Context.animateTo({}, () => { }); 107 } 108 render() { 109 Stack.create(); 110 let earlierCreatedChild_3 = this.findChildById("3"); 111 if (earlierCreatedChild_3 == undefined) { 112 View.create(new DialogView("3", this, { dialogShow: this.__dialogVis })); 113 } 114 else { 115 earlierCreatedChild_3.updateWithValueParams({}); 116 View.create(earlierCreatedChild_3); 117 } 118 Stack.pop(); 119 } 120} 121class DialogView extends View { 122 constructor(compilerAssignedUniqueChildId, parent, params) { 123 super(compilerAssignedUniqueChildId, parent); 124 this.__dialogShow = new SynchedPropertySimpleTwoWay(params.dialogShow, this, "dialogShow"); 125 this.updateWithValueParams(params); 126 } 127 updateWithValueParams(params) { 128 } 129 aboutToBeDeleted() { 130 this.__dialogShow.aboutToBeDeleted(); 131 SubscriberManager.Get().delete(this.id()); 132 } 133 get dialogShow() { 134 return this.__dialogShow.get(); 135 } 136 set dialogShow(newValue) { 137 this.__dialogShow.set(newValue); 138 } 139 render() { 140 Column.create(); 141 Column.pop(); 142 } 143} 144loadDocument(new ListComponent("1", undefined, {})); 145`