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 ListEditModeModifier extends ModifierWithKey<boolean> { 18 constructor(value: boolean) { 19 super(value); 20 } 21 static identity: Symbol = Symbol('editMode'); 22 applyPeer(node: KNode, reset: boolean): void { 23 if (reset) { 24 getUINativeModule().list.resetEditMode(node); 25 } else { 26 getUINativeModule().list.setEditMode(node, this.value!); 27 } 28 } 29} 30 31class ListMultiSelectableModifier extends ModifierWithKey<boolean> { 32 constructor(value: boolean) { 33 super(value); 34 } 35 static identity: Symbol = Symbol('listMultiSelectable'); 36 applyPeer(node: KNode, reset: boolean): void { 37 if (reset) { 38 getUINativeModule().list.resetMultiSelectable(node); 39 } else { 40 getUINativeModule().list.setMultiSelectable(node, this.value!); 41 } 42 } 43} 44 45class ListAlignListItemModifier extends ModifierWithKey<ListItemAlign> { 46 constructor(value: ListItemAlign) { 47 super(value); 48 } 49 static identity: Symbol = Symbol('listAlignListItem'); 50 applyPeer(node: KNode, reset: boolean): void { 51 if (reset) { 52 getUINativeModule().list.resetAlignListItem(node); 53 } else { 54 getUINativeModule().list.setAlignListItem(node, this.value!); 55 } 56 } 57} 58 59class ListScrollSnapAlignModifier extends ModifierWithKey<ScrollSnapAlign> { 60 constructor(value: ScrollSnapAlign) { 61 super(value); 62 } 63 static identity: Symbol = Symbol('listScrollSnapAlign'); 64 applyPeer(node: KNode, reset: boolean): void { 65 if (reset) { 66 getUINativeModule().list.resetScrollSnapAlign(node); 67 } else { 68 getUINativeModule().list.setScrollSnapAlign(node, this.value!); 69 } 70 } 71} 72 73class ContentStartOffsetModifier extends ModifierWithKey<number> { 74 constructor(value: number) { 75 super(value); 76 } 77 static identity: Symbol = Symbol('contentStartOffset'); 78 applyPeer(node: KNode, reset: boolean): void { 79 if (reset) { 80 getUINativeModule().list.resetContentStartOffset(node); 81 } else { 82 getUINativeModule().list.setContentStartOffset(node, this.value); 83 } 84 } 85} 86 87class ContentEndOffsetModifier extends ModifierWithKey<number> { 88 constructor(value: number) { 89 super(value); 90 } 91 static identity: Symbol = Symbol('contentEndOffset'); 92 applyPeer(node: KNode, reset: boolean): void { 93 if (reset) { 94 getUINativeModule().list.resetContentEndOffset(node); 95 } else { 96 getUINativeModule().list.setContentEndOffset(node, this.value); 97 } 98 } 99} 100 101class ListDividerModifier extends ModifierWithKey<DividerStyle> { 102 constructor(value: DividerStyle) { 103 super(value); 104 } 105 static identity: Symbol = Symbol('listDivider'); 106 applyPeer(node: KNode, reset: boolean): void { 107 if (reset) { 108 getUINativeModule().list.resetDivider(node); 109 } else { 110 getUINativeModule().list.setDivider(node, this.value?.strokeWidth!, this.value?.color, this.value?.startMargin, this.value?.endMargin); 111 } 112 } 113 114 checkObjectDiff(): boolean { 115 return !(this.stageValue?.strokeWidth === this.value?.strokeWidth && 116 this.stageValue?.color === this.value?.color && 117 this.stageValue?.startMargin === this.value?.startMargin && 118 this.stageValue?.endMargin === this.value?.endMargin); 119 } 120} 121 122class ChainAnimationOptionsModifier extends ModifierWithKey<ChainAnimationOptions> { 123 constructor(value: ChainAnimationOptions) { 124 super(value); 125 } 126 static identity: Symbol = Symbol('chainAnimationOptions'); 127 applyPeer(node: KNode, reset: boolean): void { 128 if (reset) { 129 getUINativeModule().list.resetChainAnimationOptions(node); 130 } else { 131 getUINativeModule().list.setChainAnimationOptions(node, this.value?.minSpace!, 132 this.value?.maxSpace!, this.value?.conductivity, this.value?.intensity, 133 this.value?.edgeEffect, this.value?.stiffness, this.value?.damping); 134 } 135 } 136 137 checkObjectDiff(): boolean { 138 return !(this.stageValue.minSpace === this.value.minSpace && this.stageValue.maxSpace === this.value.maxSpace && 139 this.stageValue.conductivity === this.value.conductivity && this.stageValue.intensity === this.value.intensity && 140 this.stageValue.edgeEffect === this.value.edgeEffect && this.stageValue.stiffness === this.value.stiffness && 141 this.stageValue.damping === this.value.damping); 142 } 143} 144 145class ListChainAnimationModifier extends ModifierWithKey<boolean> { 146 constructor(value: boolean) { 147 super(value); 148 } 149 static identity: Symbol = Symbol('listChainAnimation'); 150 applyPeer(node: KNode, reset: boolean): void { 151 if (reset) { 152 getUINativeModule().list.resetChainAnimation(node); 153 } else { 154 getUINativeModule().list.setChainAnimation(node, this.value!); 155 } 156 } 157} 158 159class ListCachedCountModifier extends ModifierWithKey<number> { 160 constructor(value: number) { 161 super(value); 162 } 163 static identity: Symbol = Symbol('listCachedCount'); 164 applyPeer(node: KNode, reset: boolean): void { 165 if (reset) { 166 getUINativeModule().list.resetCachedCount(node); 167 } else { 168 getUINativeModule().list.setCachedCount(node, this.value!); 169 } 170 } 171} 172 173class ListEnableScrollInteractionModifier extends ModifierWithKey<boolean> { 174 constructor(value: boolean) { 175 super(value); 176 } 177 static identity: Symbol = Symbol('listEnableScrollInteraction'); 178 applyPeer(node: KNode, reset: boolean): void { 179 if (reset) { 180 getUINativeModule().list.resetEnableScrollInteraction(node); 181 } else { 182 getUINativeModule().list.setEnableScrollInteraction(node, this.value!); 183 } 184 } 185} 186 187class ListStickyModifier extends ModifierWithKey<number> { 188 constructor(value: number) { 189 super(value); 190 } 191 static identity: Symbol = Symbol('listSticky'); 192 applyPeer(node: KNode, reset: boolean): void { 193 if (reset) { 194 getUINativeModule().list.resetSticky(node); 195 } else { 196 getUINativeModule().list.setSticky(node, this.value!); 197 } 198 } 199} 200 201class ListEdgeEffectModifier extends ModifierWithKey<ArkListEdgeEffect> { 202 constructor(value: ArkListEdgeEffect) { 203 super(value); 204 } 205 static identity: Symbol = Symbol('listEdgeEffect'); 206 applyPeer(node: KNode, reset: boolean): void { 207 if (reset) { 208 getUINativeModule().list.resetListEdgeEffect(node); 209 } else { 210 getUINativeModule().list.setListEdgeEffect(node, this.value.value!, this.value.options?.alwaysEnabled); 211 } 212 } 213 checkObjectDiff(): boolean { 214 return !((this.stageValue.value === this.value.value) && 215 (this.stageValue.options === this.value.options)); 216 } 217} 218 219class ListListDirectionModifier extends ModifierWithKey<number> { 220 constructor(value: number) { 221 super(value); 222 } 223 static identity: Symbol = Symbol('listListDirection'); 224 applyPeer(node: KNode, reset: boolean): void { 225 if (reset) { 226 getUINativeModule().list.resetListDirection(node); 227 } else { 228 getUINativeModule().list.setListDirection(node, this.value!); 229 } 230 } 231} 232 233class ListFrictionModifier extends ModifierWithKey<number | Resource> { 234 constructor(value: number | Resource) { 235 super(value); 236 } 237 static identity: Symbol = Symbol('listFriction'); 238 applyPeer(node: KNode, reset: boolean): void { 239 if (reset) { 240 getUINativeModule().list.resetListFriction(node); 241 } else { 242 if (!isNumber(this.value) && !isResource(this.value)) { 243 getUINativeModule().list.resetListFriction(node); 244 } else { 245 getUINativeModule().list.setListFriction(node, this.value); 246 } 247 } 248 } 249 250 checkObjectDiff(): boolean { 251 return !isBaseOrResourceEqual(this.stageValue, this.value); 252 } 253} 254 255class ListNestedScrollModifier extends ModifierWithKey<NestedScrollOptions> { 256 constructor(value: NestedScrollOptions) { 257 super(value); 258 } 259 static identity: Symbol = Symbol('listNestedScroll'); 260 applyPeer(node: KNode, reset: boolean): void { 261 if (reset) { 262 getUINativeModule().list.resetListNestedScroll(node); 263 } else { 264 getUINativeModule().list.setListNestedScroll(node, this.value?.scrollForward, this.value?.scrollBackward); 265 } 266 } 267} 268 269class ListScrollBarModifier extends ModifierWithKey<number> { 270 constructor(value: number) { 271 super(value); 272 } 273 static identity: Symbol = Symbol('listScrollBar'); 274 applyPeer(node: KNode, reset: boolean): void { 275 if (reset) { 276 getUINativeModule().list.resetListScrollBar(node); 277 } else { 278 getUINativeModule().list.setListScrollBar(node, this.value!); 279 } 280 } 281} 282 283class ListLanesModifier extends ModifierWithKey<ArkLanesOpt> { 284 constructor(value: ArkLanesOpt) { 285 super(value); 286 } 287 static identity: Symbol = Symbol('listLanes'); 288 applyPeer(node: KNode, reset: boolean): void { 289 if (reset) { 290 getUINativeModule().list.resetListLanes(node); 291 } else { 292 getUINativeModule().list.setListLanes(node, this.value.lanesNum, 293 this.value.minLength, this.value.maxLength, this.value.gutter); 294 } 295 } 296 checkObjectDiff(): boolean { 297 return true; 298 } 299} 300 301class ListClipModifier extends ModifierWithKey<boolean | object> { 302 constructor(value: boolean | object) { 303 super(value); 304 } 305 static identity: Symbol = Symbol('listClip'); 306 applyPeer(node: KNode, reset: boolean): void { 307 if (reset) { 308 getUINativeModule().common.resetClipWithEdge(node); 309 } else { 310 getUINativeModule().common.setClipWithEdge(node, this.value); 311 } 312 } 313 checkObjectDiff(): boolean { 314 return true; 315 } 316} 317 318class ArkListComponent extends ArkComponent implements ListAttribute { 319 constructor(nativePtr: KNode) { 320 super(nativePtr); 321 } 322 lanes(value: number | LengthConstrain, gutter?: any): this { 323 let opt: ArkLanesOpt = new ArkLanesOpt(); 324 opt.gutter = gutter; 325 if (isUndefined(value)) { 326 opt.lanesNum = undefined; 327 } else if (isNumber(value)) { 328 opt.lanesNum = value as number; 329 } else { 330 const lc = value as LengthConstrain; 331 opt.minLength = lc.minLength; 332 opt.maxLength = lc.maxLength; 333 } 334 modifierWithKey(this._modifiersWithKeys, ListLanesModifier.identity, ListLanesModifier, opt); 335 return this; 336 } 337 alignListItem(value: ListItemAlign): this { 338 modifierWithKey(this._modifiersWithKeys, ListAlignListItemModifier.identity, ListAlignListItemModifier, value); 339 return this; 340 } 341 listDirection(value: Axis): this { 342 modifierWithKey(this._modifiersWithKeys, ListListDirectionModifier.identity, ListListDirectionModifier, value); 343 return this; 344 } 345 scrollBar(value: BarState): this { 346 modifierWithKey(this._modifiersWithKeys, ListScrollBarModifier.identity, ListScrollBarModifier, value); 347 return this; 348 } 349 edgeEffect(value: EdgeEffect, options?: EdgeEffectOptions | undefined): this { 350 let effect: ArkListEdgeEffect = new ArkListEdgeEffect(); 351 effect.value = value; 352 effect.options = options; 353 modifierWithKey(this._modifiersWithKeys, ListEdgeEffectModifier.identity, ListEdgeEffectModifier, effect); 354 return this; 355 } 356 contentStartOffset(value: number): this { 357 modifierWithKey(this._modifiersWithKeys, ContentStartOffsetModifier.identity, ContentStartOffsetModifier, value); 358 return this; 359 } 360 contentEndOffset(value: number): this { 361 modifierWithKey(this._modifiersWithKeys, ContentEndOffsetModifier.identity, ContentEndOffsetModifier, value); 362 return this; 363 } 364 divider(value: { strokeWidth: any; color?: any; startMargin?: any; endMargin?: any; } | null): this { 365 modifierWithKey(this._modifiersWithKeys, ListDividerModifier.identity, ListDividerModifier, value); 366 return this; 367 } 368 editMode(value: boolean): this { 369 modifierWithKey(this._modifiersWithKeys, ListEditModeModifier.identity, ListEditModeModifier, value); 370 return this; 371 } 372 multiSelectable(value: boolean): this { 373 modifierWithKey(this._modifiersWithKeys, ListMultiSelectableModifier.identity, ListMultiSelectableModifier, value); 374 return this; 375 } 376 cachedCount(value: number): this { 377 modifierWithKey(this._modifiersWithKeys, ListCachedCountModifier.identity, ListCachedCountModifier, value); 378 return this; 379 } 380 chainAnimation(value: boolean): this { 381 modifierWithKey(this._modifiersWithKeys, ListChainAnimationModifier.identity, ListChainAnimationModifier, value); 382 return this; 383 } 384 chainAnimationOptions(value: ChainAnimationOptions): this { 385 modifierWithKey(this._modifiersWithKeys, ChainAnimationOptionsModifier.identity, ChainAnimationOptionsModifier, value); 386 return this; 387 } 388 sticky(value: StickyStyle): this { 389 modifierWithKey(this._modifiersWithKeys, ListStickyModifier.identity, ListStickyModifier, value); 390 return this; 391 } 392 scrollSnapAlign(value: ScrollSnapAlign): this { 393 modifierWithKey(this._modifiersWithKeys, ListScrollSnapAlignModifier.identity, ListScrollSnapAlignModifier, value); 394 return this; 395 } 396 nestedScroll(value: NestedScrollOptions): this { 397 modifierWithKey(this._modifiersWithKeys, ListNestedScrollModifier.identity, ListNestedScrollModifier, value); 398 return this; 399 } 400 enableScrollInteraction(value: boolean): this { 401 modifierWithKey(this._modifiersWithKeys, ListEnableScrollInteractionModifier.identity, ListEnableScrollInteractionModifier, value); 402 return this; 403 } 404 friction(value: any): this { 405 modifierWithKey(this._modifiersWithKeys, ListFrictionModifier.identity, ListFrictionModifier, value); 406 return this; 407 } 408 clip(value: boolean | CircleAttribute | EllipseAttribute | PathAttribute | RectAttribute): this { 409 modifierWithKey(this._modifiersWithKeys, ListClipModifier.identity, ListClipModifier, value); 410 return this; 411 } 412 onScroll(event: (scrollOffset: number, scrollState: ScrollState) => void): this { 413 throw new Error('Method not implemented.'); 414 } 415 onScrollIndex(event: (start: number, end: number, center: number) => void): this { 416 throw new Error('Method not implemented.'); 417 } 418 onReachStart(event: () => void): this { 419 throw new Error('Method not implemented.'); 420 } 421 onReachEnd(event: () => void): this { 422 throw new Error('Method not implemented.'); 423 } 424 onScrollStart(event: () => void): this { 425 throw new Error('Method not implemented.'); 426 } 427 onScrollStop(event: () => void): this { 428 throw new Error('Method not implemented.'); 429 } 430 onItemDelete(event: (index: number) => boolean): this { 431 throw new Error('Method not implemented.'); 432 } 433 onItemMove(event: (from: number, to: number) => boolean): this { 434 throw new Error('Method not implemented.'); 435 } 436 onItemDragStart(event: (event: ItemDragInfo, itemIndex: number) => void | (() => any)): this { 437 throw new Error('Method not implemented.'); 438 } 439 onItemDragEnter(event: (event: ItemDragInfo) => void): this { 440 throw new Error('Method not implemented.'); 441 } 442 onItemDragMove(event: (event: ItemDragInfo, itemIndex: number, insertIndex: number) => void): this { 443 throw new Error('Method not implemented.'); 444 } 445 onItemDragLeave(event: (event: ItemDragInfo, itemIndex: number) => void): this { 446 throw new Error('Method not implemented.'); 447 } 448 onItemDrop(event: (event: ItemDragInfo, itemIndex: number, insertIndex: number, isSuccess: boolean) => void): this { 449 throw new Error('Method not implemented.'); 450 } 451 onScrollFrameBegin(event: (offset: number, state: ScrollState) => { offsetRemain: number; }): this { 452 throw new Error('Method not implemented.'); 453 } 454} 455 456// @ts-ignore 457globalThis.List.attributeModifier = function (modifier) { 458 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 459 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 460 let component = this.createOrGetNode(elmtId, () => { 461 return new ArkListComponent(nativeNode); 462 }); 463 applyUIAttributes(modifier, nativeNode, component); 464 component.applyModifierPatch(); 465}; 466