import React, { useEffect, useRef } from 'react'; import { View, StyleSheet, TouchableOpacity, Modal, ActivityIndicator, useWindowDimensions } from 'react-native'; import { useVideoPlayer, VideoView } from 'expo-video'; import { Ionicons } from '@expo/vector-icons'; import { LinearGradient } from 'expo-linear-gradient'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { colors, gradients } from '../../../theme'; interface FullScreenVideoModalProps { uri: string | null; visible: boolean; saving: boolean; onClose: () => void; onSave: () => void; } const FullScreenVideoModalComponent: React.FC = ({ uri, visible, saving, onClose, onSave, }) => { const { width: windowWidth, height: windowHeight } = useWindowDimensions(); const insets = useSafeAreaInsets(); // Use safe area insets for button positioning to avoid notch/dynamic island const buttonTop = insets.top + 10; const player = useVideoPlayer(uri ? { uri } : null, (setupPlayer) => { setupPlayer.loop = false; }); // Swap the source when a different video is shown, without reloading on // the initial mount (useVideoPlayer already loaded the first source). const mountedUriRef = useRef(uri); useEffect(() => { if (uri && uri !== mountedUriRef.current) { mountedUriRef.current = uri; player.replace({ uri }); } }, [uri, player]); // Play while the modal is visible, pause otherwise (there is no // declarative `shouldPlay` prop on `VideoView`). useEffect(() => { if (visible) { player.play(); } else { player.pause(); } }, [visible, player]); return ( {saving ? ( ) : ( )} {uri && ( )} ); }; export const FullScreenVideoModal = React.memo(FullScreenVideoModalComponent); const styles = StyleSheet.create({ overlay: { flex: 1, backgroundColor: 'rgba(0, 0, 0, 0.95)', justifyContent: 'center', alignItems: 'center', }, closeButton: { position: 'absolute', right: 20, zIndex: 10, }, saveButton: { position: 'absolute', left: 20, zIndex: 10, }, buttonGradient: { width: 44, height: 44, borderRadius: 22, justifyContent: 'center', alignItems: 'center', }, });