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} 38class ArkListItemComponent extends ArkComponent implements ListItemAttribute { 39 constructor(nativePtr: KNode) { 40 super(nativePtr); 41 } 42 sticky(value: Sticky): this { 43 throw new Error('Method not implemented.'); 44 } 45 editable(value: boolean | EditMode): this { 46 throw new Error('Method not implemented.'); 47 } 48 selectable(value: boolean): this { 49 modifierWithKey(this._modifiersWithKeys, ListItemSelectableModifier.identity, ListItemSelectableModifier, value); 50 return this; 51 } 52 selected(value: boolean): this { 53 modifierWithKey(this._modifiersWithKeys, ListItemSelectedModifier.identity, ListItemSelectedModifier, value); 54 return this; 55 } 56 swipeAction(value: SwipeActionOptions): this { 57 throw new Error('Method not implemented.'); 58 } 59 onSelect(event: (isSelected: boolean) => void): this { 60 throw new Error('Method not implemented.'); 61 } 62} 63 64// @ts-ignore 65globalThis.ListItem.attributeModifier = function (modifier) { 66 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 67 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 68 let component = this.createOrGetNode(elmtId, () => { 69 return new ArkListItemComponent(nativeNode); 70 }); 71 applyUIAttributes(modifier, nativeNode, component); 72 component.applyModifierPatch(); 73}; 74