• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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/**
17 * 通过实现AttributeModifier接口,自定义属性修改器
18 * 将拖拽排序相关样式封装成属性修改器,可以方便移植
19 */
20export class ListItemModifier implements AttributeModifier<ListItemAttribute> {
21  // 阴影
22  public hasShadow: boolean = false;
23  // 缩放
24  public scale: number = 1;
25  // 纵轴偏移量
26  public offsetY: number = 0;
27  // 横轴偏移量
28  public offsetX: number = 0;
29  // 透明度
30  public opacity: number = 1;
31  // 是否被删除
32  public isDeleted: boolean = false;
33  public static instance: ListItemModifier | null = null;
34
35  public static getInstance(): ListItemModifier {
36    if (!ListItemModifier.instance) {
37      ListItemModifier.instance = new ListItemModifier();
38    }
39    return ListItemModifier.instance;
40  }
41
42  /**
43   * 定义组件普通状态时的样式
44   * @param instance: ListItem属性
45   */
46  applyNormalAttribute(instance: ListItemAttribute): void {
47    if (this.hasShadow) {
48      instance.shadow({ radius: $r('app.integer.list_exchange_shadow_radius'), color: $r('app.color.list_exchange_box_shadow') });
49      instance.zIndex(1);
50      instance.opacity(0.5);
51    } else {
52      instance.opacity(this.opacity);
53    }
54    instance.translate({ x: this.offsetX, y: this.offsetY });
55    instance.scale({ x: this.scale, y: this.scale });
56  }
57}