Skip to content

Commit 51a0e8f

Browse files
committed
Simplify header
1 parent 9280e0b commit 51a0e8f

2 files changed

Lines changed: 50 additions & 37 deletions

File tree

example/app/(tabs)/fetchable.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ function ErrorOnRenderCheck() {
2222
)
2323
}
2424

25+
function Header({reload}: {reload: () => void}) {
26+
return (
27+
<Box
28+
flexDirection="column"
29+
gap="4"
30+
marginHorizontal={`${LIST_HORIZONTAL_MARGIN}`}
31+
marginBottom="16"
32+
flexShrink={1}
33+
>
34+
<Button onPress={reload} title="Reload" />
35+
</Box>
36+
)
37+
}
38+
2539
export default function FetchableScreen() {
2640
const [reloadKey, setReloadKey] = React.useState(1)
2741

@@ -31,26 +45,17 @@ export default function FetchableScreen() {
3145
}
3246

3347
const insets = useSafeAreaInsets()
48+
const contentContainerStyle = [
49+
styles.contentContainer,
50+
{paddingTop: insets.top, paddingBottom: insets.bottom},
51+
]
3452

3553
return (
3654
<ReactDataList.Fetchable
3755
renderer={
3856
<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-
}
57+
contentContainerStyle={contentContainerStyle}
58+
ListHeaderComponent={<Header reload={reload} />}
5459
/>
5560
}
5661
renderPendingRows={

example/app/(tabs)/index.tsx

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ function ErrorOnRenderCheck() {
3232
)
3333
}
3434

35+
function Header({
36+
toggleThorinAndCompany,
37+
jumbleFellowship,
38+
}: {
39+
toggleThorinAndCompany: () => void
40+
jumbleFellowship: () => void
41+
}) {
42+
return (
43+
<Box
44+
flexDirection="row"
45+
gap="4"
46+
marginHorizontal={`${LIST_HORIZONTAL_MARGIN}`}
47+
marginBottom="16"
48+
flexShrink={1}
49+
>
50+
<Button onPress={toggleThorinAndCompany} title="Toggle Thorin and Company" />
51+
<Button onPress={jumbleFellowship} title="Jumble Fellowship" />
52+
</Box>
53+
)
54+
}
55+
3556
export default function HomeScreen() {
3657
const [fellowship, setFellowship] =
3758
React.useState<ReadonlyArray<MiddleEarthCharacter>>(getJumbledFellowship)
@@ -47,34 +68,21 @@ export default function HomeScreen() {
4768
}
4869

4970
const insets = useSafeAreaInsets()
71+
const contentContainerStyle = [
72+
styles.contentContainer,
73+
{paddingTop: insets.top, paddingBottom: insets.bottom},
74+
]
5075

5176
return (
5277
<ReactDataList
5378
renderer={
5479
<FlashListRenderer
55-
contentContainerStyle={[
56-
styles.contentContainer,
57-
{paddingTop: insets.top, paddingBottom: insets.bottom},
58-
]}
80+
contentContainerStyle={contentContainerStyle}
5981
ListHeaderComponent={
60-
<Box
61-
flexDirection="row"
62-
gap="4"
63-
marginHorizontal={`${LIST_HORIZONTAL_MARGIN}`}
64-
marginBottom="16"
65-
flexShrink={1}
66-
>
67-
<Button
68-
onPress={toggleThorinAndCompany}
69-
title={
70-
isShowingThorinAndCompany
71-
? "Hide Thorin and Company"
72-
: "Show Thorin and Company"
73-
}
74-
style={styles.button}
75-
/>
76-
<Button onPress={jumbleFellowship} title="Jumble Fellowship" />
77-
</Box>
82+
<Header
83+
toggleThorinAndCompany={toggleThorinAndCompany}
84+
jumbleFellowship={jumbleFellowship}
85+
/>
7886
}
7987
/>
8088
}

0 commit comments

Comments
 (0)