header.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { ThemedText } from '@/components/themed-text';
  2. import { ThemedView } from '@/components/themed-view';
  3. import { useThemeColor } from '@/hooks/use-theme-color';
  4. import { ActivityIndicator, Pressable, StyleSheet } from "react-native";
  5. import { Back } from "./icons";
  6. type Props = {
  7. title: string;
  8. loading: boolean;
  9. canGoBack: boolean;
  10. onBack: () => void;
  11. };
  12. export default function Header({ title, loading, canGoBack, onBack }: Props) {
  13. let iconColor = useThemeColor({}, 'icon');
  14. let iconColorDisabled = useThemeColor({}, 'iconDisabled');
  15. if (!canGoBack)
  16. iconColor = iconColorDisabled;
  17. return (
  18. <ThemedView style={styles.container}>
  19. <Pressable
  20. onPress={onBack}
  21. disabled={!canGoBack}
  22. style={styles.back}
  23. >
  24. <ThemedView style={styles.backText}>
  25. <Back size={24} color={iconColor} />
  26. </ThemedView>
  27. </Pressable>
  28. <ThemedText numberOfLines={1} style={styles.title}>
  29. {title || " "}
  30. </ThemedText>
  31. <ThemedView style={styles.right}>
  32. {loading && <ActivityIndicator size="small" />}
  33. </ThemedView>
  34. </ThemedView>
  35. );
  36. }
  37. const styles = StyleSheet.create({
  38. container: {
  39. height: 56,
  40. flexDirection: "row",
  41. alignItems: "center",
  42. paddingHorizontal: 12,
  43. borderBottomWidth: 1,
  44. },
  45. back: {
  46. width: 40,
  47. justifyContent: "center",
  48. alignItems: "center",
  49. },
  50. backText: { fontSize: 20 },
  51. disabled: { opacity: 0.3 },
  52. title: {
  53. flex: 1,
  54. fontSize: 16,
  55. fontWeight: "600",
  56. },
  57. right: {
  58. width: 40,
  59. alignItems: "center",
  60. },
  61. });