This repository was archived by the owner on Jan 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathCustomHeaderScreen.tsx
89 lines (80 loc) · 2.13 KB
/
CustomHeaderScreen.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
78
79
80
81
82
83
84
85
86
87
88
89
import * as React from 'react';
import { Text, TouchableOpacity, Animated, View } from 'react-native';
import { StackNavigationProp, StackHeaderProps } from '@react-navigation/stack';
import { useCollapsibleHeader } from 'react-navigation-collapsible';
import { StackParamList } from '../App';
import { createRow } from './Row';
const data: number[] = [];
for (let i = 0; i < 100; i++) {
data.push(i);
}
type ScreenProps = {
navigation: StackNavigationProp<StackParamList>;
};
export const renderCustomHeader = ({
navigation,
options,
route,
progress,
}: StackHeaderProps) => {
const title = options.headerTitle || options.title || route.name;
return (
<View
style={{
width: '100%',
height: 200,
backgroundColor: 'blue',
padding: 20,
}}>
<View
style={{
flex: 1,
backgroundColor: 'gray',
alignItems: 'center',
justifyContent: 'center',
}}>
<Text
style={{
fontSize: 32,
color: 'white',
marginBottom: 10,
}}>
{title}
</Text>
{progress?.previous && (
<TouchableOpacity onPress={navigation.goBack}>
<View>
<Text
style={{
fontSize: 16,
fontWeight: 'bold',
color: 'white',
}}>
{'<< GO BACK'}
</Text>
</View>
</TouchableOpacity>
)}
</View>
</View>
);
};
const CustomHeaderScreen = ({ navigation }: ScreenProps) => {
const { onScroll, containerPaddingTop, scrollIndicatorInsetTop } =
useCollapsibleHeader({
navigationOptions: {
header: renderCustomHeader,
},
});
return (
<Animated.FlatList
data={data}
onScroll={onScroll}
contentContainerStyle={{ paddingTop: containerPaddingTop }}
scrollIndicatorInsets={{ top: scrollIndicatorInsetTop }}
renderItem={createRow(() => navigation.navigate('CustomHeaderDetail'))}
keyExtractor={(item: any) => item.toString()}
/>
);
};
export { CustomHeaderScreen };