|
| 1 | +import Constants from "expo-constants"; |
| 2 | +import { useMemo } from "react"; |
| 3 | +import { StyleSheet, Text, View } from "react-native"; |
| 4 | +import { SafeAreaView } from "react-native-safe-area-context"; |
| 5 | + |
| 6 | +import BurgerButton from "../components/BurgerButton"; |
| 7 | +import { useAppTheme } from "../theme/useAppTheme"; |
| 8 | + |
| 9 | +type AboutScreenProps = { |
| 10 | + onOpenMenu: () => void; |
| 11 | +}; |
| 12 | + |
| 13 | +type VersionRowProps = { |
| 14 | + label: string; |
| 15 | + value: string; |
| 16 | +}; |
| 17 | + |
| 18 | +function VersionRow({ label, value }: VersionRowProps) { |
| 19 | + const { colors } = useAppTheme(); |
| 20 | + const styles = useMemo(() => createStyles(colors), [colors]); |
| 21 | + |
| 22 | + return ( |
| 23 | + <View style={styles.row}> |
| 24 | + <Text style={styles.rowLabel}>{label}</Text> |
| 25 | + <Text style={styles.rowValue}>{value}</Text> |
| 26 | + </View> |
| 27 | + ); |
| 28 | +} |
| 29 | + |
| 30 | +function coerceVersionValue(value: unknown): string { |
| 31 | + if (typeof value === "string" && value.trim().length > 0) return value; |
| 32 | + if (typeof value === "number" && Number.isFinite(value)) return String(value); |
| 33 | + return "Unavailable"; |
| 34 | +} |
| 35 | + |
| 36 | +export default function AboutScreen({ onOpenMenu }: AboutScreenProps) { |
| 37 | + const { colors } = useAppTheme(); |
| 38 | + const styles = useMemo(() => createStyles(colors), [colors]); |
| 39 | + |
| 40 | + const appVersion = coerceVersionValue(Constants.nativeAppVersion); |
| 41 | + const buildVersion = coerceVersionValue(Constants.nativeBuildVersion); |
| 42 | + const configuredVersion = coerceVersionValue(Constants.expoConfig?.version); |
| 43 | + const runtimeVersion = coerceVersionValue(Constants.expoConfig?.runtimeVersion); |
| 44 | + |
| 45 | + return ( |
| 46 | + <SafeAreaView style={styles.safe} edges={["top", "left", "right", "bottom"]}> |
| 47 | + <View style={styles.headerRow}> |
| 48 | + <BurgerButton onPress={onOpenMenu} /> |
| 49 | + <View style={styles.headerMeta}> |
| 50 | + <Text style={styles.title} accessibilityRole="header"> |
| 51 | + About |
| 52 | + </Text> |
| 53 | + <Text style={styles.subtitle}>Build and version information for this app.</Text> |
| 54 | + </View> |
| 55 | + </View> |
| 56 | + |
| 57 | + <View style={styles.content}> |
| 58 | + <View style={styles.card}> |
| 59 | + <VersionRow label="App Version" value={appVersion} /> |
| 60 | + <VersionRow label="Build" value={buildVersion} /> |
| 61 | + <VersionRow label="Configured Version" value={configuredVersion} /> |
| 62 | + <VersionRow label="Runtime Version" value={runtimeVersion} /> |
| 63 | + </View> |
| 64 | + </View> |
| 65 | + </SafeAreaView> |
| 66 | + ); |
| 67 | +} |
| 68 | + |
| 69 | +function createStyles(colors: ReturnType<typeof useAppTheme>["colors"]) { |
| 70 | + return StyleSheet.create({ |
| 71 | + safe: { |
| 72 | + flex: 1, |
| 73 | + backgroundColor: colors.background, |
| 74 | + }, |
| 75 | + headerRow: { |
| 76 | + paddingHorizontal: 12, |
| 77 | + paddingTop: 8, |
| 78 | + flexDirection: "row", |
| 79 | + alignItems: "center", |
| 80 | + gap: 10, |
| 81 | + }, |
| 82 | + headerMeta: { |
| 83 | + flex: 1, |
| 84 | + gap: 2, |
| 85 | + }, |
| 86 | + title: { |
| 87 | + color: colors.textPrimary, |
| 88 | + fontSize: 21, |
| 89 | + fontWeight: "800", |
| 90 | + }, |
| 91 | + subtitle: { |
| 92 | + color: colors.textMuted, |
| 93 | + fontSize: 12, |
| 94 | + lineHeight: 17, |
| 95 | + }, |
| 96 | + content: { |
| 97 | + paddingHorizontal: 12, |
| 98 | + paddingTop: 14, |
| 99 | + gap: 12, |
| 100 | + }, |
| 101 | + card: { |
| 102 | + borderRadius: 12, |
| 103 | + borderWidth: 1, |
| 104 | + borderColor: colors.border, |
| 105 | + backgroundColor: colors.surface, |
| 106 | + paddingVertical: 12, |
| 107 | + paddingHorizontal: 12, |
| 108 | + gap: 10, |
| 109 | + }, |
| 110 | + row: { |
| 111 | + flexDirection: "row", |
| 112 | + alignItems: "center", |
| 113 | + justifyContent: "space-between", |
| 114 | + gap: 10, |
| 115 | + }, |
| 116 | + rowLabel: { |
| 117 | + flex: 1, |
| 118 | + color: colors.textMuted, |
| 119 | + fontSize: 12, |
| 120 | + fontWeight: "600", |
| 121 | + }, |
| 122 | + rowValue: { |
| 123 | + color: colors.textPrimary, |
| 124 | + fontSize: 13, |
| 125 | + fontWeight: "700", |
| 126 | + }, |
| 127 | + }); |
| 128 | +} |
0 commit comments