diff --git a/src/SegmentedArc.js b/src/SegmentedArc.js index 6943794..2ecff66 100644 --- a/src/SegmentedArc.js +++ b/src/SegmentedArc.js @@ -131,13 +131,10 @@ export const SegmentedArc = ({ delay: animationDelay, useNativeDriver: false, easing: Easing.out(Easing.ease) - }).start(); - - const listenerId = arcAnimatedValue.addListener(e => { - if (e.value === lastFilledSegment.filled) animationRunning.current = false; + }).start(() => { + animationRunning.current = false; }); - return () => arcAnimatedValue.removeListener(listenerId); - }, []); + }, [lastFilledSegment.filled]); if (arcs.length === 0) { return null; diff --git a/src/components/Segment.js b/src/components/Segment.js index 0691a4d..c64f668 100644 --- a/src/components/Segment.js +++ b/src/components/Segment.js @@ -12,20 +12,17 @@ export const Segment = ({ arc }) => { const { filledArcWidth, radius, isAnimated, emptyArcWidth, arcAnimatedValue } = segmentedArcContext; const arcRef = useRef(); - const animationComplete = useRef(false); useEffect(() => { if (!isAnimated) return; const listener = arcAnimatedValue.addListener(v => { if (!arcRef.current) return; - if (animationComplete.current) return; if (v.value <= arc.start) return; if (v.value >= arc.end) { arcRef.current.setNativeProps({ d: drawArc(arc.centerX, arc.centerY, radius, arc.start, arc.end) }); - animationComplete.current = true; } else { arcRef.current.setNativeProps({ d: drawArc(arc.centerX, arc.centerY, radius, arc.start, v.value)