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 16/// <reference path='./import.ts' /> 17class ArkFormComponentComponent extends ArkComponent implements FormComponentAttribute { 18 constructor(nativePtr: KNode, classType?: ModifierType) { 19 super(nativePtr, classType); 20 } 21 size(value: { width: Length; height: Length }): this { 22 modifierWithKey(this._modifiersWithKeys, 23 FormComponentSizeModifier.identity, FormComponentSizeModifier, value); 24 return this; 25 } 26 27 visibility(value: Visibility): this { 28 modifierWithKey(this._modifiersWithKeys, 29 FormComponentVisibilityModifier.identity, FormComponentVisibilityModifier, value); 30 return this; 31 } 32 33 moduleName(value: string): this { 34 modifierWithKey(this._modifiersWithKeys, 35 FormComponentModuleNameModifier.identity, FormComponentModuleNameModifier, value); 36 return this; 37 } 38 dimension(value: FormDimension): this { 39 modifierWithKey(this._modifiersWithKeys, 40 FormComponentDimensionModifier.identity, FormComponentDimensionModifier, value); 41 return this; 42 } 43 allowUpdate(value: boolean): this { 44 modifierWithKey(this._modifiersWithKeys, 45 FormComponentAllowUpdateModifier.identity, FormComponentAllowUpdateModifier, value); 46 return this; 47 } 48 onAcquired(callback: (info: { id: number; }) => void): this { 49 throw new Error('Method not implemented.'); 50 } 51 onError(callback: (info: { errcode: number; msg: string; }) => void): this { 52 throw new Error('Method not implemented.'); 53 } 54 onRouter(callback: (info: any) => void): this { 55 throw new Error('Method not implemented.'); 56 } 57 onUninstall(callback: (info: { id: number; }) => void): this { 58 throw new Error('Method not implemented.'); 59 } 60 onLoad(callback: () => void): this { 61 throw new Error('Method not implemented.'); 62 } 63} 64 65class FormComponentModuleNameModifier extends ModifierWithKey<string> { 66 constructor(value: string) { 67 super(value); 68 } 69 static identity: Symbol = Symbol('formComponentModuleName'); 70 applyPeer(node: KNode, reset: boolean): void { 71 if (reset) { 72 getUINativeModule().formComponent.resetModuleName(node); 73 } else { 74 getUINativeModule().formComponent.setModuleName(node, this.value!); 75 } 76 } 77} 78 79class FormComponentDimensionModifier extends ModifierWithKey<FormDimension> { 80 constructor(value: FormDimension) { 81 super(value); 82 } 83 static identity: Symbol = Symbol('formComponentDimension'); 84 applyPeer(node: KNode, reset: boolean): void { 85 if (reset) { 86 getUINativeModule().formComponent.resetDimension(node); 87 } else { 88 getUINativeModule().formComponent.setDimension(node, this.value); 89 } 90 } 91 92 checkObjectDiff(): boolean { 93 return !isBaseOrResourceEqual(this.stageValue, this.value); 94 } 95} 96 97class FormComponentAllowUpdateModifier extends ModifierWithKey<boolean> { 98 constructor(value: boolean) { 99 super(value); 100 } 101 static identity: Symbol = Symbol('formComponentAllowUpdate'); 102 applyPeer(node: KNode, reset: boolean): void { 103 if (reset) { 104 getUINativeModule().formComponent.resetAllowUpdate(node); 105 } else { 106 getUINativeModule().formComponent.setAllowUpdate(node, this.value!); 107 } 108 } 109} 110 111class FormComponentSizeModifier extends ModifierWithKey<{ width: Length; height: Length }> { 112 constructor(value: { width: Length; height: Length }) { 113 super(value); 114 } 115 static identity: Symbol = Symbol('formComponentSize'); 116 applyPeer(node: KNode, reset: boolean): void { 117 if (reset) { 118 getUINativeModule().formComponent.resetSize(node); 119 } else { 120 getUINativeModule().formComponent.setSize(node, this.value.width, this.value.height); 121 } 122 } 123 124 checkObjectDiff(): boolean { 125 let widthEQ = isBaseOrResourceEqual(this.stageValue.width, this.value.width); 126 let heightEQ = isBaseOrResourceEqual(this.stageValue.height, this.value.height); 127 return !widthEQ || !heightEQ; 128 } 129} 130 131class FormComponentVisibilityModifier extends ModifierWithKey<Visibility> { 132 constructor(value: Visibility) { 133 super(value); 134 } 135 static identity: Symbol = Symbol('formComponentVisibility'); 136 applyPeer(node: KNode, reset: boolean): void { 137 if (reset) { 138 getUINativeModule().formComponent.resetVisibility(node); 139 } else { 140 getUINativeModule().formComponent.setVisibility(node, this.value); 141 } 142 } 143} 144 145// @ts-ignore 146globalThis.FormComponent.attributeModifier = function (modifier: ArkComponent): void { 147 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 148 return new ArkFormComponentComponent(nativePtr); 149 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 150 return new modifierJS.FormComponentModifier(nativePtr, classType); 151 }); 152}; 153