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