header.tsx 1.2 KB

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