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 ArkGridComponent extends ArkComponent implements GridAttribute { 18 constructor(nativePtr: KNode) { 19 super(nativePtr); 20 } 21 columnsTemplate(value: string): this { 22 modifierWithKey(this._modifiersWithKeys, GridColumnsTemplateModifier.identity, GridColumnsTemplateModifier, value); 23 return this; 24 } 25 rowsTemplate(value: string): this { 26 modifierWithKey(this._modifiersWithKeys, GridRowsTemplateModifier.identity, GridRowsTemplateModifier, value); 27 return this; 28 } 29 columnsGap(value: Length): this { 30 modifierWithKey(this._modifiersWithKeys, GridColumnsGapModifier.identity, GridColumnsGapModifier, value); 31 return this; 32 } 33 rowsGap(value: Length): this { 34 modifierWithKey(this._modifiersWithKeys, GridRowsGapModifier.identity, GridRowsGapModifier, value); 35 return this; 36 } 37 scrollBarWidth(value: string | number): this { 38 modifierWithKey(this._modifiersWithKeys, GridScrollBarWidthModifier.identity, GridScrollBarWidthModifier, value); 39 return this; 40 } 41 scrollBarColor(value: string | number | Color): this { 42 modifierWithKey(this._modifiersWithKeys, GridScrollBarColorModifier.identity, GridScrollBarColorModifier, value); 43 return this; 44 } 45 scrollBar(value: BarState): this { 46 modifierWithKey(this._modifiersWithKeys, GridScrollBarModifier.identity, GridScrollBarModifier, value); 47 return this; 48 } 49 onScrollBarUpdate(event: (index: number, offset: number) => ComputedBarAttribute): this { 50 throw new Error('Method not implemented.'); 51 } 52 onScrollIndex(event: (first: number, last: number) => void): this { 53 throw new Error('Method not implemented.'); 54 } 55 cachedCount(value: number): this { 56 modifierWithKey(this._modifiersWithKeys, GridCachedCountModifier.identity, GridCachedCountModifier, value); 57 return this; 58 } 59 editMode(value: boolean): this { 60 modifierWithKey(this._modifiersWithKeys, GridEditModeModifier.identity, GridEditModeModifier, value); 61 return this; 62 } 63 multiSelectable(value: boolean): this { 64 modifierWithKey(this._modifiersWithKeys, GridMultiSelectableModifier.identity, GridMultiSelectableModifier, value); 65 return this; 66 } 67 maxCount(value: number): this { 68 modifierWithKey(this._modifiersWithKeys, GridMaxCountModifier.identity, GridMaxCountModifier, value); 69 return this; 70 } 71 minCount(value: number): this { 72 modifierWithKey(this._modifiersWithKeys, GridMinCountModifier.identity, GridMinCountModifier, value); 73 return this; 74 } 75 cellLength(value: number): this { 76 modifierWithKey(this._modifiersWithKeys, GridCellLengthModifier.identity, GridCellLengthModifier, value); 77 return this; 78 } 79 layoutDirection(value: GridDirection): this { 80 modifierWithKey(this._modifiersWithKeys, GridLayoutDirectionModifier.identity, GridLayoutDirectionModifier, value); 81 return this; 82 } 83 supportAnimation(value: boolean): this { 84 modifierWithKey(this._modifiersWithKeys, GridSupportAnimationModifier.identity, GridSupportAnimationModifier, value); 85 return this; 86 } 87 onItemDragStart(event: (event: ItemDragInfo, itemIndex: number) => void | (() => any)): this { 88 throw new Error('Method not implemented.'); 89 } 90 onItemDragEnter(event: (event: ItemDragInfo) => void): this { 91 throw new Error('Method not implemented.'); 92 } 93 onItemDragMove(event: (event: ItemDragInfo, itemIndex: number, insertIndex: number) => void): this { 94 throw new Error('Method not implemented.'); 95 } 96 onItemDragLeave(event: (event: ItemDragInfo, itemIndex: number) => void): this { 97 throw new Error('Method not implemented.'); 98 } 99 onItemDrop(event: (event: ItemDragInfo, itemIndex: number, insertIndex: number, isSuccess: boolean) => void): this { 100 throw new Error('Method not implemented.'); 101 } 102 edgeEffect(value: EdgeEffect, options?: EdgeEffectOptions | undefined): this { 103 let effect: ArkGridEdgeEffect = new ArkGridEdgeEffect(); 104 effect.value = value; 105 effect.options = options; 106 modifierWithKey(this._modifiersWithKeys, GridEdgeEffectModifier.identity, GridEdgeEffectModifier, effect); 107 return this; 108 } 109 nestedScroll(value: NestedScrollOptions): this { 110 modifierWithKey(this._modifiersWithKeys, GridNestedScrollModifier.identity, GridNestedScrollModifier, value); 111 return this; 112 } 113 enableScrollInteraction(value: boolean): this { 114 modifierWithKey(this._modifiersWithKeys, GridEnableScrollModifier.identity, GridEnableScrollModifier, value); 115 return this; 116 } 117 friction(value: number | Resource): this { 118 modifierWithKey(this._modifiersWithKeys, GridFrictionModifier.identity, GridFrictionModifier, value); 119 return this; 120 } 121 onScroll(event: (scrollOffset: number, scrollState: ScrollState) => void): this { 122 throw new Error('Method not implemented.'); 123 } 124 onReachStart(event: () => void): this { 125 throw new Error('Method not implemented.'); 126 } 127 onReachEnd(event: () => void): this { 128 throw new Error('Method not implemented.'); 129 } 130 onScrollStart(event: () => void): this { 131 throw new Error('Method not implemented.'); 132 } 133 onScrollStop(event: () => void): this { 134 throw new Error('Method not implemented.'); 135 } 136 onScrollFrameBegin(event: (offset: number, state: ScrollState) => { offsetRemain: number; }): this { 137 throw new Error('Method not implemented.'); 138 } 139 clip(value: boolean | CircleAttribute | EllipseAttribute | PathAttribute | RectAttribute): this { 140 modifierWithKey(this._modifiersWithKeys, GridClipModifier.identity, GridClipModifier, value); 141 return this; 142 } 143} 144 145class GridColumnsTemplateModifier extends ModifierWithKey<string> { 146 constructor(value: string) { 147 super(value); 148 } 149 static identity: Symbol = Symbol('gridColumnsTemplate'); 150 applyPeer(node: KNode, reset: boolean): void { 151 if (reset) { 152 getUINativeModule().grid.resetColumnsTemplate(node); 153 } else { 154 getUINativeModule().grid.setColumnsTemplate(node, this.value); 155 } 156 } 157} 158 159class GridRowsTemplateModifier extends ModifierWithKey<string> { 160 constructor(value: string) { 161 super(value); 162 } 163 static identity: Symbol = Symbol('gridRowsTemplate'); 164 applyPeer(node: KNode, reset: boolean): void { 165 if (reset) { 166 getUINativeModule().grid.resetRowsTemplate(node); 167 } else { 168 getUINativeModule().grid.setRowsTemplate(node, this.value); 169 } 170 } 171} 172 173class GridColumnsGapModifier extends ModifierWithKey<Length> { 174 constructor(value: Length) { 175 super(value); 176 } 177 static identity: Symbol = Symbol('gridColumnsGap'); 178 applyPeer(node: KNode, reset: boolean): void { 179 if (reset) { 180 getUINativeModule().grid.resetColumnsGap(node); 181 } else { 182 getUINativeModule().grid.setColumnsGap(node, this.value!); 183 } 184 } 185 checkObjectDiff(): boolean { 186 return !isBaseOrResourceEqual(this.stageValue, this.value); 187 } 188} 189 190class GridRowsGapModifier extends ModifierWithKey<Length> { 191 constructor(value: Length) { 192 super(value); 193 } 194 static identity: Symbol = Symbol('gridRowsGap'); 195 applyPeer(node: KNode, reset: boolean): void { 196 if (reset) { 197 getUINativeModule().grid.resetRowsGap(node); 198 } else { 199 getUINativeModule().grid.setRowsGap(node, this.value!); 200 } 201 } 202 checkObjectDiff(): boolean { 203 return !isBaseOrResourceEqual(this.stageValue, this.value); 204 } 205} 206 207class GridScrollBarWidthModifier extends ModifierWithKey<string | number> { 208 constructor(value: string | number) { 209 super(value); 210 } 211 static identity: Symbol = Symbol('gridScrollBarWidth'); 212 applyPeer(node: KNode, reset: boolean): void { 213 if (reset) { 214 getUINativeModule().grid.resetScrollBarWidth(node); 215 } else { 216 getUINativeModule().grid.setScrollBarWidth(node, this.value); 217 } 218 } 219} 220 221class GridScrollBarModifier extends ModifierWithKey<BarState> { 222 constructor(value: BarState) { 223 super(value); 224 } 225 static identity: Symbol = Symbol('gridScrollBar'); 226 applyPeer(node: KNode, reset: boolean): void { 227 if (reset) { 228 getUINativeModule().grid.resetScrollBar(node); 229 } else { 230 getUINativeModule().grid.setScrollBar(node, this.value); 231 } 232 } 233} 234 235class GridScrollBarColorModifier extends ModifierWithKey<string | number | Color> { 236 constructor(value: string | number | Color) { 237 super(value); 238 } 239 static identity: Symbol = Symbol('gridScrollBarColor'); 240 applyPeer(node: KNode, reset: boolean): void { 241 if (reset) { 242 getUINativeModule().grid.resetScrollBarColor(node); 243 } else { 244 getUINativeModule().grid.setScrollBarColor(node, this.value); 245 } 246 } 247} 248 249class GridEditModeModifier extends ModifierWithKey<boolean> { 250 constructor(value: boolean) { 251 super(value); 252 } 253 static identity: Symbol = Symbol('gridEditMode'); 254 applyPeer(node: KNode, reset: boolean): void { 255 if (reset) { 256 getUINativeModule().grid.resetEditMode(node); 257 } else { 258 getUINativeModule().grid.setEditMode(node, this.value); 259 } 260 } 261} 262 263class GridCachedCountModifier extends ModifierWithKey<number> { 264 constructor(value: number) { 265 super(value); 266 } 267 static identity: Symbol = Symbol('gridCachedCount'); 268 applyPeer(node: KNode, reset: boolean): void { 269 if (reset) { 270 getUINativeModule().grid.resetCachedCount(node); 271 } else { 272 getUINativeModule().grid.setCachedCount(node, this.value); 273 } 274 } 275} 276 277class GridMultiSelectableModifier extends ModifierWithKey<boolean> { 278 constructor(value: boolean) { 279 super(value); 280 } 281 static identity: Symbol = Symbol('gridMultiSelectable'); 282 applyPeer(node: KNode, reset: boolean): void { 283 if (reset) { 284 getUINativeModule().grid.resetMultiSelectable(node); 285 } else { 286 getUINativeModule().grid.setMultiSelectable(node, this.value); 287 } 288 } 289} 290 291class GridEdgeEffectModifier extends ModifierWithKey<ArkGridEdgeEffect> { 292 constructor(value: ArkGridEdgeEffect) { 293 super(value); 294 } 295 static identity: Symbol = Symbol('gridEdgeEffect'); 296 applyPeer(node: KNode, reset: boolean): void { 297 if (reset) { 298 getUINativeModule().grid.resetEdgeEffect(node); 299 } else { 300 getUINativeModule().grid.setEdgeEffect(node, this.value?.value, this.value.options?.alwaysEnabled); 301 } 302 } 303 304 checkObjectDiff(): boolean { 305 return !((this.stageValue.value === this.value.value) && 306 (this.stageValue.options === this.value.options)); 307 } 308} 309 310class GridNestedScrollModifier extends ModifierWithKey<NestedScrollOptions> { 311 constructor(value: NestedScrollOptions) { 312 super(value); 313 } 314 static identity: Symbol = Symbol('gridNestedScroll'); 315 applyPeer(node: KNode, reset: boolean): void { 316 if (reset) { 317 getUINativeModule().grid.resetNestedScroll(node); 318 } else { 319 getUINativeModule().grid.setNestedScroll(node, this.value?.scrollForward, this.value?.scrollBackward); 320 } 321 } 322 323 checkObjectDiff(): boolean { 324 return !((this.stageValue.scrollForward === this.value.scrollForward) && 325 (this.stageValue.scrollBackward === this.value.scrollBackward)); 326 } 327} 328 329class GridEnableScrollModifier extends ModifierWithKey<boolean> { 330 constructor(value: boolean) { 331 super(value); 332 } 333 static identity: Symbol = Symbol('gridEnableScroll'); 334 applyPeer(node: KNode, reset: boolean): void { 335 if (reset) { 336 getUINativeModule().grid.resetEnableScroll(node); 337 } else { 338 getUINativeModule().grid.setEnableScroll(node, this.value); 339 } 340 } 341} 342 343class GridFrictionModifier extends ModifierWithKey<number | Resource> { 344 constructor(value: number | Resource) { 345 super(value); 346 } 347 static identity: Symbol = Symbol('gridFriction'); 348 applyPeer(node: KNode, reset: boolean): void { 349 if (reset) { 350 getUINativeModule().grid.resetFriction(node); 351 } else { 352 getUINativeModule().grid.setFriction(node, this.value); 353 } 354 } 355 356 checkObjectDiff(): boolean { 357 return !isBaseOrResourceEqual(this.stageValue, this.value); 358 } 359} 360 361class GridMaxCountModifier extends ModifierWithKey<number> { 362 constructor(value: number) { 363 super(value); 364 } 365 static identity: Symbol = Symbol('gridMaxCount'); 366 applyPeer(node: KNode, reset: boolean): void { 367 if (reset) { 368 getUINativeModule().grid.resetMaxCount(node); 369 } else { 370 getUINativeModule().grid.setMaxCount(node, this.value); 371 } 372 } 373} 374 375class GridMinCountModifier extends ModifierWithKey<number> { 376 constructor(value: number) { 377 super(value); 378 } 379 static identity: Symbol = Symbol('gridMinCount'); 380 applyPeer(node: KNode, reset: boolean): void { 381 if (reset) { 382 getUINativeModule().grid.resetMinCount(node); 383 } else { 384 getUINativeModule().grid.setMinCount(node, this.value); 385 } 386 } 387} 388 389class GridCellLengthModifier extends ModifierWithKey<number> { 390 constructor(value: number) { 391 super(value); 392 } 393 static identity: Symbol = Symbol('gridCellLength'); 394 applyPeer(node: KNode, reset: boolean): void { 395 if (reset) { 396 getUINativeModule().grid.resetCellLength(node); 397 } else { 398 getUINativeModule().grid.setCellLength(node, this.value); 399 } 400 } 401} 402 403class GridLayoutDirectionModifier extends ModifierWithKey<GridDirection> { 404 constructor(value: GridDirection) { 405 super(value); 406 } 407 static identity: Symbol = Symbol('gridLayoutDirection'); 408 applyPeer(node: KNode, reset: boolean): void { 409 if (reset) { 410 getUINativeModule().grid.resetLayoutDirection(node); 411 } else { 412 getUINativeModule().grid.setLayoutDirection(node, this.value); 413 } 414 } 415} 416 417class GridSupportAnimationModifier extends ModifierWithKey<boolean> { 418 constructor(value: boolean) { 419 super(value); 420 } 421 static identity: Symbol = Symbol('gridSupportAnimation'); 422 applyPeer(node: KNode, reset: boolean): void { 423 if (reset) { 424 getUINativeModule().grid.resetSupportAnimation(node); 425 } else { 426 getUINativeModule().grid.setSupportAnimation(node, this.value); 427 } 428 } 429} 430 431class GridClipModifier extends ModifierWithKey<boolean | object> { 432 constructor(value: boolean | object) { 433 super(value); 434 } 435 static identity: Symbol = Symbol('gridClip'); 436 applyPeer(node: KNode, reset: boolean): void { 437 if (reset) { 438 getUINativeModule().common.resetClipWithEdge(node); 439 } else { 440 getUINativeModule().common.setClipWithEdge(node, this.value); 441 } 442 } 443 checkObjectDiff(): boolean { 444 return true; 445 } 446} 447 448// @ts-ignore 449globalThis.Grid.attributeModifier = function (modifier) { 450 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 451 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 452 let component = this.createOrGetNode(elmtId, () => { 453 return new ArkGridComponent(nativeNode); 454 }); 455 applyUIAttributes(modifier, nativeNode, component); 456 component.applyModifierPatch(); 457}; 458