|
| 1 | +import React from 'react'; |
| 2 | +import { View, Text, StyleSheet, Pressable } from 'react-native'; |
| 3 | +import { useRouter, Link } from 'expo-router'; |
| 4 | +import FontAwesome from '@expo/vector-icons/FontAwesome'; |
| 5 | +import Colors from '@/constants/Colors'; |
| 6 | +import { useColorScheme } from '@/hooks/useColorScheme'; |
| 7 | + |
| 8 | +interface CustomHeaderProps { |
| 9 | + title: string; |
| 10 | + showBackButton?: boolean; |
| 11 | + showModalButton?: boolean; |
| 12 | +} |
| 13 | + |
| 14 | +export default function CustomHeader({ title, showBackButton = false, showModalButton = false }: CustomHeaderProps) { |
| 15 | + const router = useRouter(); |
| 16 | + const colorScheme = useColorScheme(); |
| 17 | + const textColor = Colors[colorScheme ?? 'light'].text; |
| 18 | + |
| 19 | + return ( |
| 20 | + <View style={styles.container}> |
| 21 | + {showBackButton && ( |
| 22 | + <Pressable style={styles.backButton} onPress={() => router.back()}> |
| 23 | + <FontAwesome name="arrow-left" size={22} color={textColor} /> |
| 24 | + </Pressable> |
| 25 | + )} |
| 26 | + |
| 27 | + <Text style={[styles.title, { color: textColor }]}>{title}</Text> |
| 28 | + |
| 29 | + {showModalButton && ( |
| 30 | + <Link href="/modal" asChild style={styles.rightButton}> |
| 31 | + <Pressable>{({ pressed }) => <FontAwesome name="info-circle" size={25} color={textColor} style={{ opacity: pressed ? 0.5 : 1 }} />}</Pressable> |
| 32 | + </Link> |
| 33 | + )} |
| 34 | + |
| 35 | + {!showModalButton && <View style={styles.placeholderRight} />} |
| 36 | + </View> |
| 37 | + ); |
| 38 | +} |
| 39 | + |
| 40 | +const styles = StyleSheet.create({ |
| 41 | + container: { |
| 42 | + height: 60, |
| 43 | + flexDirection: 'row', |
| 44 | + alignItems: 'center', |
| 45 | + justifyContent: 'space-between', |
| 46 | + paddingHorizontal: 15, |
| 47 | + backgroundColor: '#121212', |
| 48 | + borderBottomWidth: 1, |
| 49 | + borderBottomColor: '#333', |
| 50 | + paddingTop: 5, |
| 51 | + marginBottom: 5, |
| 52 | + }, |
| 53 | + backButton: { |
| 54 | + width: 40, |
| 55 | + height: 40, |
| 56 | + justifyContent: 'center', |
| 57 | + alignItems: 'center', |
| 58 | + }, |
| 59 | + title: { |
| 60 | + fontSize: 18, |
| 61 | + fontWeight: 'bold', |
| 62 | + flex: 1, |
| 63 | + textAlign: 'center', |
| 64 | + }, |
| 65 | + rightButton: { |
| 66 | + width: 40, |
| 67 | + height: 40, |
| 68 | + justifyContent: 'center', |
| 69 | + alignItems: 'center', |
| 70 | + }, |
| 71 | + placeholderRight: { |
| 72 | + width: 40, |
| 73 | + }, |
| 74 | +}); |
0 commit comments