Skip to content

Commit 9280e0b

Browse files
committed
Add a basic Fetchable example
1 parent 51530c0 commit 9280e0b

File tree

3 files changed

+106
-3
lines changed

3 files changed

+106
-3
lines changed

example/app/(tabs)/_layout.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ export default function TabLayout() {
3131
),
3232
}}
3333
/>
34+
<Tabs.Screen
35+
name="fetchable"
36+
options={{
37+
title: "Fetchable",
38+
tabBarIcon: ({color, size}) => (
39+
<FontAwesome size={size} name="code" color={color} />
40+
),
41+
}}
42+
/>
3443
</Tabs>
3544
)
3645
}

example/app/(tabs)/fetchable.tsx

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import * as React from "react"
2+
import {StyleSheet, View} from "react-native"
3+
import {useSafeAreaInsets} from "react-native-safe-area-context"
4+
5+
import {ReactDataList} from "@attio/react-data-list"
6+
7+
import {Box} from "../../src/components/design-system/box"
8+
import {Button} from "../../src/components/design-system/button"
9+
import {LIST_HORIZONTAL_MARGIN} from "../../src/components/design-system/constants"
10+
import {ListHeaderDataListRow} from "../../src/components/features/list-header/list-header-data-list-row"
11+
import {LoadingListItemDataListRow} from "../../src/components/features/loading-list-item/loading-list-item-data-list-row"
12+
import MiddleEarthHobbitCompanyDataListRows from "../../src/components/features/middle-earth-hobbit-company-data-list/middle-earth-hobbit-company-data-list-rows"
13+
import {FlashListRenderer} from "../../src/data-list/flashlist-renderer"
14+
15+
function ErrorOnRenderCheck() {
16+
return (
17+
<View
18+
onLayout={() => {
19+
throw new Error("This never happens as we evaluate descriptors before first paint.")
20+
}}
21+
/>
22+
)
23+
}
24+
25+
export default function FetchableScreen() {
26+
const [reloadKey, setReloadKey] = React.useState(1)
27+
28+
// Jumble fellowship to test recreating list.
29+
const reload = () => {
30+
setReloadKey((k) => k + 1)
31+
}
32+
33+
const insets = useSafeAreaInsets()
34+
35+
return (
36+
<ReactDataList.Fetchable
37+
renderer={
38+
<FlashListRenderer
39+
contentContainerStyle={[
40+
styles.contentContainer,
41+
{paddingTop: insets.top, paddingBottom: insets.bottom},
42+
]}
43+
ListHeaderComponent={
44+
<Box
45+
flexDirection="column"
46+
gap="4"
47+
marginHorizontal={`${LIST_HORIZONTAL_MARGIN}`}
48+
marginBottom="16"
49+
flexShrink={1}
50+
>
51+
<Button onPress={reload} title="Reload" />
52+
</Box>
53+
}
54+
/>
55+
}
56+
renderPendingRows={
57+
<>
58+
<ListHeaderDataListRow title="Thorin and Company" />
59+
<LoadingListItemDataListRow />
60+
<LoadingListItemDataListRow />
61+
<LoadingListItemDataListRow />
62+
<LoadingListItemDataListRow />
63+
<LoadingListItemDataListRow />
64+
<LoadingListItemDataListRow />
65+
</>
66+
}
67+
renderEmpty={() => (
68+
<View style={styles.alert}>
69+
<ErrorOnRenderCheck />
70+
</View>
71+
)}
72+
>
73+
<ListHeaderDataListRow title="Thorin and Company" />
74+
<MiddleEarthHobbitCompanyDataListRows key={reloadKey} />
75+
</ReactDataList.Fetchable>
76+
)
77+
}
78+
79+
const styles = StyleSheet.create({
80+
container: {
81+
flex: 1,
82+
},
83+
button: {
84+
flex: 1,
85+
},
86+
contentContainer: {
87+
marginBottom: 64,
88+
},
89+
alert: {
90+
width: "100%",
91+
aspectRatio: 1,
92+
backgroundColor: "red",
93+
},
94+
})

example/src/components/features/middle-earth-hobbit-company-data-list/middle-earth-hobbit-company-data-list-rows.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import {CharacterListItemDataListRow} from "../character-list-item/character-lis
22
import {useMiddleEarthHobbitCompanyData} from "./use-middle-earth-hobbit-company-data"
33

44
export default function MiddleEarthHobbitCompanyDataListRows() {
5-
const places = useMiddleEarthHobbitCompanyData()
5+
const characters = useMiddleEarthHobbitCompanyData()
66

7-
return places.map((p) => (
8-
<CharacterListItemDataListRow key={p.name} name={p.name} race={p.race} url={p.url} />
7+
return characters.map((c) => (
8+
<CharacterListItemDataListRow key={c.name} name={c.name} race={c.race} url={c.url} />
99
))
1010
}

0 commit comments

Comments
 (0)