import React, { useEffect, useRef, useState } from "react"; import { Dimensions, FlatList, Image, KeyboardAvoidingView, Modal, Platform, Pressable, Text, TextInput, View, } from "react-native"; import { useTheme } from "../../contexts/ThemeContext"; interface ImageItem { uri: string; } interface ImageCaptionModalProps { visible: boolean; images: ImageItem[]; onSend: (caption: string) => void; onCancel: () => void; } export function ImageCaptionModal({ visible, images, onSend, onCancel }: ImageCaptionModalProps) { const { colors } = useTheme(); const [caption, setCaption] = useState(""); const [selectedIndex, setSelectedIndex] = useState(0); const inputRef = useRef(null); const { width, height } = Dimensions.get("window"); useEffect(() => { if (visible) { setCaption(""); setSelectedIndex(0); setTimeout(() => inputRef.current?.focus(), 300); } }, [visible]); const handleSend = () => { onSend(caption.trim()); setCaption(""); }; const currentImage = images[selectedIndex]?.uri ?? ""; const isMultiple = images.length > 1; return ( {/* Top bar with cancel + count */} Cancel {isMultiple && ( {selectedIndex + 1} / {images.length} )} {/* Image preview */} {/* Thumbnail strip — only for multiple images */} {isMultiple && ( String(i)} contentContainerStyle={{ paddingHorizontal: 12, paddingVertical: 8, gap: 8 }} renderItem={({ item, index }) => ( setSelectedIndex(index)}> )} /> )} {/* Caption input + send */} {"\u2191"} ); }