|
| 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 | +}) |
0 commit comments