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 ListItemSelectedModifier extends ModifierWithKey<boolean> { 18 static identity: Symbol = Symbol('listItemSelected'); 19 applyPeer(node: KNode, reset: boolean): void { 20 if (reset) { 21 getUINativeModule().listItem.resetListItemSelected(node); 22 } else { 23 getUINativeModule().listItem.setListItemSelected(node, this.value!); 24 } 25 } 26} 27 28class ListItemSelectableModifier extends ModifierWithKey<boolean> { 29 static identity: Symbol = Symbol('listItemSelectable'); 30 applyPeer(node: KNode, reset: boolean): void { 31 if (reset) { 32 getUINativeModule().listItem.resetSelectable(node); 33 } else { 34 getUINativeModule().listItem.setSelectable(node, this.value!); 35 } 36 } 37} 38 39class ListItemSwipeActionModifier extends ModifierWithKey<SwipeActionOptions> { 40 constructor(value: SwipeActionOptions) { 41 super(value); 42 } 43 static identity: Symbol = Symbol('listItemSwipeAction'); 44 applyPeer(node: KNode, reset: boolean): void { 45 if (reset) { 46 getUINativeModule().listItem.resetSwipeAction(node); 47 } else { 48 getUINativeModule().listItem.setSwipeAction(node, this.value); 49 } 50 } 51 checkObjectDiff(): boolean { 52 return true; 53 } 54} 55 56class ArkListItemComponent extends ArkComponent implements ListItemAttribute { 57 constructor(nativePtr: KNode, classType?: ModifierType) { 58 super(nativePtr, classType); 59 } 60 initialize(value: Object[]): this { 61 return this; 62 } 63 sticky(value: Sticky): this { 64 throw new Error('Method not implemented.'); 65 } 66 editable(value: boolean | EditMode): this { 67 throw new Error('Method not implemented.'); 68 } 69 selectable(value: boolean): this { 70 modifierWithKey(this._modifiersWithKeys, ListItemSelectableModifier.identity, ListItemSelectableModifier, value); 71 return this; 72 } 73 selected(value: boolean): this { 74 modifierWithKey(this._modifiersWithKeys, ListItemSelectedModifier.identity, ListItemSelectedModifier, value); 75 return this; 76 } 77 swipeAction(value: SwipeActionOptions): this { 78 modifierWithKey(this._modifiersWithKeys, ListItemSwipeActionModifier.identity, ListItemSwipeActionModifier, value); 79 return this; 80 } 81 onSelect(event: (isSelected: boolean) => void): this { 82 throw new Error('Method not implemented.'); 83 } 84} 85 86// @ts-ignore 87globalThis.ListItem.attributeModifier = function (modifier: ArkComponent): void { 88 attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => { 89 return new ArkListItemComponent(nativePtr); 90 }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => { 91 return new modifierJS.ListItemModifier(nativePtr, classType); 92 }); 93}; 94