diff --git a/src/AnimatedLineGraph.tsx b/src/AnimatedLineGraph.tsx index bee225a..a2b6720 100644 --- a/src/AnimatedLineGraph.tsx +++ b/src/AnimatedLineGraph.tsx @@ -140,7 +140,7 @@ export function AnimatedLineGraph({ const gradientPaths = useSharedValue<{ from?: SkPath; to?: SkPath }>({}) const commands = useSharedValue([]) const [commandsChanged, setCommandsChanged] = useState(0) - const pointSelectedIndex = useRef() + const pointSelectedIndex = useRef(undefined) const pathRange: GraphPathRange = useMemo( () => getGraphPathRange(allPoints, range), @@ -352,7 +352,7 @@ export function AnimatedLineGraph({ const dataPoint = pointsInRange[pointIndex] pointSelectedIndex.current = pointIndex - if (dataPoint != null) { + if (dataPoint != null && isActive.value) { onPointSelected?.(dataPoint) } } @@ -363,6 +363,7 @@ export function AnimatedLineGraph({ onPointSelected, pathRange.x, pointsInRange, + isActive, ] )