• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 XComponentNode extends FrameNode {
17  private nativeModule_: any;
18  private xcomponentNode_: any;
19  private renderType_: NodeRenderType;
20  constructor(uiContext: UIContext, options: RenderOptions,
21    id: string, type: XComponentType, libraryname?: string, controller?: XComponentController) {
22    super(uiContext, 'XComponentNode');
23    const elmtId = ViewStackProcessor.AllocateNewElmetIdForNextComponent();
24    this.xcomponentNode_ = getUINativeModule().xcomponentNode;
25    this.renderType_ = options.type;
26    const surfaceId = options.surfaceId;
27    const selfIdealWidth = options.selfIdealSize.width;
28    const selfIdealHeight = options.selfIdealSize.height;
29    this.nativeModule_ = this.xcomponentNode_.create(elmtId, id, type, this.renderType_, surfaceId, selfIdealWidth, selfIdealHeight, libraryname, controller);
30    this.xcomponentNode_.registerOnCreateCallback(this.nativeModule_, this.onCreate);
31    this.xcomponentNode_.registerOnDestroyCallback(this.nativeModule_, this.onDestroy);
32    this.nodePtr_ = this.xcomponentNode_.getFrameNode(this.nativeModule_);
33    this.setNodePtr(getUINativeModule().nativeUtils.createNativeStrongRef(this.nodePtr_), this.nodePtr_);
34  }
35
36  onCreate(event?: object): void { }
37
38  onDestroy(): void { }
39
40  changeRenderType(type: NodeRenderType): boolean {
41    if (this.renderType_ === type) {
42      return true;
43    }
44    if (this.xcomponentNode_.changeRenderType(this.nativeModule_, type)) {
45      this.renderType_ = type;
46      return true;
47    }
48    return false;
49  }
50}
51