• 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 GridColSpanModifier extends ModifierWithKey<ArkGridColColumnOption> {
18  constructor(value: ArkGridColColumnOption) {
19    super(value);
20  }
21  static identity: Symbol = Symbol('gridColSpan');
22  applyPeer(node: KNode, reset: boolean): void {
23    if (reset) {
24      getUINativeModule().gridCol.resetSpan(node);
25    } else {
26      if (isNumber(this.value)) {
27        getUINativeModule().gridCol.setSpan(node, this.value,
28          this.value, this.value, this.value, this.value, this.value);
29      } else {
30        getUINativeModule().gridCol.setSpan(node, this.value.xs,
31          this.value.sm, this.value.md, this.value.lg, this.value.xl, this.value.xxl);
32      }
33    }
34  }
35  checkObjectDiff(): boolean {
36    if (isNumber(this.stageValue) && isNumber(this.value)) {
37      return this.stageValue !== this.value;
38    } else if (isObject(this.stageValue) && isObject(this.value)) {
39      return this.stageValue.xs !== this.value.xs ||
40        this.stageValue.sm !== this.value.sm ||
41        this.stageValue.md !== this.value.md ||
42        this.stageValue.lg !== this.value.lg ||
43        this.stageValue.xl !== this.value.xl ||
44        this.stageValue.xxl !== this.value.xxl;
45    } else {
46      return true;
47    }
48  }
49}
50class GridColOffsetModifier extends ModifierWithKey<ArkGridColColumnOption> {
51  constructor(value: ArkGridColColumnOption) {
52    super(value);
53  }
54  static identity: Symbol = Symbol('gridColOffset');
55  applyPeer(node: KNode, reset: boolean): void {
56    if (reset) {
57      getUINativeModule().gridCol.resetGridColOffset(node);
58    } else {
59      if (isNumber(this.value)) {
60        getUINativeModule().gridCol.setGridColOffset(node, this.value,
61          this.value, this.value, this.value, this.value, this.value);
62      } else {
63        getUINativeModule().gridCol.setGridColOffset(node, this.value.xs,
64          this.value.sm, this.value.md, this.value.lg, this.value.xl, this.value.xxl);
65      }
66    }
67  }
68  checkObjectDiff(): boolean {
69    if (isNumber(this.stageValue) && isNumber(this.value)) {
70      return this.stageValue !== this.value;
71    } else if (isObject(this.stageValue) && isObject(this.value)) {
72      return this.stageValue.xs !== this.value.xs ||
73        this.stageValue.sm !== this.value.sm ||
74        this.stageValue.md !== this.value.md ||
75        this.stageValue.lg !== this.value.lg ||
76        this.stageValue.xl !== this.value.xl ||
77        this.stageValue.xxl !== this.value.xxl;
78    } else {
79      return true;
80    }
81  }
82}
83class GridColOrderModifier extends ModifierWithKey<ArkGridColColumnOption> {
84  constructor(value: ArkGridColColumnOption) {
85    super(value);
86  }
87  static identity: Symbol = Symbol('gridColOrder');
88  applyPeer(node: KNode, reset: boolean): void {
89    if (reset) {
90      getUINativeModule().gridCol.resetOrder(node);
91    } else {
92      if (isNumber(this.value)) {
93        getUINativeModule().gridCol.setOrder(node, this.value,
94          this.value, this.value, this.value, this.value, this.value);
95      } else {
96        getUINativeModule().gridCol.setOrder(node, this.value.xs,
97          this.value.sm, this.value.md, this.value.lg, this.value.xl, this.value.xxl);
98      }
99    }
100  }
101  checkObjectDiff(): boolean {
102    if (isNumber(this.stageValue) && isNumber(this.value)) {
103      return this.stageValue !== this.value;
104    } else if (isObject(this.stageValue) && isObject(this.value)) {
105      return this.stageValue.xs !== this.value.xs ||
106        this.stageValue.sm !== this.value.sm ||
107        this.stageValue.md !== this.value.md ||
108        this.stageValue.lg !== this.value.lg ||
109        this.stageValue.xl !== this.value.xl ||
110        this.stageValue.xxl !== this.value.xxl;
111    } else {
112      return true;
113    }
114  }
115}
116interface GridColParam {
117  span?: number | GridColColumnOption;
118  offset?: number | GridColColumnOption;
119  order?: number | GridColColumnOption;
120}
121class ArkGridColComponent extends ArkComponent implements GridColAttribute {
122  constructor(nativePtr: KNode, classType?: ModifierType) {
123    super(nativePtr, classType);
124  }
125  allowChildCount(): number {
126    return 1;
127  }
128  span(value: number | GridColColumnOption): GridColAttribute {
129    modifierWithKey(this._modifiersWithKeys, GridColSpanModifier.identity, GridColSpanModifier, value);
130    return this;
131  }
132  gridColOffset(value: number | GridColColumnOption): GridColAttribute {
133    modifierWithKey(this._modifiersWithKeys, GridColOffsetModifier.identity, GridColOffsetModifier, value);
134    return this;
135  }
136  order(value: number | GridColColumnOption): GridColAttribute {
137    modifierWithKey(this._modifiersWithKeys, GridColOrderModifier.identity, GridColOrderModifier, value);
138    return this;
139  }
140  initialize(value: Object[]): GridColAttribute {
141    if (value[0] !== undefined) {
142      modifierWithKey(this._modifiersWithKeys, GridColSpanModifier.identity,
143        GridColSpanModifier, (value[0] as GridColParam).span);
144      modifierWithKey(this._modifiersWithKeys, GridColOffsetModifier.identity,
145        GridColOffsetModifier, (value[0] as GridColParam).offset);
146      modifierWithKey(this._modifiersWithKeys, GridColOrderModifier.identity,
147        GridColOrderModifier, (value[0] as GridColParam).order);
148    } else {
149      modifierWithKey(this._modifiersWithKeys, GridColSpanModifier.identity,
150        GridColSpanModifier, null);
151      modifierWithKey(this._modifiersWithKeys, GridColOffsetModifier.identity,
152        GridColOffsetModifier, null);
153      modifierWithKey(this._modifiersWithKeys, GridColOrderModifier.identity,
154        GridColOrderModifier, null);
155    }
156    return this;
157  }
158}
159
160// @ts-ignore
161globalThis.GridCol.attributeModifier = function (modifier: ArkComponent): void {
162  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
163    return new ArkGridColComponent(nativePtr);
164  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
165    return new modifierJS.GridColModifier(nativePtr, classType);
166  });
167};
168