• 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 ArkGridComponent extends ArkComponent implements GridAttribute {
18  constructor(nativePtr: KNode, classType?: ModifierType) {
19    super(nativePtr, classType);
20  }
21  columnsTemplate(value: string): this {
22    modifierWithKey(this._modifiersWithKeys, GridColumnsTemplateModifier.identity, GridColumnsTemplateModifier, value);
23    return this;
24  }
25  rowsTemplate(value: string): this {
26    modifierWithKey(this._modifiersWithKeys, GridRowsTemplateModifier.identity, GridRowsTemplateModifier, value);
27    return this;
28  }
29  columnsGap(value: Length): this {
30    modifierWithKey(this._modifiersWithKeys, GridColumnsGapModifier.identity, GridColumnsGapModifier, value);
31    return this;
32  }
33  rowsGap(value: Length): this {
34    modifierWithKey(this._modifiersWithKeys, GridRowsGapModifier.identity, GridRowsGapModifier, value);
35    return this;
36  }
37  scrollBarWidth(value: string | number): this {
38    modifierWithKey(this._modifiersWithKeys, GridScrollBarWidthModifier.identity, GridScrollBarWidthModifier, value);
39    return this;
40  }
41  scrollBarColor(value: string | number | Color): this {
42    modifierWithKey(this._modifiersWithKeys, GridScrollBarColorModifier.identity, GridScrollBarColorModifier, value);
43    return this;
44  }
45  scrollBar(value: BarState): this {
46    modifierWithKey(this._modifiersWithKeys, GridScrollBarModifier.identity, GridScrollBarModifier, value);
47    return this;
48  }
49  onScrollBarUpdate(event: (index: number, offset: number) => ComputedBarAttribute): this {
50    throw new Error('Method not implemented.');
51  }
52  onScrollIndex(event: (first: number, last: number) => void): this {
53    throw new Error('Method not implemented.');
54  }
55  cachedCount(value: number): this {
56    modifierWithKey(this._modifiersWithKeys, GridCachedCountModifier.identity, GridCachedCountModifier, value);
57    return this;
58  }
59  editMode(value: boolean): this {
60    modifierWithKey(this._modifiersWithKeys, GridEditModeModifier.identity, GridEditModeModifier, value);
61    return this;
62  }
63  multiSelectable(value: boolean): this {
64    modifierWithKey(this._modifiersWithKeys, GridMultiSelectableModifier.identity, GridMultiSelectableModifier, value);
65    return this;
66  }
67  maxCount(value: number): this {
68    modifierWithKey(this._modifiersWithKeys, GridMaxCountModifier.identity, GridMaxCountModifier, value);
69    return this;
70  }
71  minCount(value: number): this {
72    modifierWithKey(this._modifiersWithKeys, GridMinCountModifier.identity, GridMinCountModifier, value);
73    return this;
74  }
75  cellLength(value: number): this {
76    modifierWithKey(this._modifiersWithKeys, GridCellLengthModifier.identity, GridCellLengthModifier, value);
77    return this;
78  }
79  layoutDirection(value: GridDirection): this {
80    modifierWithKey(this._modifiersWithKeys, GridLayoutDirectionModifier.identity, GridLayoutDirectionModifier, value);
81    return this;
82  }
83  supportAnimation(value: boolean): this {
84    modifierWithKey(this._modifiersWithKeys, GridSupportAnimationModifier.identity, GridSupportAnimationModifier, value);
85    return this;
86  }
87  onItemDragStart(event: (event: ItemDragInfo, itemIndex: number) => void | (() => any)): this {
88    throw new Error('Method not implemented.');
89  }
90  onItemDragEnter(event: (event: ItemDragInfo) => void): this {
91    throw new Error('Method not implemented.');
92  }
93  onItemDragMove(event: (event: ItemDragInfo, itemIndex: number, insertIndex: number) => void): this {
94    throw new Error('Method not implemented.');
95  }
96  onItemDragLeave(event: (event: ItemDragInfo, itemIndex: number) => void): this {
97    throw new Error('Method not implemented.');
98  }
99  onItemDrop(event: (event: ItemDragInfo, itemIndex: number, insertIndex: number, isSuccess: boolean) => void): this {
100    throw new Error('Method not implemented.');
101  }
102  edgeEffect(value: EdgeEffect, options?: EdgeEffectOptions | undefined): this {
103    let effect: ArkGridEdgeEffect = new ArkGridEdgeEffect();
104    effect.value = value;
105    effect.options = options;
106    modifierWithKey(this._modifiersWithKeys, GridEdgeEffectModifier.identity, GridEdgeEffectModifier, effect);
107    return this;
108  }
109  nestedScroll(value: NestedScrollOptions): this {
110    modifierWithKey(this._modifiersWithKeys, GridNestedScrollModifier.identity, GridNestedScrollModifier, value);
111    return this;
112  }
113  enableScrollInteraction(value: boolean): this {
114    modifierWithKey(this._modifiersWithKeys, GridEnableScrollModifier.identity, GridEnableScrollModifier, value);
115    return this;
116  }
117  friction(value: number | Resource): this {
118    modifierWithKey(this._modifiersWithKeys, GridFrictionModifier.identity, GridFrictionModifier, value);
119    return this;
120  }
121  onScroll(event: (scrollOffset: number, scrollState: ScrollState) => void): this {
122    throw new Error('Method not implemented.');
123  }
124  onReachStart(event: () => void): this {
125    throw new Error('Method not implemented.');
126  }
127  onReachEnd(event: () => void): this {
128    throw new Error('Method not implemented.');
129  }
130  onScrollStart(event: () => void): this {
131    throw new Error('Method not implemented.');
132  }
133  onScrollStop(event: () => void): this {
134    throw new Error('Method not implemented.');
135  }
136  onScrollFrameBegin(event: (offset: number, state: ScrollState) => { offsetRemain: number; }): this {
137    throw new Error('Method not implemented.');
138  }
139  clip(value: boolean | CircleAttribute | EllipseAttribute | PathAttribute | RectAttribute): this {
140    modifierWithKey(this._modifiersWithKeys, GridClipModifier.identity, GridClipModifier, value);
141    return this;
142  }
143  flingSpeedLimit(value: number): this {
144    modifierWithKey(this._modifiersWithKeys, GridFlingSpeedLimitModifier.identity, GridFlingSpeedLimitModifier, value);
145    return this;
146  }
147  alignItems(value: GridItemAlignment): this {
148    modifierWithKey(this._modifiersWithKeys, GridAlignItemsModifier.identity, GridAlignItemsModifier, value);
149    return this;
150  }
151}
152
153class GridColumnsTemplateModifier extends ModifierWithKey<string> {
154  static identity: Symbol = Symbol('gridColumnsTemplate');
155  applyPeer(node: KNode, reset: boolean): void {
156    if (reset) {
157      getUINativeModule().grid.resetColumnsTemplate(node);
158    } else {
159      getUINativeModule().grid.setColumnsTemplate(node, this.value);
160    }
161  }
162}
163
164class GridRowsTemplateModifier extends ModifierWithKey<string> {
165  static identity: Symbol = Symbol('gridRowsTemplate');
166  applyPeer(node: KNode, reset: boolean): void {
167    if (reset) {
168      getUINativeModule().grid.resetRowsTemplate(node);
169    } else {
170      getUINativeModule().grid.setRowsTemplate(node, this.value);
171    }
172  }
173}
174
175class GridColumnsGapModifier extends ModifierWithKey<Length> {
176  static identity: Symbol = Symbol('gridColumnsGap');
177  applyPeer(node: KNode, reset: boolean): void {
178    if (reset) {
179      getUINativeModule().grid.resetColumnsGap(node);
180    } else {
181      getUINativeModule().grid.setColumnsGap(node, this.value!);
182    }
183  }
184  checkObjectDiff(): boolean {
185    return !isBaseOrResourceEqual(this.stageValue, this.value);
186  }
187}
188
189class GridRowsGapModifier extends ModifierWithKey<Length> {
190  static identity: Symbol = Symbol('gridRowsGap');
191  applyPeer(node: KNode, reset: boolean): void {
192    if (reset) {
193      getUINativeModule().grid.resetRowsGap(node);
194    } else {
195      getUINativeModule().grid.setRowsGap(node, this.value!);
196    }
197  }
198  checkObjectDiff(): boolean {
199    return !isBaseOrResourceEqual(this.stageValue, this.value);
200  }
201}
202
203class GridScrollBarWidthModifier extends ModifierWithKey<string | number> {
204  static identity: Symbol = Symbol('gridScrollBarWidth');
205  applyPeer(node: KNode, reset: boolean): void {
206    if (reset) {
207      getUINativeModule().grid.resetScrollBarWidth(node);
208    } else {
209      getUINativeModule().grid.setScrollBarWidth(node, this.value);
210    }
211  }
212}
213
214class GridScrollBarModifier extends ModifierWithKey<BarState> {
215  static identity: Symbol = Symbol('gridScrollBar');
216  applyPeer(node: KNode, reset: boolean): void {
217    if (reset) {
218      getUINativeModule().grid.resetScrollBar(node);
219    } else {
220      getUINativeModule().grid.setScrollBar(node, this.value);
221    }
222  }
223}
224
225class GridScrollBarColorModifier extends ModifierWithKey<string | number | Color> {
226  static identity: Symbol = Symbol('gridScrollBarColor');
227  applyPeer(node: KNode, reset: boolean): void {
228    if (reset) {
229      getUINativeModule().grid.resetScrollBarColor(node);
230    } else {
231      getUINativeModule().grid.setScrollBarColor(node, this.value);
232    }
233  }
234}
235
236class GridEditModeModifier extends ModifierWithKey<boolean> {
237  static identity: Symbol = Symbol('gridEditMode');
238  applyPeer(node: KNode, reset: boolean): void {
239    if (reset) {
240      getUINativeModule().grid.resetEditMode(node);
241    } else {
242      getUINativeModule().grid.setEditMode(node, this.value);
243    }
244  }
245}
246
247class GridCachedCountModifier extends ModifierWithKey<number> {
248  static identity: Symbol = Symbol('gridCachedCount');
249  applyPeer(node: KNode, reset: boolean): void {
250    if (reset) {
251      getUINativeModule().grid.resetCachedCount(node);
252    } else {
253      getUINativeModule().grid.setCachedCount(node, this.value);
254    }
255  }
256}
257
258class GridMultiSelectableModifier extends ModifierWithKey<boolean> {
259  static identity: Symbol = Symbol('gridMultiSelectable');
260  applyPeer(node: KNode, reset: boolean): void {
261    if (reset) {
262      getUINativeModule().grid.resetMultiSelectable(node);
263    } else {
264      getUINativeModule().grid.setMultiSelectable(node, this.value);
265    }
266  }
267}
268
269class GridEdgeEffectModifier extends ModifierWithKey<ArkGridEdgeEffect> {
270  static identity: Symbol = Symbol('gridEdgeEffect');
271  applyPeer(node: KNode, reset: boolean): void {
272    if (reset) {
273      getUINativeModule().grid.resetEdgeEffect(node);
274    } else {
275      getUINativeModule().grid.setEdgeEffect(node, this.value?.value, this.value.options?.alwaysEnabled);
276    }
277  }
278
279  checkObjectDiff(): boolean {
280    return !((this.stageValue.value === this.value.value) &&
281      (this.stageValue.options === this.value.options));
282  }
283}
284
285class GridNestedScrollModifier extends ModifierWithKey<NestedScrollOptions> {
286  static identity: Symbol = Symbol('gridNestedScroll');
287  applyPeer(node: KNode, reset: boolean): void {
288    if (reset) {
289      getUINativeModule().grid.resetNestedScroll(node);
290    } else {
291      getUINativeModule().grid.setNestedScroll(node, this.value?.scrollForward, this.value?.scrollBackward);
292    }
293  }
294
295  checkObjectDiff(): boolean {
296    return !((this.stageValue.scrollForward === this.value.scrollForward) &&
297      (this.stageValue.scrollBackward === this.value.scrollBackward));
298  }
299}
300
301class GridEnableScrollModifier extends ModifierWithKey<boolean> {
302  static identity: Symbol = Symbol('gridEnableScroll');
303  applyPeer(node: KNode, reset: boolean): void {
304    if (reset) {
305      getUINativeModule().grid.resetEnableScroll(node);
306    } else {
307      getUINativeModule().grid.setEnableScroll(node, this.value);
308    }
309  }
310}
311
312class GridFrictionModifier extends ModifierWithKey<number | Resource> {
313  static identity: Symbol = Symbol('gridFriction');
314  applyPeer(node: KNode, reset: boolean): void {
315    if (reset) {
316      getUINativeModule().grid.resetFriction(node);
317    } else {
318      getUINativeModule().grid.setFriction(node, this.value);
319    }
320  }
321
322  checkObjectDiff(): boolean {
323    return !isBaseOrResourceEqual(this.stageValue, this.value);
324  }
325}
326
327class GridMaxCountModifier extends ModifierWithKey<number> {
328  static identity: Symbol = Symbol('gridMaxCount');
329  applyPeer(node: KNode, reset: boolean): void {
330    if (reset) {
331      getUINativeModule().grid.resetMaxCount(node);
332    } else {
333      getUINativeModule().grid.setMaxCount(node, this.value);
334    }
335  }
336}
337
338class GridMinCountModifier extends ModifierWithKey<number> {
339  static identity: Symbol = Symbol('gridMinCount');
340  applyPeer(node: KNode, reset: boolean): void {
341    if (reset) {
342      getUINativeModule().grid.resetMinCount(node);
343    } else {
344      getUINativeModule().grid.setMinCount(node, this.value);
345    }
346  }
347}
348
349class GridCellLengthModifier extends ModifierWithKey<number> {
350  static identity: Symbol = Symbol('gridCellLength');
351  applyPeer(node: KNode, reset: boolean): void {
352    if (reset) {
353      getUINativeModule().grid.resetCellLength(node);
354    } else {
355      getUINativeModule().grid.setCellLength(node, this.value);
356    }
357  }
358}
359
360class GridLayoutDirectionModifier extends ModifierWithKey<GridDirection> {
361  static identity: Symbol = Symbol('gridLayoutDirection');
362  applyPeer(node: KNode, reset: boolean): void {
363    if (reset) {
364      getUINativeModule().grid.resetLayoutDirection(node);
365    } else {
366      getUINativeModule().grid.setLayoutDirection(node, this.value);
367    }
368  }
369}
370
371class GridSupportAnimationModifier extends ModifierWithKey<boolean> {
372  static identity: Symbol = Symbol('gridSupportAnimation');
373  applyPeer(node: KNode, reset: boolean): void {
374    if (reset) {
375      getUINativeModule().grid.resetSupportAnimation(node);
376    } else {
377      getUINativeModule().grid.setSupportAnimation(node, this.value);
378    }
379  }
380}
381
382class GridClipModifier extends ModifierWithKey<boolean | object> {
383  constructor(value: boolean | object) {
384    super(value);
385  }
386  static identity: Symbol = Symbol('gridClip');
387  applyPeer(node: KNode, reset: boolean): void {
388    if (reset) {
389      getUINativeModule().common.resetClipWithEdge(node);
390    } else {
391      getUINativeModule().common.setClipWithEdge(node, this.value);
392    }
393  }
394  checkObjectDiff(): boolean {
395    return true;
396  }
397}
398
399class GridFlingSpeedLimitModifier extends ModifierWithKey<number> {
400  constructor(value: number) {
401    super(value);
402  }
403  static identity: Symbol = Symbol('gridFlingSpeedLimit');
404  applyPeer(node: KNode, reset: boolean): void {
405    if (reset) {
406      getUINativeModule().grid.resetFlingSpeedLimit(node);
407    } else {
408      getUINativeModule().grid.setFlingSpeedLimit(node, this.value);
409    }
410  }
411}
412
413class GridAlignItemsModifier extends ModifierWithKey<GridItemAlignment> {
414  constructor(value: GridItemAlignment) {
415    super(value);
416  }
417  static identity: Symbol = Symbol('gridAlignItems');
418  applyPeer(node: KNode, reset: boolean): void {
419    if (reset) {
420      getUINativeModule().grid.resetAlignItems(node);
421    } else {
422      getUINativeModule().grid.setAlignItems(node, this.value);
423    }
424  }
425}
426
427// @ts-ignore
428globalThis.Grid.attributeModifier = function (modifier: ArkComponent): void {
429  attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
430    return new ArkGridComponent(nativePtr);
431  }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
432    return new modifierJS.GridModifier(nativePtr, classType);
433  });
434};
435