• 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
16declare class ArkUINativeNodeContent {
17    static getNativeContent(value: ArkUINativeNodeContent): Object;
18}
19
20class NodeContent extends Content {
21    nativeContent_: ArkUINativeNodeContent;
22    nativePtr_: NodePtr;
23    nativeRef_: NativeStrongRef;
24    nodeArray_: Array<FrameNode>;
25
26    constructor() {
27        super();
28        this.nativeRef_ = getUINativeModule().frameNode.createNodeContent();
29        this.nativePtr_ = this.nativeRef_.getNativeHandle();
30        this.nodeArray_ = new Array<FrameNode>();
31    }
32
33    addFrameNode(node: FrameNode): void {
34        if (this.nodeArray_.includes(node)) {
35            return;
36        }
37        if (getUINativeModule().frameNode.addFrameNodeToNodeContent(node.getNodePtr(), this.nativePtr_)) {
38            this.nodeArray_.push(node);
39        }
40    }
41
42    removeFrameNode(node: FrameNode): void {
43        if (!this.nodeArray_.includes(node)) {
44            return;
45        }
46        if (getUINativeModule().frameNode.removeFrameNodeFromNodeContent(node.getNodePtr(), this.nativePtr_)) {
47            let index = this.nodeArray_.indexOf(node);
48            if (index > -1) {
49                this.nodeArray_.splice(index, 1);
50            }
51        }
52    }
53}