Skip to content

Commit d8ca741

Browse files
bluerssenadnelson
andauthored
Add Masonry List and Support for OnRefresh (#557)
* Add Masonry List and Support for OnRefresh * Fix Triggers and Props * Oops * Update packages/types/src/component-types.ts Co-authored-by: Allen Nelson <[email protected]> * Update packages/types/src/component-types.ts Co-authored-by: Allen Nelson <[email protected]> Co-authored-by: Allen Nelson <[email protected]>
1 parent 56a7e42 commit d8ca741

File tree

3 files changed

+99
-30
lines changed

3 files changed

+99
-30
lines changed

packages/core/src/mappings/FlashList.ts

Lines changed: 82 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,89 @@ import {
55
createNumberProp,
66
CONTAINER_COMPONENT_STYLES_SECTIONS,
77
GROUPS,
8+
Triggers,
9+
createActionProp,
10+
createStaticNumberProp,
811
} from "@draftbit/types";
912

10-
export const SEED_DATA = {
11-
name: "FlashList",
12-
tag: "FlashList",
13-
description: "Flashlist by Shopify",
14-
packageName: "@shopify/flash-list",
15-
category: COMPONENT_TYPES.data,
16-
stylesPanelSections: CONTAINER_COMPONENT_STYLES_SECTIONS,
17-
layout: {
18-
flex: 1,
13+
export const SEED_DATA = [
14+
{
15+
name: "Masonry List",
16+
tag: "MasonryFlashList",
17+
description: "Masonry Flashlist by Shopify",
18+
packageName: "@shopify/flash-list",
19+
category: COMPONENT_TYPES.data,
20+
stylesPanelSections: CONTAINER_COMPONENT_STYLES_SECTIONS,
21+
layout: {
22+
flex: 1,
23+
},
24+
triggers: [Triggers.OnRefresh, Triggers.OnEndReached],
25+
props: {
26+
onRefresh: createActionProp(),
27+
onEndReached: createActionProp(),
28+
numColumns: createNumColumnsType({
29+
editable: true,
30+
}),
31+
estimatedItemSize: createNumberProp({
32+
group: GROUPS.basic,
33+
label: "Est. Item Size",
34+
description: "Approximate size of the items before rendering.",
35+
defaultValue: 50,
36+
step: 1,
37+
precision: 0,
38+
}),
39+
optimizeItemArrangement: createStaticBoolProp({
40+
label: "Optimize Item Arrangement",
41+
description:
42+
"If enabled, MasonryFlashList will try to reduce difference in column height by modifying item order. If true, specifying overrideItemLayout is required. Default value is false.",
43+
}),
44+
onEndReachedThreshold: createStaticNumberProp({
45+
label: "End Reached Threshold",
46+
description:
47+
"How far from the end (in units of visible length of the list) the bottom edge of the list must be from the end of the content to trigger the onEndReached callback. Thus a value of 0.5 will trigger onEndReached when the end of the content is within half the visible length of the list.",
48+
defaultValue: 0.5,
49+
}),
50+
},
1951
},
20-
props: {
21-
estimatedItemSize: createNumberProp({
22-
group: GROUPS.basic,
23-
label: "Est. Item Size",
24-
description: "Approximate size of the items before rendering.",
25-
defaultValue: 50,
26-
step: 1,
27-
precision: 0,
28-
}),
29-
horizontal: createStaticBoolProp({
30-
label: "Horizontal",
31-
description: "Render list horizontally",
32-
}),
33-
inverted: createStaticBoolProp({
34-
label: "Inverted",
35-
description: "If true, reverses the direction.",
36-
}),
37-
numColumns: createNumColumnsType({
38-
editable: true,
39-
}),
52+
{
53+
name: "FlashList",
54+
tag: "FlashList",
55+
description: "Flashlist by Shopify",
56+
packageName: "@shopify/flash-list",
57+
category: COMPONENT_TYPES.data,
58+
stylesPanelSections: CONTAINER_COMPONENT_STYLES_SECTIONS,
59+
layout: {
60+
flex: 1,
61+
},
62+
triggers: [Triggers.OnRefresh, Triggers.OnEndReached],
63+
props: {
64+
onRefresh: createActionProp(),
65+
onEndReached: createActionProp(),
66+
estimatedItemSize: createNumberProp({
67+
group: GROUPS.basic,
68+
label: "Est. Item Size",
69+
description: "Approximate size of the items before rendering.",
70+
defaultValue: 50,
71+
step: 1,
72+
precision: 0,
73+
}),
74+
horizontal: createStaticBoolProp({
75+
label: "Horizontal",
76+
description: "Render list horizontally",
77+
}),
78+
inverted: createStaticBoolProp({
79+
label: "Inverted",
80+
description: "If true, reverses the direction.",
81+
}),
82+
numColumns: createNumColumnsType({
83+
editable: true,
84+
}),
85+
onEndReachedThreshold: createStaticNumberProp({
86+
label: "End Reached Threshold",
87+
description:
88+
"How far from the end (in units of visible length of the list) the bottom edge of the list must be from the end of the content to trigger the onEndReached callback. Thus a value of 0.5 will trigger onEndReached when the end of the content is within half the visible length of the list.",
89+
defaultValue: 0.5,
90+
}),
91+
},
4092
},
41-
};
93+
];

packages/core/src/mappings/FlatList.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import {
33
createNumColumnsType,
44
createStaticBoolProp,
55
CONTAINER_COMPONENT_STYLES_SECTIONS,
6+
Triggers,
7+
createActionProp,
8+
createStaticNumberProp,
69
} from "@draftbit/types";
710

811
export const SEED_DATA = {
@@ -14,7 +17,10 @@ export const SEED_DATA = {
1417
layout: {
1518
flex: 1,
1619
},
20+
triggers: [Triggers.OnRefresh, Triggers.OnEndReached],
1721
props: {
22+
onRefresh: createActionProp(),
23+
onEndReached: createActionProp(),
1824
horizontal: createStaticBoolProp({
1925
label: "Horizontal",
2026
description: "Render list horizontally",
@@ -26,5 +32,15 @@ export const SEED_DATA = {
2632
numColumns: createNumColumnsType({
2733
editable: true,
2834
}),
35+
initialNumToRender: createStaticBoolProp({
36+
label: "Initial Num To Render",
37+
descriprion: "How many items to render in the initial batch",
38+
}),
39+
onEndReachedThreshold: createStaticNumberProp({
40+
label: "End Reached Threshold",
41+
description:
42+
"How far from the end (in units of visible length of the list) the bottom edge of the list must be from the end of the content to trigger the onEndReached callback. Thus a value of 0.5 will trigger onEndReached when the end of the content is within half the visible length of the list.",
43+
defaultValue: 0.5,
44+
}),
2945
},
3046
};

packages/types/src/component-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const Triggers = {
1313
OnCheck: "ON_CHECK",
1414
OnUncheck: "ON_UNCHECK",
1515
OnPressIcon: "ON_PRESS_ICON",
16+
OnEndReached: "ON_END_REACHED",
1617
};
1718

1819
export const StylesPanelSections = {

0 commit comments

Comments
 (0)