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 GridColSpanModifier extends ModifierWithKey<ArkGridColColumnOption> { 18 constructor(value: ArkGridColColumnOption) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('gridColSpan'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().gridCol.resetSpan(node); 25 } else { 26 if (isNumber(this.value)) { 27 getUINativeModule().gridCol.setSpan(node, this.value, 28 this.value, this.value, this.value, this.value, this.value); 29 } else { 30 getUINativeModule().gridCol.setSpan(node, this.value.xs, 31 this.value.sm, this.value.md, this.value.lg, this.value.xl, this.value.xxl); 32 } 33 } 34 } 35 checkObjectDiff(): boolean { 36 if (isNumber(this.stageValue) && isNumber(this.value)) { 37 return this.stageValue !== this.value; 38 } else if (isObject(this.stageValue) && isObject(this.value)) { 39 return this.stageValue.xs !== this.value.xs || 40 this.stageValue.sm !== this.value.sm || 41 this.stageValue.md !== this.value.md || 42 this.stageValue.lg !== this.value.lg || 43 this.stageValue.xl !== this.value.xl || 44 this.stageValue.xxl !== this.value.xxl; 45 } else { 46 return true; 47 } 48 } 49} 50class GridColOffsetModifier extends ModifierWithKey<ArkGridColColumnOption> { 51 constructor(value: ArkGridColColumnOption) { 52 super(value); 53 } 54 static identity: Symbol = Symbol('gridColOffset'); 55 applyPeer(node: KNode, reset: boolean): void { 56 if (reset) { 57 getUINativeModule().gridCol.resetGridColOffset(node); 58 } else { 59 if (isNumber(this.value)) { 60 getUINativeModule().gridCol.setGridColOffset(node, this.value, 61 this.value, this.value, this.value, this.value, this.value); 62 } else { 63 getUINativeModule().gridCol.setGridColOffset(node, this.value.xs, 64 this.value.sm, this.value.md, this.value.lg, this.value.xl, this.value.xxl); 65 } 66 } 67 } 68 checkObjectDiff(): boolean { 69 if (isNumber(this.stageValue) && isNumber(this.value)) { 70 return this.stageValue !== this.value; 71 } else if (isObject(this.stageValue) && isObject(this.value)) { 72 return this.stageValue.xs !== this.value.xs || 73 this.stageValue.sm !== this.value.sm || 74 this.stageValue.md !== this.value.md || 75 this.stageValue.lg !== this.value.lg || 76 this.stageValue.xl !== this.value.xl || 77 this.stageValue.xxl !== this.value.xxl; 78 } else { 79 return true; 80 } 81 } 82} 83class GridColOrderModifier extends ModifierWithKey<ArkGridColColumnOption> { 84 constructor(value: ArkGridColColumnOption) { 85 super(value); 86 } 87 static identity: Symbol = Symbol('gridColOrder'); 88 applyPeer(node: KNode, reset: boolean): void { 89 if (reset) { 90 getUINativeModule().gridCol.resetOrder(node); 91 } else { 92 if (isNumber(this.value)) { 93 getUINativeModule().gridCol.setOrder(node, this.value, 94 this.value, this.value, this.value, this.value, this.value); 95 } else { 96 getUINativeModule().gridCol.setOrder(node, this.value.xs, 97 this.value.sm, this.value.md, this.value.lg, this.value.xl, this.value.xxl); 98 } 99 } 100 } 101 checkObjectDiff(): boolean { 102 if (isNumber(this.stageValue) && isNumber(this.value)) { 103 return this.stageValue !== this.value; 104 } else if (isObject(this.stageValue) && isObject(this.value)) { 105 return this.stageValue.xs !== this.value.xs || 106 this.stageValue.sm !== this.value.sm || 107 this.stageValue.md !== this.value.md || 108 this.stageValue.lg !== this.value.lg || 109 this.stageValue.xl !== this.value.xl || 110 this.stageValue.xxl !== this.value.xxl; 111 } else { 112 return true; 113 } 114 } 115} 116 117class ArkGridColComponent extends ArkComponent implements GridColAttribute { 118 constructor(nativePtr: KNode) { 119 super(nativePtr); 120 } 121 span(value: number | GridColColumnOption): GridColAttribute { 122 modifierWithKey(this._modifiersWithKeys, GridColSpanModifier.identity, GridColSpanModifier, value); 123 return this; 124 } 125 gridColOffset(value: number | GridColColumnOption): GridColAttribute { 126 modifierWithKey(this._modifiersWithKeys, GridColOffsetModifier.identity, GridColOffsetModifier, value); 127 return this; 128 } 129 order(value: number | GridColColumnOption): GridColAttribute { 130 modifierWithKey(this._modifiersWithKeys, GridColOrderModifier.identity, GridColOrderModifier, value); 131 return this; 132 } 133} 134 135// @ts-ignore 136globalThis.GridCol.attributeModifier = function (modifier) { 137 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 138 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 139 140 let component = this.createOrGetNode(elmtId, () => { 141 return new ArkGridColComponent(nativeNode); 142 }); 143 applyUIAttributes(modifier, nativeNode, component); 144 component.applyModifierPatch(); 145}; 146