|
| 1 | +import { |
| 2 | + Platform, |
| 3 | + Pressable, |
| 4 | + ScrollView, |
| 5 | + StyleSheet, |
| 6 | + Text, |
| 7 | + View, |
| 8 | +} from 'react-native'; |
| 9 | +import { Image } from 'expo-image'; |
| 10 | + |
| 11 | +import type { ExifTags } from '@lodev09/react-native-exify'; |
| 12 | + |
| 13 | +interface ExifOverlayProps { |
| 14 | + uri?: string; |
| 15 | + tags: ExifTags | null; |
| 16 | + onClose: () => void; |
| 17 | +} |
| 18 | + |
| 19 | +const formatValue = (value: unknown): string => { |
| 20 | + if (Array.isArray(value)) return value.join(', '); |
| 21 | + if (typeof value === 'number') |
| 22 | + return String(Math.round(value * 1000000) / 1000000); |
| 23 | + return String(value); |
| 24 | +}; |
| 25 | + |
| 26 | +export const ExifOverlay = ({ uri, tags, onClose }: ExifOverlayProps) => { |
| 27 | + if (!tags) return null; |
| 28 | + |
| 29 | + const entries = Object.entries(tags).sort(([a], [b]) => a.localeCompare(b)); |
| 30 | + |
| 31 | + return ( |
| 32 | + <View style={styles.backdrop}> |
| 33 | + <View style={styles.panel}> |
| 34 | + <View style={styles.header}> |
| 35 | + <Text style={styles.title}>EXIF</Text> |
| 36 | + <View style={styles.headerRight}> |
| 37 | + <Text style={styles.count}>{entries.length} tags</Text> |
| 38 | + <Pressable style={styles.closeButton} onPress={onClose}> |
| 39 | + <View style={styles.closeIcon}> |
| 40 | + <Text style={styles.closeIconText}>✕</Text> |
| 41 | + </View> |
| 42 | + </Pressable> |
| 43 | + </View> |
| 44 | + </View> |
| 45 | + {uri && ( |
| 46 | + <Image source={{ uri }} style={styles.preview} contentFit="cover" /> |
| 47 | + )} |
| 48 | + {uri && ( |
| 49 | + <Text style={styles.uri} numberOfLines={2} selectable> |
| 50 | + {uri} |
| 51 | + </Text> |
| 52 | + )} |
| 53 | + <ScrollView style={styles.scroll} showsVerticalScrollIndicator={false}> |
| 54 | + {entries.map(([key, value]) => ( |
| 55 | + <View key={key} style={styles.row}> |
| 56 | + <Text style={styles.key} numberOfLines={1}> |
| 57 | + {key} |
| 58 | + </Text> |
| 59 | + <Text style={styles.value} numberOfLines={2} selectable> |
| 60 | + {formatValue(value)} |
| 61 | + </Text> |
| 62 | + </View> |
| 63 | + ))} |
| 64 | + </ScrollView> |
| 65 | + </View> |
| 66 | + </View> |
| 67 | + ); |
| 68 | +}; |
| 69 | + |
| 70 | +const styles = StyleSheet.create({ |
| 71 | + backdrop: { |
| 72 | + ...StyleSheet.absoluteFillObject, |
| 73 | + justifyContent: 'center', |
| 74 | + padding: 20, |
| 75 | + }, |
| 76 | + panel: { |
| 77 | + flex: 1, |
| 78 | + backgroundColor: 'rgba(0, 0, 0, 0.8)', |
| 79 | + borderRadius: 16, |
| 80 | + overflow: 'hidden', |
| 81 | + marginTop: 60, |
| 82 | + marginBottom: 20, |
| 83 | + }, |
| 84 | + header: { |
| 85 | + flexDirection: 'row', |
| 86 | + alignItems: 'center', |
| 87 | + justifyContent: 'space-between', |
| 88 | + paddingHorizontal: 16, |
| 89 | + paddingVertical: 12, |
| 90 | + borderBottomWidth: StyleSheet.hairlineWidth, |
| 91 | + borderBottomColor: 'rgba(255, 255, 255, 0.15)', |
| 92 | + }, |
| 93 | + title: { |
| 94 | + color: '#fff', |
| 95 | + fontSize: 15, |
| 96 | + fontWeight: '700', |
| 97 | + letterSpacing: 1, |
| 98 | + }, |
| 99 | + headerRight: { |
| 100 | + flexDirection: 'row', |
| 101 | + alignItems: 'center', |
| 102 | + gap: 10, |
| 103 | + }, |
| 104 | + count: { |
| 105 | + color: 'rgba(255, 255, 255, 0.4)', |
| 106 | + fontSize: 13, |
| 107 | + }, |
| 108 | + closeButton: { |
| 109 | + padding: 2, |
| 110 | + }, |
| 111 | + closeIcon: { |
| 112 | + width: 26, |
| 113 | + height: 26, |
| 114 | + borderRadius: 13, |
| 115 | + backgroundColor: 'rgba(255, 255, 255, 0.15)', |
| 116 | + alignItems: 'center', |
| 117 | + justifyContent: 'center', |
| 118 | + }, |
| 119 | + closeIconText: { |
| 120 | + color: 'rgba(255, 255, 255, 0.6)', |
| 121 | + fontSize: 12, |
| 122 | + fontWeight: '600', |
| 123 | + }, |
| 124 | + preview: { |
| 125 | + height: 120, |
| 126 | + borderBottomWidth: StyleSheet.hairlineWidth, |
| 127 | + borderBottomColor: 'rgba(255, 255, 255, 0.1)', |
| 128 | + }, |
| 129 | + uri: { |
| 130 | + color: 'rgba(255, 255, 255, 0.35)', |
| 131 | + fontSize: 11, |
| 132 | + fontFamily: Platform.select({ ios: 'Menlo', android: 'monospace' }), |
| 133 | + paddingHorizontal: 16, |
| 134 | + paddingVertical: 8, |
| 135 | + borderBottomWidth: StyleSheet.hairlineWidth, |
| 136 | + borderBottomColor: 'rgba(255, 255, 255, 0.1)', |
| 137 | + }, |
| 138 | + scroll: { |
| 139 | + flex: 1, |
| 140 | + }, |
| 141 | + row: { |
| 142 | + flexDirection: 'row', |
| 143 | + paddingHorizontal: 16, |
| 144 | + paddingVertical: 8, |
| 145 | + borderBottomWidth: StyleSheet.hairlineWidth, |
| 146 | + borderBottomColor: 'rgba(255, 255, 255, 0.06)', |
| 147 | + }, |
| 148 | + key: { |
| 149 | + width: 140, |
| 150 | + color: 'rgba(255, 255, 255, 0.5)', |
| 151 | + fontSize: 12, |
| 152 | + fontFamily: Platform.select({ ios: 'Menlo', android: 'monospace' }), |
| 153 | + }, |
| 154 | + value: { |
| 155 | + flex: 1, |
| 156 | + color: '#fff', |
| 157 | + fontSize: 12, |
| 158 | + fontFamily: Platform.select({ ios: 'Menlo', android: 'monospace' }), |
| 159 | + }, |
| 160 | +}); |
0 commit comments