import React, { useEffect, useRef, useState } from 'react'; import { Animated } from 'react-native'; import GradientText from 'src/components/GradientText'; import { MenuContent, LinesBox, Line } from './styles'; import useAnimationVertically from './useAnimation'; export interface MenuContentProps { width?: number; height?: number; borderRadius?: number; backgroundColor?: string; activeOpacity?: number; lineColor?: string; disableBoxShadow?: boolean; onPress?: () => void; } export interface linePositionRefsProps { topLinePosition?: number; middleLinePosition?: number; bottomLinePosition?: number; } export function AnimatedMenuVertically(menuProps: MenuContentProps) { const [linePositionRefs, setLinePositionRefs] = useState({} as linePositionRefsProps) const { toogleAnimations, topLineAnimatedStyle, middleLineAnimatedStyle, bottomLineAnimatedStyle, } = useAnimationVertically(linePositionRefs); const setLinePositionByKey = (key: keyof linePositionRefsProps, positionYValue: number) => { setLinePositionRefs({ ...linePositionRefs, [key]: positionYValue }) } return ( { toogleAnimations() menuProps.onPress && menuProps.onPress() }} > { const positionY = event.nativeEvent.layout.y; setLinePositionByKey("topLinePosition", positionY); }} style={topLineAnimatedStyle} {...menuProps} /> { const positionY = event.nativeEvent.layout.y; setLinePositionByKey("middleLinePosition", positionY); }} style={middleLineAnimatedStyle} {...menuProps} /> { const positionY = event.nativeEvent.layout.y; setLinePositionByKey("bottomLinePosition", positionY); }} style={bottomLineAnimatedStyle} {...menuProps} /> ); } export default AnimatedMenuVertically;