1/* 2 * Copyright (c) 2024 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 16const pip = requireNapi('pip'); 17const NodeController = requireNapi('arkui.node').NodeController; 18const FrameNode = requireNapi('arkui.node').FrameNode; 19 20const TAG = 'PiPContent'; 21const ABOUT_TO_STOP = 3; 22 23class XCNodeController extends NodeController { 24 constructor(k2) { 25 super(); 26 this.node = null; 27 this.mXComponent = k2; 28 } 29 30 makeNode(i2) { 31 let j2; 32 this.node = new FrameNode(i2); 33 this.node.appendChild(this.mXComponent); 34 return this.node; 35 } 36 37 removeNode() { 38 let h2; 39 (h2 = this.node) === null || h2 === void 0 ? void 0 : h2.removeChild(this.mXComponent); 40 } 41} 42 43class PiPContent extends ViewPU { 44 constructor(b2, c2, d2, e2 = -1, f2 = undefined, g2) { 45 super(b2, d2, e2, g2); 46 if (typeof f2 === 'function') { 47 this.paramsGenerator_ = f2; 48 } 49 this.xComponentController = new XComponentController; 50 this.nodeController = null; 51 this.mXCNodeController = null; 52 this.useNode = false; 53 this.xComponentId = 'pipContent'; 54 this.xComponentType = 'surface'; 55 this.xComponent = null; 56 this.setInitiallyProvidedValue(c2); 57 } 58 59 setInitiallyProvidedValue(a2) { 60 if (a2.xComponentController !== undefined) { 61 this.xComponentController = a2.xComponentController; 62 } 63 if (a2.nodeController !== undefined) { 64 this.nodeController = a2.nodeController; 65 } 66 if (a2.mXCNodeController !== undefined) { 67 this.mXCNodeController = a2.mXCNodeController; 68 } 69 if (a2.useNode !== undefined) { 70 this.useNode = a2.useNode; 71 } 72 if (a2.xComponentId !== undefined) { 73 this.xComponentId = a2.xComponentId; 74 } 75 if (a2.xComponentType !== undefined) { 76 this.xComponentType = a2.xComponentType; 77 } 78 if (a2.xComponent !== undefined) { 79 this.xComponent = a2.xComponent; 80 } 81 } 82 83 updateStateVars(z1) { 84 } 85 86 purgeVariableDependenciesOnElmtId(y1) { 87 } 88 89 aboutToAppear() { 90 this.nodeController = pip.getCustomUIController(); 91 this.xComponent = pip.getTypeNode(); 92 if (this.xComponent === null || this.xComponent === undefined) { 93 console.error(TAG, `xComponent node is null`); 94 return; 95 } 96 let u1 = this.xComponent.getNodeType(); 97 if (u1 !== 'XComponent') { 98 console.error(`xComponent type mismatch: ${u1}`); 99 return; 100 } 101 this.useNode = true; 102 pip.setTypeNodeEnabled(); 103 this.mXCNodeController = new XCNodeController(this.xComponent); 104 console.info(TAG, 'use Node Controller'); 105 pip.on('stateChange', (w1) => { 106 let x1; 107 console.info(TAG, `stateChange state: ${w1}`); 108 if (w1 === ABOUT_TO_STOP) { 109 (x1 = this.mXCNodeController) === null || x1 === void 0 ? void 0 : x1.removeNode(); 110 } 111 }); 112 } 113 114 aboutToBeDeleted() { 115 SubscriberManager.Get().delete(this.id__()); 116 this.aboutToBeDeletedInternal(); 117 } 118 119 aboutToDisappear() { 120 pip.off('stateChange'); 121 } 122 123 initialRender() { 124 this.observeComponentCreation2((s1, t1) => { 125 Stack.create(); 126 Stack.size({ width: '100%', height: '100%' }); 127 }, Stack); 128 this.observeComponentCreation2((h1, i1) => { 129 If.create(); 130 if (this.useNode) { 131 this.ifElseBranchUpdateFunction(0, () => { 132 this.buildNode.bind(this)(); 133 }); 134 } else { 135 this.ifElseBranchUpdateFunction(1, () => { 136 this.buildXComponent.bind(this)(); 137 }); 138 } 139 }, If); 140 If.pop(); 141 this.observeComponentCreation2((a1, b1) => { 142 If.create(); 143 if (this.nodeController !== null) { 144 this.ifElseBranchUpdateFunction(0, () => { 145 this.buildCustomUI.bind(this)(); 146 }); 147 } else { 148 this.ifElseBranchUpdateFunction(1, () => { 149 }); 150 } 151 }, If); 152 If.pop(); 153 Stack.pop(); 154 } 155 156 buildCustomUI(g1 = null) { 157 this.observeComponentCreation2((i1, j1) => { 158 NodeContainer.create(this.nodeController); 159 NodeContainer.size({ width: '100%', height: '100%'}); 160 }, NodeContainer); 161 } 162 163 buildXComponent(b1 = null) { 164 this.observeComponentCreation2((d1, e1) => { 165 XComponent.create({ 166 id: this.xComponentId, 167 type: this.xComponentType, 168 controller: this.xComponentController 169 }, 'pipContent_XComponent'); 170 XComponent.onLoad((() => { 171 pip.initXComponentController(this.xComponentController); 172 console.info(TAG, 'XComponent onLoad done'); 173 })); 174 XComponent.size({ width: '100%', height: '100%' }); 175 XComponent.backgroundColor(Color.Transparent); 176 }, XComponent); 177 } 178 179 buildNode(x = null) { 180 this.observeComponentCreation2((z, a1) => { 181 NodeContainer.create(this.mXCNodeController); 182 NodeContainer.size({ width: '100%', height: '100%' }); 183 }, NodeContainer); 184 } 185 186 rerender() { 187 this.updateDirtyElements(); 188 } 189 190 static getEntryName() { 191 return 'PiPContent'; 192 } 193} 194 195ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); 196loadDocument(new PiPContent(void 0, {})); 197ViewStackProcessor.StopGetAccessRecording();