import React, { useEffect, useState } from 'react'; import { Animated, View } from 'react-native'; import Svg, { Polygon as SVGPolygon } from 'react-native-svg'; import { useAnimation } from '../../functions/animation'; import { generateInfo, generateLines, generatePolygonPoints, useComponentSize, useCoordinateGuidePoles, useCoordinateScorePoles } from '../../functions/utility'; import { black } from '../../style/colors'; import { IGenericChartProps } from '../../types'; import InfoLayer from '../InfoLayer'; import styles from './styles'; export default function Polygon({ innerColor, innerOpacity, outerStroke, style, poles, animation: animationInput, type, }: IGenericChartProps) { const { size, offset, onLayout } = useComponentSize(); const [multiplier, setMultiplier] = useState(0); const [animValue, setAnimValue] = useState( new Animated.Value(0), ); const animation = animationInput && useAnimation({ ...animationInput, value: animValue }); useEffect(() => { if (size) { animValue.addListener(({ value }) => setMultiplier(value)); animation?.start(); } return () => { animValue.removeAllListeners(); animation?.stop(); }; }, [size]); const coordinateScorePoles = useCoordinateScorePoles( { array: poles, length: size ?? 0, multiplier: animationInput ? multiplier : 1, }, type, ); const coordinateGuidePoles = useCoordinateGuidePoles( { array: poles, length: size ?? 0 }, type, ); const coordinateGuideInfos = useCoordinateGuidePoles( { array: poles, length: (size ?? 0) / 2 }, type, ); return ( {size && size !== Number.POSITIVE_INFINITY && ( {generateLines(coordinateGuidePoles, size, 'guide')} {generateLines(coordinateScorePoles, size, 'score')} )} {size && size !== Number.POSITIVE_INFINITY && ( )} ); }