header.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. type Props = {
  6. title: string;
  7. loading: boolean;
  8. canGoBack: boolean;
  9. onBack: () => void;
  10. };
  11. export default function Header({ title, loading, canGoBack, onBack }: Props) {
  12. const borderColor = useThemeColor({}, 'border');
  13. return (
  14. <ThemedView style={[{ borderColor }, styles.container]}>
  15. <Pressable
  16. onPress={onBack}
  17. disabled={!canGoBack}
  18. style={styles.back}
  19. >
  20. <ThemedText style={[styles.backText, !canGoBack && styles.disabled]}>
  21. ←
  22. </ThemedText>
  23. </Pressable>
  24. <ThemedText numberOfLines={1} style={styles.title}>
  25. {title || " "}
  26. </ThemedText>
  27. <ThemedView style={styles.right}>
  28. {loading && <ActivityIndicator size="small" />}
  29. </ThemedView>
  30. </ThemedView>
  31. );
  32. }
  33. const styles = StyleSheet.create({
  34. container: {
  35. height: 56,
  36. flexDirection: "row",
  37. alignItems: "center",
  38. paddingHorizontal: 12,
  39. borderBottomWidth: 1,
  40. },
  41. back: {
  42. width: 40,
  43. justifyContent: "center",
  44. alignItems: "center",
  45. },
  46. backText: { fontSize: 20 },
  47. disabled: { opacity: 0.3 },
  48. title: {
  49. flex: 1,
  50. fontSize: 16,
  51. fontWeight: "600",
  52. },
  53. right: {
  54. width: 40,
  55. alignItems: "center",
  56. },
  57. });