• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-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/**
17 * The options to help grid layout
18 *
19 * @interface GridLayoutOptions
20 * @syscap SystemCapability.ArkUI.ArkUI.Full
21 * @crossplatform
22 * @since 10
23 */
24declare interface GridLayoutOptions {
25  /**
26   * The size of most grid items, in [rows, columns], generally [1, 1]
27   *
28   * @type { [number, number] } regularSize
29   * @syscap SystemCapability.ArkUI.ArkUI.Full
30   * @crossplatform
31   * @since 10
32   */
33  regularSize: [number, number];
34
35  /**
36   * The indexes of grid items with irregular size.
37   *
38   * @type { ?number[] } irregularIndexes
39   * @default number[] no irregular grid item
40   * @syscap SystemCapability.ArkUI.ArkUI.Full
41   * @crossplatform
42   * @since 10
43   */
44  irregularIndexes?: number[];
45
46  /**
47   * Called to return the size of the irregular grid items with the specified index in [rows, columns].
48   *
49   * @type { ?function } onGetIrregularSizeByIndex,
50   * all irregular grid items will occupy an entire line if not set
51   * @syscap SystemCapability.ArkUI.ArkUI.Full
52   * @crossplatform
53   * @since 10
54   */
55  onGetIrregularSizeByIndex?: (index: number) => [number, number]
56}
57
58/**
59 * Defines the grid interface.
60 *
61 * @interface GridInterface
62 * @syscap SystemCapability.ArkUI.ArkUI.Full
63 * @since 7
64 */
65/**
66 * Defines the grid interface.
67 *
68 * @interface GridInterface
69 * @syscap SystemCapability.ArkUI.ArkUI.Full
70 * @crossplatform
71 * @since 10
72 */
73interface GridInterface {
74  /**
75   * Grid is returned when the parameter is transferred.
76   *
77   * @param { Scroller } scroller
78   * @returns { GridAttribute }
79   * @syscap SystemCapability.ArkUI.ArkUI.Full
80   * @since 7
81   */
82  /**
83   * Grid is returned when the parameter is transferred.
84   *
85   * @param { Scroller } scroller - Controller bound to the grid
86   * @param { GridLayoutOptions } layoutOptions - The options to help grid layout
87   * @returns { GridAttribute } The attribute of the grid
88   * @syscap SystemCapability.ArkUI.ArkUI.Full
89   * @crossplatform
90   * @since 10
91   */
92  (scroller?: Scroller, layoutOptions?: GridLayoutOptions): GridAttribute;
93}
94
95/**
96 * The enum of property layoutDirection
97 *
98 * @enum { number }
99 * @syscap SystemCapability.ArkUI.ArkUI.Full
100 * @since 8
101 */
102/**
103 * The enum of property layoutDirection
104 *
105 * @enum { number }
106 * @syscap SystemCapability.ArkUI.ArkUI.Full
107 * @crossplatform
108 * @since 10
109 */
110declare enum GridDirection {
111  /**
112   * The row direction.
113   *
114   * @syscap SystemCapability.ArkUI.ArkUI.Full
115   * @since 8
116   */
117  /**
118   * The row direction.
119   *
120   * @syscap SystemCapability.ArkUI.ArkUI.Full
121   * @crossplatform
122   * @since 10
123   */
124  Row,
125
126  /**
127   * The column direction.
128   *
129   * @syscap SystemCapability.ArkUI.ArkUI.Full
130   * @since 8
131   */
132  /**
133   * The column direction.
134   *
135   * @syscap SystemCapability.ArkUI.ArkUI.Full
136   * @crossplatform
137   * @since 10
138   */
139  Column,
140
141  /**
142   * The row reverse direction.
143   *
144   * @syscap SystemCapability.ArkUI.ArkUI.Full
145   * @since 8
146   */
147  /**
148   * The row reverse direction.
149   *
150   * @syscap SystemCapability.ArkUI.ArkUI.Full
151   * @crossplatform
152   * @since 10
153   */
154  RowReverse,
155
156  /**
157   * The column reverse direction.
158   *
159   * @syscap SystemCapability.ArkUI.ArkUI.Full
160   * @since 8
161   */
162  /**
163   * The column reverse direction.
164   *
165   * @syscap SystemCapability.ArkUI.ArkUI.Full
166   * @crossplatform
167   * @since 10
168   */
169  ColumnReverse,
170}
171
172/**
173 * The attribute of scrollbar to compute scrollbar position and height.
174 *
175 * @interface ComputedBarAttribute
176 * @syscap SystemCapability.ArkUI.ArkUI.Full
177 * @crossplatform
178 * @since 10
179 */
180declare interface ComputedBarAttribute {
181  /**
182   * The offset of the grid.
183   *
184   * @type { number }
185   * @syscap SystemCapability.ArkUI.ArkUI.Full
186   * @crossplatform
187   * @since 10
188   */
189  totalOffset: number;
190
191  /**
192   * The range of the grid.
193   *
194   * @type { number }
195   * @syscap SystemCapability.ArkUI.ArkUI.Full
196   * @crossplatform
197   * @since 10
198   */
199  totalLength: number;
200}
201
202/**
203 * Defines the grid attribute functions.
204 *
205 * @extends CommonMethod
206 * @syscap SystemCapability.ArkUI.ArkUI.Full
207 * @since 7
208 */
209/**
210 * Defines the grid attribute functions.
211 *
212 * @extends CommonMethod
213 * @syscap SystemCapability.ArkUI.ArkUI.Full
214 * @crossplatform
215 * @since 10
216 */
217declare class GridAttribute extends CommonMethod<GridAttribute> {
218  /**
219   * This parameter specifies the number of columns in the current grid layout.
220   *
221   * @param { string } value
222   * @returns { GridAttribute }
223   * @syscap SystemCapability.ArkUI.ArkUI.Full
224   * @since 7
225   */
226  /**
227   * This parameter specifies the number of columns in the current grid layout.
228   *
229   * @param { string } value
230   * @returns { GridAttribute }
231   * @syscap SystemCapability.ArkUI.ArkUI.Full
232   * @crossplatform
233   * @since 10
234   */
235  columnsTemplate(value: string): GridAttribute;
236
237  /**
238   * Lets you set the number of rows in the current grid layout,
239   *
240   * @param { string } value
241   * @returns { GridAttribute }
242   * @syscap SystemCapability.ArkUI.ArkUI.Full
243   * @since 7
244   */
245  /**
246   * Lets you set the number of rows in the current grid layout,
247   *
248   * @param { string } value
249   * @returns { GridAttribute }
250   * @syscap SystemCapability.ArkUI.ArkUI.Full
251   * @crossplatform
252   * @since 10
253   */
254  rowsTemplate(value: string): GridAttribute;
255
256  /**
257   * Allows you to set the spacing between columns.
258   *
259   * @param { Length } value
260   * @returns { GridAttribute }
261   * @syscap SystemCapability.ArkUI.ArkUI.Full
262   * @since 7
263   */
264  /**
265   * Allows you to set the spacing between columns.
266   *
267   * @param { Length } value
268   * @returns { GridAttribute }
269   * @syscap SystemCapability.ArkUI.ArkUI.Full
270   * @crossplatform
271   * @since 10
272   */
273  columnsGap(value: Length): GridAttribute;
274
275  /**
276   * Lets you set the spacing between rows.
277   *
278   * @param { Length } value
279   * @returns { GridAttribute }
280   * @syscap SystemCapability.ArkUI.ArkUI.Full
281   * @since 7
282   */
283  /**
284   * Lets you set the spacing between rows.
285   *
286   * @param { Length } value
287   * @returns { GridAttribute }
288   * @syscap SystemCapability.ArkUI.ArkUI.Full
289   * @crossplatform
290   * @since 10
291   */
292  rowsGap(value: Length): GridAttribute;
293
294  /**
295   * This parameter specifies the width of the scroll bar.
296   *
297   * @param { number | string } value
298   * @returns { GridAttribute }
299   * @syscap SystemCapability.ArkUI.ArkUI.Full
300   * @since 7
301   */
302  /**
303   * This parameter specifies the width of the scroll bar.
304   *
305   * @param { number | string } value
306   * @returns { GridAttribute }
307   * @syscap SystemCapability.ArkUI.ArkUI.Full
308   * @crossplatform
309   * @since 10
310   */
311  scrollBarWidth(value: number | string): GridAttribute;
312
313  /**
314   * Sets the color of the scroll bar.
315   *
316   * @param { Color | number | string } value
317   * @returns { GridAttribute }
318   * @syscap SystemCapability.ArkUI.ArkUI.Full
319   * @since 7
320   */
321  /**
322   * Sets the color of the scroll bar.
323   *
324   * @param { Color | number | string } value
325   * @returns { GridAttribute }
326   * @syscap SystemCapability.ArkUI.ArkUI.Full
327   * @crossplatform
328   * @since 10
329   */
330  scrollBarColor(value: Color | number | string): GridAttribute;
331
332  /**
333   * Lets you set the spacing between rows.
334   *
335   * @param { BarState } value
336   * @returns { GridAttribute }
337   * @syscap SystemCapability.ArkUI.ArkUI.Full
338   * @since 7
339   */
340  /**
341   * Lets you set the spacing between rows.
342   *
343   * @param { BarState } value
344   * @returns { GridAttribute }
345   * @syscap SystemCapability.ArkUI.ArkUI.Full
346   * @crossplatform
347   * @since 10
348   */
349  scrollBar(value: BarState): GridAttribute;
350
351  /**
352   * Set scrollbar position.
353   *
354   * @param { function } event - callback of grid scroll,
355   * index is the current first displayed item, offset is the grid offset,
356   * return ComputedBarAttribute to update scrollbar position and height.
357   * @returns { GridAttribute }
358   * @syscap SystemCapability.ArkUI.ArkUI.Full
359   * @crossplatform
360   * @since 10
361   */
362  onScrollBarUpdate(event: (index: number, offset: number) => ComputedBarAttribute): GridAttribute;
363
364  /**
365   * Sets the status of the scroll bar.
366   *
367   * @param { function } event - of grid scroll,
368   * first is the index  of the starting sliding position, last is the index  of the ending sliding position.
369   * @returns { GridAttribute }
370   * @syscap SystemCapability.ArkUI.ArkUI.Full
371   * @since 7
372   */
373  /**
374   * Sets the status of the scroll bar.
375   *
376   * @param { function } event - of grid scroll,
377   * first is the index  of the starting sliding position, last is the index  of the ending sliding position,
378   * return void to no return value.
379   * @returns { GridAttribute }
380   * @syscap SystemCapability.ArkUI.ArkUI.Full
381   * @crossplatform
382   * @since 10
383   */
384  onScrollIndex(event: (first: number, last: number) => void): GridAttribute;
385
386  /**
387   * cached Count
388   *
389   * @param { number } value
390   * @returns { GridAttribute }
391   * @syscap SystemCapability.ArkUI.ArkUI.Full
392   * @since 7
393   */
394  /**
395   * cached Count
396   *
397   * @param { number } value
398   * @returns { GridAttribute }
399   * @syscap SystemCapability.ArkUI.ArkUI.Full
400   * @crossplatform
401   * @since 10
402   */
403  cachedCount(value: number): GridAttribute;
404
405  /**
406   * editMode
407   *
408   * @param { boolean } value
409   * @returns { GridAttribute }
410   * @syscap SystemCapability.ArkUI.ArkUI.Full
411   * @since 8
412   */
413  /**
414   * editMode
415   *
416   * @param { boolean } value
417   * @returns { GridAttribute }
418   * @syscap SystemCapability.ArkUI.ArkUI.Full
419   * @crossplatform
420   * @since 10
421   */
422  editMode(value: boolean): GridAttribute;
423
424  /**
425   * Called when judging whether it is multiSelectable.
426   *
427   * @param { boolean } value
428   * @returns { GridAttribute }
429   * @syscap SystemCapability.ArkUI.ArkUI.Full
430   * @since 8
431   */
432  /**
433   * Called when judging whether it is multiSelectable.
434   *
435   * @param { boolean } value
436   * @returns { GridAttribute }
437   * @syscap SystemCapability.ArkUI.ArkUI.Full
438   * @crossplatform
439   * @since 10
440   */
441  multiSelectable(value: boolean): GridAttribute;
442
443  /**
444   * maxCount
445   *
446   * @param { number } value
447   * @returns { GridAttribute }
448   * @syscap SystemCapability.ArkUI.ArkUI.Full
449   * @since 8
450   */
451  /**
452   * maxCount
453   *
454   * @param { number } value
455   * @returns { GridAttribute }
456   * @syscap SystemCapability.ArkUI.ArkUI.Full
457   * @crossplatform
458   * @since 10
459   */
460  maxCount(value: number): GridAttribute;
461
462  /**
463   * minCount
464   *
465   * @param { number } value
466   * @returns { GridAttribute }
467   * @syscap SystemCapability.ArkUI.ArkUI.Full
468   * @since 8
469   */
470  /**
471   * minCount
472   *
473   * @param { number } value
474   * @returns { GridAttribute }
475   * @syscap SystemCapability.ArkUI.ArkUI.Full
476   * @crossplatform
477   * @since 10
478   */
479  minCount(value: number): GridAttribute;
480
481  /**
482   * cellLength
483   *
484   * @param { number } value
485   * @returns { GridAttribute }
486   * @syscap SystemCapability.ArkUI.ArkUI.Full
487   * @since 8
488   */
489  /**
490   * cellLength
491   *
492   * @param { number } value
493   * @returns { GridAttribute }
494   * @syscap SystemCapability.ArkUI.ArkUI.Full
495   * @crossplatform
496   * @since 10
497   */
498  cellLength(value: number): GridAttribute;
499
500  /**
501   * Control GridDirection of the grid.
502   *
503   * @param { GridDirection } value
504   * @returns { GridAttribute }
505   * @syscap SystemCapability.ArkUI.ArkUI.Full
506   * @since 8
507   */
508  /**
509   * Control GridDirection of the grid.
510   *
511   * @param { GridDirection } value
512   * @returns { GridAttribute }
513   * @syscap SystemCapability.ArkUI.ArkUI.Full
514   * @crossplatform
515   * @since 10
516   */
517  layoutDirection(value: GridDirection): GridAttribute;
518
519  /**
520   * Control if the grid supports animation.
521   *
522   * @param { boolean } value
523   * @returns { GridAttribute }
524   * @syscap SystemCapability.ArkUI.ArkUI.Full
525   * @since 8
526   */
527  /**
528   * Control if the grid supports animation.
529   *
530   * @param { boolean } value
531   * @returns { GridAttribute }
532   * @syscap SystemCapability.ArkUI.ArkUI.Full
533   * @crossplatform
534   * @since 10
535   */
536  supportAnimation(value: boolean): GridAttribute;
537
538  /**
539   * After a listener is bound, the component can be dragged. After the drag occurs, a callback is triggered.
540   * (To be triggered, press and hold for 170 milliseconds (ms))
541   *
542   * @param { function } event
543   * @returns { GridAttribute }
544   * @syscap SystemCapability.ArkUI.ArkUI.Full
545   * @since 8
546   */
547  /**
548   * After a listener is bound, the component can be dragged. After the drag occurs, a callback is triggered.
549   * (To be triggered, press and hold for 170 milliseconds (ms))
550   *
551   * @param { function } event
552   * @returns { GridAttribute }
553   * @syscap SystemCapability.ArkUI.ArkUI.Full
554   * @crossplatform
555   * @since 10
556   */
557  onItemDragStart(event: (event: ItemDragInfo, itemIndex: number) => (() => any) | void): GridAttribute;
558
559  /**
560   * After binding, a callback is triggered when the component is dragged to the range of the component.
561   *
562   * @param { function } event
563   * @returns { GridAttribute }
564   * @syscap SystemCapability.ArkUI.ArkUI.Full
565   * @since 8
566   */
567  /**
568   * After binding, a callback is triggered when the component is dragged to the range of the component.
569   *
570   * @param { function } event
571   * @returns { GridAttribute }
572   * @syscap SystemCapability.ArkUI.ArkUI.Full
573   * @crossplatform
574   * @since 10
575   */
576  onItemDragEnter(event: (event: ItemDragInfo) => void): GridAttribute;
577
578  /**
579   * After binding, a callback is triggered when the drag moves within the range of a placeable component.
580   *
581   * @param { function } event
582   * @returns { GridAttribute }
583   * @syscap SystemCapability.ArkUI.ArkUI.Full
584   * @since 8
585   */
586  /**
587   * After binding, a callback is triggered when the drag moves within the range of a placeable component.
588   *
589   * @param { function } event
590   * @returns { GridAttribute }
591   * @syscap SystemCapability.ArkUI.ArkUI.Full
592   * @crossplatform
593   * @since 10
594   */
595  onItemDragMove(event: (event: ItemDragInfo, itemIndex: number, insertIndex: number) => void): GridAttribute;
596
597  /**
598   * After binding, a callback is triggered when the component is dragged out of the component range.
599   *
600   * @param { function } event
601   * @returns { GridAttribute }
602   * @syscap SystemCapability.ArkUI.ArkUI.Full
603   * @since 8
604   */
605  /**
606   * After binding, a callback is triggered when the component is dragged out of the component range.
607   *
608   * @param { function } event
609   * @returns { GridAttribute }
610   * @syscap SystemCapability.ArkUI.ArkUI.Full
611   * @crossplatform
612   * @since 10
613   */
614  onItemDragLeave(event: (event: ItemDragInfo, itemIndex: number) => void): GridAttribute;
615
616  /**
617   * The component bound to this event can be used as the drag release target.
618   * This callback is triggered when the drag behavior is stopped within the scope of the component.
619   *
620   * @param { function } event
621   * @returns { GridAttribute }
622   * @syscap SystemCapability.ArkUI.ArkUI.Full
623   * @since 8
624   */
625  /**
626   * The component bound to this event can be used as the drag release target.
627   * This callback is triggered when the drag behavior is stopped within the scope of the component.
628   *
629   * @param { function } event
630   * @returns { GridAttribute }
631   * @syscap SystemCapability.ArkUI.ArkUI.Full
632   * @crossplatform
633   * @since 10
634   */
635  onItemDrop(
636    event: (event: ItemDragInfo, itemIndex: number, insertIndex: number, isSuccess: boolean) => void,
637  ): GridAttribute;
638
639  /**
640   * Called when the sliding effect is set.
641   *
642   * @param { EdgeEffect } value - Scroll effect. For details, see EdgeEffect.
643   * @returns { GridAttribute } The attribute of the grid
644   * @syscap SystemCapability.ArkUI.ArkUI.Full
645   * @crossplatform
646   * @since 10
647   */
648  edgeEffect(value: EdgeEffect): GridAttribute;
649
650  /**
651   * Called to setting the nested scroll options.
652   *
653   * @param { NestedScrollOptions } value - options for nested scrolling.
654   * @returns { GridAttribute } the attribute of the grid.
655   * @syscap SystemCapability.ArkUI.ArkUI.Full
656   * @since 10
657   */
658  nestedScroll(value: NestedScrollOptions): GridAttribute;
659
660  /**
661   * Called when setting whether to enable scroll by gesture or mouse.
662   *
663   * @param { boolean } value
664   * @returns { GridAttribute } The attribute of the grid
665   * @syscap SystemCapability.ArkUI.ArkUI.Full
666   * @crossplatform
667   * @since 10
668   */
669  enableScrollInteraction(value: boolean): GridAttribute;
670
671  /**
672   * Called to setting the friction.
673   *
674   * @param { number | Resource } value - options for scrolling friction.
675   * @returns { GridAttribute } the attribute of the grid.
676   * @syscap SystemCapability.ArkUI.ArkUI.Full
677   * @crossplatform
678   * @since 10
679   */
680  friction(value: number | Resource): GridAttribute;
681
682  /**
683   * Called When sliding the grid.
684   *
685   * @param { function } event - callback of grid scroll,
686   * scrollOffset is offset per frame scrolling, ScrollState is current sliding state.
687   * @returns { GridAttribute }
688   * @syscap SystemCapability.ArkUI.ArkUI.Full
689   * @crossplatform
690   * @since 10
691   */
692  onScroll(event: (scrollOffset: number, scrollState: ScrollState) => void): GridAttribute;
693
694  /**
695   * Called when the grid begins to arrive.
696   *
697   * @param { function } event
698   * @returns { GridAttribute }
699   * @syscap SystemCapability.ArkUI.ArkUI.Full
700   * @crossplatform
701   * @since 10
702   */
703  onReachStart(event: () => void): GridAttribute;
704
705  /**
706   * Called when the grid reaches the end.
707   *
708   * @param { function } event
709   * @returns { GridAttribute }
710   * @syscap SystemCapability.ArkUI.ArkUI.Full
711   * @crossplatform
712   * @since 10
713   */
714  onReachEnd(event: () => void): GridAttribute;
715
716  /**
717   * Called when the slider start.
718   *
719   * @param { function } event
720   * @returns { GridAttribute }
721   * @syscap SystemCapability.ArkUI.ArkUI.Full
722   * @crossplatform
723   * @since 10
724   */
725  onScrollStart(event: () => void): GridAttribute;
726
727  /**
728   * Called when the slider stops.
729   *
730   * @param { function } event
731   * @returns { GridAttribute }
732   * @syscap SystemCapability.ArkUI.ArkUI.Full
733   * @crossplatform
734   * @since 10
735   */
736  onScrollStop(event: () => void): GridAttribute;
737
738  /**
739   * Called when scrolling begin each frame.
740   *
741   * @param { function } event - callback of grid scroll,
742   * offset is the amount of sliding that is about to occur, state is current sliding state,
743   * return number to actual sliding offset.
744   * @returns { GridAttribute }
745   * @syscap SystemCapability.ArkUI.ArkUI.Full
746   * @crossplatform
747   * @since 10
748   */
749  onScrollFrameBegin(event: (offset: number, state: ScrollState) => { offsetRemain: number }): GridAttribute;
750}
751
752/**
753 * Defines Grid Component.
754 *
755 * @syscap SystemCapability.ArkUI.ArkUI.Full
756 * @since 7
757 */
758/**
759 * Defines Grid Component.
760 *
761 * @syscap SystemCapability.ArkUI.ArkUI.Full
762 * @crossplatform
763 * @since 10
764 */
765declare const Grid: GridInterface;
766
767/**
768 * Defines Grid Component instance.
769 *
770 * @syscap SystemCapability.ArkUI.ArkUI.Full
771 * @since 7
772 */
773/**
774 * Defines Grid Component instance.
775 *
776 * @syscap SystemCapability.ArkUI.ArkUI.Full
777 * @crossplatform
778 * @since 10
779 */
780declare const GridInstance: GridAttribute;
781