Matthias Nott
2026-03-07 3c02569a045aa5303f97142893f7cfef86eaf9b3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import React, { useCallback } from "react";
import {
  Alert,
  Dimensions,
  Image,
  Modal,
  Pressable,
  ScrollView,
  Text,
  View,
} from "react-native";
import { cacheDirectory, writeAsStringAsync } from "expo-file-system/legacy";
import * as Clipboard from "expo-clipboard";
import * as Sharing from "expo-sharing";
/** Apple-style share icon (square with upward arrow) */
function ShareIcon({ size = 18, color = "#fff" }: { size?: number; color?: string }) {
  const boxSize = size * 0.7;
  const arrowWidth = 2;
  return (
    <View style={{ width: size, height: size, alignItems: "center", justifyContent: "flex-end" }}>
      {/* Arrow shaft + head */}
      <View
        style={{
          position: "absolute",
          top: 0,
          width: arrowWidth,
          height: size * 0.65,
          backgroundColor: color,
          borderRadius: 1,
        }}
      />
      <View
        style={{
          position: "absolute",
          top: 0,
          width: 0,
          height: 0,
          borderLeftWidth: size * 0.22,
          borderRightWidth: size * 0.22,
          borderBottomWidth: size * 0.25,
          borderLeftColor: "transparent",
          borderRightColor: "transparent",
          borderBottomColor: color,
          transform: [{ translateY: -size * 0.12 }],
        }}
      />
      {/* Open box (3 sides) */}
      <View
        style={{
          width: boxSize,
          height: boxSize * 0.7,
          borderWidth: arrowWidth,
          borderTopWidth: 0,
          borderColor: color,
          borderRadius: 2,
        }}
      />
    </View>
  );
}
interface ImageViewerProps {
  visible: boolean;
  imageBase64: string;
  onClose: () => void;
}
export function ImageViewer({ visible, imageBase64, onClose }: ImageViewerProps) {
  const { width, height } = Dimensions.get("window");
  const handleCopy = useCallback(async () => {
    try {
      await Clipboard.setImageAsync(imageBase64);
    } catch (err: any) {
      Alert.alert("Copy Error", err?.message ?? String(err));
    }
  }, [imageBase64]);
  const handleShare = useCallback(async () => {
    try {
      const fileUri = `${cacheDirectory}pailot-screenshot-${Date.now()}.png`;
      await writeAsStringAsync(fileUri, imageBase64, {
        encoding: "base64",
      });
      if (!(await Sharing.isAvailableAsync())) {
        Alert.alert("Sharing not available on this device");
        return;
      }
      await Sharing.shareAsync(fileUri, { mimeType: "image/png" });
    } catch (err: any) {
      if (err?.message?.includes("User did not share")) return;
      Alert.alert("Share Error", err?.message ?? String(err));
    }
  }, [imageBase64]);
  return (
    <Modal
      visible={visible}
      transparent
      animationType="fade"
      onRequestClose={onClose}
    >
      <View style={{ flex: 1, backgroundColor: "rgba(0,0,0,0.95)" }}>
        {/* Top bar: share + close */}
        <View
          style={{
            position: "absolute",
            top: 60,
            right: 20,
            zIndex: 10,
            flexDirection: "row",
            gap: 12,
          }}
        >
          <Pressable
            onPress={handleCopy}
            hitSlop={{ top: 12, bottom: 12, left: 12, right: 12 }}
            style={{
              width: 40,
              height: 40,
              borderRadius: 20,
              backgroundColor: "rgba(255,255,255,0.15)",
              alignItems: "center",
              justifyContent: "center",
            }}
          >
            <Text style={{ color: "#fff", fontSize: 18 }}>📋</Text>
          </Pressable>
          <Pressable
            onPress={handleShare}
            hitSlop={{ top: 12, bottom: 12, left: 12, right: 12 }}
            style={{
              width: 40,
              height: 40,
              borderRadius: 20,
              backgroundColor: "rgba(255,255,255,0.15)",
              alignItems: "center",
              justifyContent: "center",
            }}
          >
            <ShareIcon size={20} color="#fff" />
          </Pressable>
          <Pressable
            onPress={onClose}
            hitSlop={{ top: 12, bottom: 12, left: 12, right: 12 }}
            style={{
              width: 40,
              height: 40,
              borderRadius: 20,
              backgroundColor: "rgba(255,255,255,0.15)",
              alignItems: "center",
              justifyContent: "center",
            }}
          >
            <Text style={{ color: "#fff", fontSize: 20, fontWeight: "600" }}>
              âœ•
            </Text>
          </Pressable>
        </View>
        {/* Zoomable image */}
        <ScrollView
          maximumZoomScale={5}
          minimumZoomScale={1}
          centerContent
          contentContainerStyle={{
            flex: 1,
            justifyContent: "center",
            alignItems: "center",
          }}
          showsVerticalScrollIndicator={false}
          showsHorizontalScrollIndicator={false}
        >
          <Image
            source={{ uri: `data:image/png;base64,${imageBase64}` }}
            style={{ width, height: height * 0.85 }}
            resizeMode="contain"
          />
        </ScrollView>
      </View>
    </Modal>
  );
}