• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/// <reference path="../../state_mgmt/src/lib/common/ifelse_native.d.ts" />
16
17class ComponentContent extends Content {
18  // the name of "builderNode_" is used in ace_engine/interfaces/native/node/native_node_napi.cpp.
19  private builderNode_: BuilderNode;
20  private attachNodeRef_: NativeStrongRef;
21  private parentWeak_: WeakRef<FrameNode> | undefined;
22  constructor(uiContext: UIContext, builder: WrappedBuilder<[]> | WrappedBuilder<[Object]>, params?: Object, options?: BuildOptions) {
23    super();
24    let builderNode = new BuilderNode(uiContext, {});
25    this.builderNode_ = builderNode;
26    this.builderNode_.build(builder, params ?? undefined, options);
27  }
28
29  public update(params: Object) {
30    this.builderNode_.update(params);
31  }
32
33  public getFrameNode(): FrameNode | null | undefined {
34    return this.builderNode_.getFrameNodeWithoutCheck();
35  }
36  public setAttachedParent(parent: WeakRef<FrameNode> | undefined) {
37    this.parentWeak_ = parent;
38  }
39  public getNodePtr(): NodePtr {
40    if (this.attachNodeRef_ !== undefined) {
41      return this.attachNodeRef_.getNativeHandle();
42    }
43    return this.builderNode_.getNodePtr();
44  }
45  public reuse(param: Object): void {
46    this.builderNode_.reuse(param);
47  }
48  public recycle(): void {
49    this.builderNode_.recycle();
50  }
51  public dispose(): void {
52    this.detachFromParent();
53    this.attachNodeRef_?.dispose();
54    this.builderNode_?.dispose();
55  }
56
57  public detachFromParent() {
58    if (this.parentWeak_ === undefined) {
59      return;
60    }
61    let parent = this.parentWeak_.deref();
62    if (parent !== undefined) {
63      parent.removeComponentContent(this);
64    }
65  }
66
67  public getNodeWithoutProxy(): NodePtr {
68    const node = this.getNodePtr();
69    const nodeType = getUINativeModule().frameNode.getNodeType(node);
70    if (nodeType === "BuilderProxyNode") {
71      const result = getUINativeModule().frameNode.getFirstUINode(node);
72      this.attachNodeRef_ = getUINativeModule().nativeUtils.createNativeStrongRef(result);
73      getUINativeModule().frameNode.removeChild(node, result);
74      return result;
75    }
76    return node;
77  }
78
79  public updateConfiguration(): void {
80    this.builderNode_.updateConfiguration();
81  }
82}
83