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/// <reference path="../../state_mgmt/distRelease/stateMgmt.d.ts" /> 16enum NodeRenderType { 17 RENDER_TYPE_DISPLAY = 0, 18 RENDER_TYPE_TEXTURE, 19} 20 21declare interface RenderOptions { 22 selfIdealSize?: Size, 23 type?: NodeRenderType, 24 surfaceId?: string 25} 26 27declare class DrawContext { } 28declare type NodePtr = Object | null; 29declare class __JSBaseNode__ { 30 constructor(options?: RenderOptions); 31 create(builder: (...args: Object[]) => void, params: Object, update: (instanceId: number, nodePtr: NodePtr) => void, 32 updateConfiguration, supportLazyBuild: boolean): NodePtr; 33 finishUpdateFunc(): void; 34 postTouchEvent(touchEvent: TouchEvent): boolean; 35 disposeNode(): void; 36 updateStart(): void; 37 updateEnd(): void; 38 onRecycleWithBindObject(): void; 39 onReuseWithBindObject(object: Object): void; 40} 41abstract class BaseNode extends ViewBuildNodeBase { 42 protected instanceId_?: number; 43 protected nodePtr_: NodePtr; 44 public builderBaseNode_: __JSBaseNode__; 45 constructor(uiContext: UIContext, options?: RenderOptions) { 46 super(false); 47 let baseNode = new __JSBaseNode__(options); 48 this.builderBaseNode_ = baseNode; 49 50 if (uiContext === undefined) { 51 throw Error('Node constructor error, param uiContext error'); 52 } else { 53 if (!(typeof uiContext === 'object') || !('instanceId_' in uiContext)) { 54 throw Error( 55 'Node constructor error, param uiContext is invalid' 56 ); 57 } 58 } 59 this.instanceId_ = uiContext.instanceId_; 60 } 61 public getInstanceId() { 62 return this.instanceId_; 63 } 64 updateInstance(uiContext: UIContext): void { 65 this.instanceId_ = uiContext.instanceId_; 66 } 67 create(builder: (...args: Object[]) => void, params: Object, update: (instanceId: number, nodePtr: NodePtr) => void, 68 updateConfiguration, supportLazyBuild: boolean): NodePtr { 69 return this.builderBaseNode_.create(builder.bind(this), params, update.bind(this), updateConfiguration.bind(this), supportLazyBuild); 70 } 71 finishUpdateFunc(): void { 72 return this.builderBaseNode_.finishUpdateFunc(); 73 } 74 postTouchEvent(touchEvent: TouchEvent): boolean { 75 return this.builderBaseNode_.postTouchEvent(touchEvent); 76 } 77 disposeNode(): void { 78 return this.builderBaseNode_.disposeNode(); 79 } 80 updateStart(): void { 81 return this.builderBaseNode_.updateStart(); 82 } 83 updateEnd(): void { 84 return this.builderBaseNode_.updateEnd(); 85 } 86 onRecycleWithBindObject(): void { 87 return this.builderBaseNode_.onRecycleWithBindObject(); 88 } 89 onReuseWithBindObject(object: Object): void { 90 return this.builderBaseNode_.onReuseWithBindObject(object); 91 } 92 public abstract ifElseBranchUpdateFunctionDirtyRetaken(): void; 93 public abstract forceCompleteRerender(deep: boolean): void; 94 public abstract forceRerenderNode(elmtId: number): void; 95 public abstract purgeDeleteElmtId(rmElmtId: number): boolean; 96} 97