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