import React, { forwardRef } from 'react'; import { useSharedValue } from 'react-native-reanimated'; import { clamp } from '../../commons/utils/clamp'; import { useVector } from '../../commons/hooks/useVector'; import { useSizeVector } from '../../commons/hooks/useSizeVector'; import Gallery from './Gallery'; import { GalleryContext, type GalleryContextType } from './context'; import type { GalleryProps, GalleryRefType } from './types'; const GalleryProvider = ( props: GalleryProps, ref?: React.ForwardedRef ) => { const startIndex = clamp(props.initialIndex ?? 0, 0, props.data.length - 1); const activeIndex = useSharedValue(startIndex); const rootSize = useSizeVector(0, 0); const rootChildSize = useSizeVector(0, 0); const translate = useVector(0, 0); const scale = useSharedValue(1); const scroll = useSharedValue(0); const scrollOffset = useSharedValue(0); const isScrolling = useSharedValue(false); const hasZoomed = useSharedValue(false); const overflow = useSharedValue<'hidden' | 'visible'>('hidden'); const hideAdjacentItems = useSharedValue(false); const context: GalleryContextType = { rootSize, rootChildSize, scroll, scrollOffset, translate, activeIndex, isScrolling, scale, hasZoomed, overflow, hideAdjacentItems, }; return ( ); }; type GalleryPropsWithRef = GalleryProps & { ref?: React.ForwardedRef; }; export default forwardRef(GalleryProvider) as ( props: GalleryPropsWithRef ) => ReturnType;