import React, {useCallback, useEffect, useState} from 'react' import { Image, ImageStyle, Pressable, StyleSheet, TouchableOpacity, TouchableWithoutFeedback, View, ViewStyle, } from 'react-native' import { FontAwesomeIcon, FontAwesomeIconStyle, } from '@fortawesome/react-native-fontawesome' import {msg} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useWebBodyScrollLock} from '#/lib/hooks/useWebBodyScrollLock' import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' import {colors, s} from '#/lib/styles' import {useLightbox, useLightboxControls} from '#/state/lightbox' import {Text} from '../util/text/Text' import {ImageSource} from './ImageViewing/@types' import ImageDefaultHeader from './ImageViewing/components/ImageDefaultHeader' export function Lightbox() { const {activeLightbox} = useLightbox() const {closeLightbox} = useLightboxControls() const isActive = !!activeLightbox useWebBodyScrollLock(isActive) if (!isActive) { return null } const initialIndex = activeLightbox.index const imgs = activeLightbox.images return ( ) } function LightboxInner({ imgs, initialIndex = 0, onClose, }: { imgs: ImageSource[] initialIndex: number onClose: () => void }) { const {_} = useLingui() const [index, setIndex] = useState(initialIndex) const [isAltExpanded, setAltExpanded] = useState(false) const canGoLeft = index >= 1 const canGoRight = index < imgs.length - 1 const onPressLeft = useCallback(() => { if (canGoLeft) { setIndex(index - 1) } }, [index, canGoLeft]) const onPressRight = useCallback(() => { if (canGoRight) { setIndex(index + 1) } }, [index, canGoRight]) const onKeyDown = useCallback( (e: KeyboardEvent) => { if (e.key === 'Escape') { onClose() } else if (e.key === 'ArrowLeft') { onPressLeft() } else if (e.key === 'ArrowRight') { onPressRight() } }, [onClose, onPressLeft, onPressRight], ) useEffect(() => { window.addEventListener('keydown', onKeyDown) return () => window.removeEventListener('keydown', onKeyDown) }, [onKeyDown]) const {isTabletOrDesktop} = useWebMediaQueries() const btnStyle = React.useMemo(() => { return isTabletOrDesktop ? styles.btnTablet : styles.btnMobile }, [isTabletOrDesktop]) const iconSize = React.useMemo(() => { return isTabletOrDesktop ? 32 : 24 }, [isTabletOrDesktop]) const img = imgs[index] const isAvi = img.type === 'circle-avi' || img.type === 'rect-avi' return ( {isAvi ? ( {img.alt} ) : ( {canGoLeft && ( )} {canGoRight && ( )} )} {img.alt ? ( { setAltExpanded(!isAltExpanded) }}> {img.alt} ) : null} ) } const styles = StyleSheet.create({ mask: { // @ts-ignore position: 'fixed', top: 0, left: 0, width: '100%', height: '100%', backgroundColor: '#000c', }, imageCenterer: { flex: 1, alignItems: 'center', justifyContent: 'center', }, image: { width: '100%', height: '100%', resizeMode: 'contain', }, aviCenterer: { flex: 1, alignItems: 'center', justifyContent: 'center', }, avi: { // @ts-ignore web-only maxWidth: `calc(min(400px, 100vw))`, // @ts-ignore web-only maxHeight: `calc(min(400px, 100vh))`, padding: 16, boxSizing: 'border-box', }, icon: { color: colors.white, }, closeBtn: { position: 'absolute', top: 10, right: 10, }, btn: { position: 'absolute', backgroundColor: '#00000077', justifyContent: 'center', alignItems: 'center', }, btnTablet: { width: 50, height: 50, borderRadius: 25, left: 30, right: 30, }, btnMobile: { width: 44, height: 44, borderRadius: 22, left: 20, right: 20, }, leftBtn: { right: 'auto', top: '50%', }, rightBtn: { left: 'auto', top: '50%', }, footer: { paddingHorizontal: 32, paddingVertical: 24, backgroundColor: colors.black, }, blurredBackground: { backdropFilter: 'blur(10px)', WebkitBackdropFilter: 'blur(10px)', } as ViewStyle, })