From ae01de44010c613fa636b8cbe6544e2cc2e2e4a0 Mon Sep 17 00:00:00 2001 From: Gustavo Aires Date: Thu, 18 Sep 2025 10:44:41 -0300 Subject: [PATCH] fix: handle undefined pointSelectedIndex and add isActive check for point selection --- src/AnimatedLineGraph.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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, ] )