forked from saleel/react-native-super-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
105 lines (88 loc) · 2.7 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import * as React from "react";
import {
ViewStyle,
ListRenderItemInfo,
SectionListRenderItemInfo,
SectionListData,
StyleProp,
RefreshControlProps,
SectionListProps,
FlatListProps
} from "react-native"
// Copy from TS 3.5
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>
// Grid item info, same as original + rowIndex
export type GridRenderItemInfo<ItemT> = ListRenderItemInfo<ItemT> & {
rowIndex: number;
}
export type GridRenderItem<ItemT> = (
info: GridRenderItemInfo<ItemT>
) => React.ReactElement | null;
// Custom props that are present in both grid and list
type CommonProps<ItemType> = {
/**
* Additional styles for rows (rows render multiple items within), apart from the generated ones.
*/
additionalRowStyle?: StyleProp<ViewStyle>;
/**
* Minimum width or height for each item in pixels (virtual).
*/
itemDimension?: number;
/**
* If true, the exact itemDimension will be used and won't be adjusted to fit the screen.
*/
fixed?: boolean;
/**
* Spacing between each item.
*/
spacing?: number;
/**
* Specifies a static width or height for the GridView container.
* If your container dimension is known or can be calculated at runtime
* (via Dimensions.get('window'), for example), passing this prop will force the grid container
* to that dimension size and avoid the reflow associated with dynamically calculating it
*/
staticDimension?: number;
/**
* Specifies a maximum width or height for the container. If not passed, full width/height
* of the screen will be used.
*/
maxDimension?: number;
/**
* Specifies the style about content row view
*/
itemContainerStyle?: StyleProp<ViewStyle>;
}
/**
* React Native Super Grid Properties
*/
export interface FlatGridProps<ItemType = any>
extends FlatListProps<ItemType>, CommonProps<ItemType> {
/**
* Items to be rendered. renderItem will be called with each item in this array.
*/
data: ItemType[];
}
/**
* Responsive Grid View for React Native.
*/
export class FlatGrid<ItemType = any> extends React.Component<
FlatGridProps<ItemType>
> {}
export type SectionItem<ItemType> = {
title: string;
data: ItemType[];
renderItem?: GridRenderItem<ItemType>;
}
// Original section list component props
type SectionGridAllowedProps<ItemType = any> = Omit<SectionListProps<ItemType>,
// This prop doesn't affect the SectionGrid, which only scrolls vertically.
| "horizontal" | "sections"
>
export interface SectionGridProps<ItemType = any>
extends SectionGridAllowedProps<ItemType>, CommonProps<ItemType> {
sections: SectionItem<ItemType>[];
}
export class SectionGrid<ItemType = any> extends React.Component<
SectionGridProps<ItemType>
> {}