• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ListItemGroupInitializeModifier extends ModifierWithKey<ListItemGroupParam> {
18  constructor(value: ListItemGroupParam) {
19    super(value);
20  }
21  static identity: Symbol = Symbol('listItemGroupinitialize');
22  applyPeer(node: KNode, reset: boolean): void {
23    if (reset) {
24      getUINativeModule().listItemGroup.resetListItemGroupInitialize(node);
25    } else {
26      getUINativeModule().listItemGroup.setListItemGroupInitialize(node, this.value?.space, this.value?.style);
27    }
28  }
29}
30class ListItemGroupDividerModifier extends ModifierWithKey<DividerStyle> {
31  constructor(value: DividerStyle) {
32    super(value);
33  }
34  static identity: Symbol = Symbol('listItemGroupDivider');
35  applyPeer(node: KNode, reset: boolean): void {
36    if (reset) {
37      getUINativeModule().listItemGroup.resetDivider(node);
38    } else {
39      getUINativeModule().listItemGroup.setDivider(node, this.value?.strokeWidth!, this.value?.color, this.value?.startMargin, this.value?.endMargin);
40    }
41  }
42
43  checkObjectDiff(): boolean {
44    return !(this.stageValue?.strokeWidth === this.value?.strokeWidth &&
45      this.stageValue?.color === this.value?.color &&
46      this.stageValue?.startMargin === this.value?.startMargin &&
47      this.stageValue?.endMargin === this.value?.endMargin);
48  }
49}
50
51class ListItemGroupChildrenMainSizeModifier extends ModifierWithKey<ChildrenMainSize> {
52  constructor(value: ChildrenMainSize) {
53    super(value);
54  }
55  static identity: Symbol = Symbol('listItemGroupChildrenMainSize');
56  applyPeer(node: KNode, reset: boolean): void {
57    if (reset) {
58      getUINativeModule().listItemGroup.resetListItemGroupChildrenMainSize(node);
59    } else {
60      getUINativeModule().listItemGroup.setListItemGroupChildrenMainSize(node, this.value);
61    }
62  }
63  checkObjectDiff(): boolean {
64    return true;
65  }
66}
67
68interface ListItemGroupParam {
69  space: string | number;
70  style: ListItemGroupStyle;
71}
72
73class ArkListItemGroupComponent extends ArkComponent implements ListItemGroupAttribute {
74  constructor(nativePtr: KNode, classType?: ModifierType) {
75    super(nativePtr, classType);
76  }
77  divider(value: { strokeWidth: any; color?: any; startMargin?: any; endMargin?: any; } | null): this {
78    modifierWithKey(this._modifiersWithKeys, ListItemGroupDividerModifier.identity, ListItemGroupDividerModifier, value);
79    return this;
80  }
81  childrenMainSize(value: ChildrenMainSize): this {
82    modifierWithKey(this._modifiersWithKeys, ListItemGroupChildrenMainSizeModifier.identity, ListItemGroupChildrenMainSizeModifier, value);
83    return this;
84  }
85  initialize(value: Object[]): this {
86    if (value[0] !== undefined) {
87      modifierWithKey(this._modifiersWithKeys, ListItemGroupInitializeModifier.identity,
88        ListItemGroupInitializeModifier, value[0] as ListItemGroupParam);
89    } else {
90      modifierWithKey(this._modifiersWithKeys, ListItemGroupInitializeModifier.identity,
91        ListItemGroupInitializeModifier, undefined);
92    }
93    return this;
94  }
95  allowChildTypes(): string[] {
96    return ['ListItem'];
97  }
98}
99
100// @ts-ignore
101globalThis.ListItemGroup.attributeModifier = function (modifier: ArkComponent): void {
102  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
103    return new ArkListItemGroupComponent(nativePtr);
104  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
105    return new modifierJS.ListItemGroupModifier(nativePtr, classType);
106  });
107};
108