-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathListViewLayout.tsx
77 lines (69 loc) · 2.04 KB
/
ListViewLayout.tsx
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
import {
InvalidationContext,
LayoutInfo,
Rect,
} from '@react-stately/virtualizer';
import {
LayoutNode,
ListLayout,
ListLayoutOptions,
} from '@react-stately/layout';
import { Node } from '@react-types/shared';
type ListViewLayoutOptions = ListLayoutOptions & {
isLoading?: boolean;
};
export class ListViewLayout<T> extends ListLayout<T, ListViewLayoutOptions> {
private isLoading: boolean = false;
update(
invalidationContext: InvalidationContext<ListViewLayoutOptions>
): void {
this.isLoading = invalidationContext.layoutOptions?.isLoading || false;
super.update(invalidationContext);
}
protected buildCollection(): LayoutNode[] {
let nodes = super.buildCollection();
let y = this.contentSize.height;
if (this.isLoading) {
let rect = new Rect(
0,
y,
this.virtualizer?.visibleRect.width,
(nodes.length === 0
? this.virtualizer?.visibleRect?.height
: this.estimatedRowHeight) ?? undefined
);
let loader = new LayoutInfo('loader', 'loader', rect);
let node = {
layoutInfo: loader,
validRect: loader.rect,
};
nodes.push(node);
this.layoutNodes.set(loader.key, node);
y = loader.rect.maxY;
}
if (nodes.length === 0) {
let rect = new Rect(
0,
y,
this.virtualizer?.visibleRect.width,
this.virtualizer?.visibleRect.height
);
let placeholder = new LayoutInfo('placeholder', 'placeholder', rect);
let node = {
layoutInfo: placeholder,
validRect: placeholder.rect,
};
nodes.push(node);
this.layoutNodes.set(placeholder.key, node);
y = placeholder.rect.maxY;
}
this.contentSize.height = y;
return nodes;
}
protected buildItem(node: Node<T>, x: number, y: number): LayoutNode {
let res = super.buildItem(node, x, y);
// allow overflow so the focus ring/selection ring can extend outside to overlap with the adjacent items borders
res.layoutInfo.allowOverflow = true;
return res;
}
}