import React, {memo, type RefObject, useMemo} from 'react'; import { type TextStyle, type StyleProp, Animated, TouchableWithoutFeedback, } from 'react-native'; import {useScrollContentOffset} from '../contexts/ScrollContentOffsetContext'; import {usePickerItemHeight} from '../contexts/PickerItemHeightContext'; import type {ListMethods, RenderItem} from '../types'; import type {Faces} from './faces'; type PickerItemContainerProps = { listRef: RefObject; item: any; index: number; faces: ReadonlyArray; renderItem: RenderItem; itemTextStyle: StyleProp | undefined; enableScrollByTapOnItem: boolean | undefined; readOnly: boolean | undefined; }; const PickerItemContainer = ({ listRef, index, item, faces, renderItem, itemTextStyle, enableScrollByTapOnItem, readOnly, }: PickerItemContainerProps) => { const offset = useScrollContentOffset(); const height = usePickerItemHeight(); const {opacity, rotateX, translateY} = useMemo(() => { const inputRange = faces.map((f) => height * (index + f.index)); return { opacity: offset.interpolate({ inputRange: inputRange, outputRange: faces.map((x) => x.opacity), extrapolate: 'clamp', }), rotateX: offset.interpolate({ inputRange: inputRange, outputRange: faces.map((x) => `${x.deg}deg`), extrapolate: 'extend', }), translateY: offset.interpolate({ inputRange: inputRange, outputRange: faces.map((x) => x.offsetY), extrapolate: 'extend', }), }; }, [faces, height, index, offset]); const renderAnimatedView = () => { return ( {renderItem({ item, index, itemTextStyle, })} ); }; if (!enableScrollByTapOnItem || readOnly) { return renderAnimatedView(); } const scrollToItem = () => listRef.current?.scrollToIndex({ index, animated: true, }); return ( {renderAnimatedView()} ); }; export default memo(PickerItemContainer);