Repository navigation
Conversation
- CartesianChart: new optional \enableHover\ prop driving the first
chartPressState via \Gesture.Hover()\ from react-native-gesture-handler;
activates on pointer enter with live point tracking and deactivates on
pointer leave/end/finalize.
- New optional \chartHoverConfig\ prop (\{ activeCursor?: string }\)
to style the hover cursor.
- Composed with \Gesture.Simultaneous\ alongside existing pan/transform
gestures so hover coexists with press-drag.
- Export \ChartHoverConfig\ type from the package entry point.
- Add \Gesture.Hover\ to the RNGH headless test stub so golden renders work.
- Add example screen (\/hover-gesture\) with cursor line + live readouts.
- Add example metro.config.js pinning web resolver conditions to the
library source (avoids a TDZ crash from freshly-built lib/dist on web).
- Changeset (minor).
🦋 Changeset detectedLatest commit: 6531333 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@adamhari is attempting to deploy a commit to the Nearform Team on Vercel. A member of the Team first needs to authorize it. |
- PolarChart: new optional \enableHover\, \hoverState\ (\{ index }\
\: Reanimated
shared value) and \chartHoverConfig\ props. A \Gesture.Hover()\ writes the
chart-space pointer position (inverted through the active transform) into
the polar chart context; \PieChart\ maps it onto slice geometry with a
\useAnimatedReaction\ hit test (angle + radius/innerRadius) and writes the
hovered slice index (-1 outside any slice / donut hole / off chart).
- Export \PieHoverState\ type from the package entry point.
- Examples: \enableHover\ + hover readouts wired into the bar chart and
scatter examples (representative cartesian varieties) and slice hover
readout in the donut chart example.
- Update changeset and route descriptions.
- website: document \enableHover\ / \chartHoverConfig\ (CartesianChart), \enableHover\ / \hoverState\ / \chartHoverConfig\ (PolarChart), add a hover section with a full cartesian example to the Chart Gestures guide, and cross-link hover from the \chartPressState\ and Pie.Chart docs. - examples: enable hover with slice readout in the pie chart example, and turn on \enableHover\ in candlestick, bar-with-tooltip and ordinal-data examples so their existing press tooltips respond to the mouse too.
Hover coverage for cartesian charts is now spread across the regular chart examples (bar, bar-with-tooltip, scatter, ordinal-data, candlestick), so the dedicated line-chart hover page is redundant. Update the website guide to point at those examples instead.
A plain mouse click (press + release without movement) finalized the pan gesture, whose end/finalize handlers unconditionally deactivated the first chartPressState - resetting a tooltip that was driven by the (still active) hover gesture. The press gesture's cleanup now consults \isPointerHovering\ (a shared value maintained by the hover gesture's active lifecycle) and defers deactivation while the pointer keeps hovering; the hover gesture deactivates the state when the pointer actually leaves the chart. Touch behavior (hover never active) is unchanged, verified by the test suite.
The highlighted dot's radius was read from \state.x.position.value\ during render, but shared-value updates happen on the UI thread without a re-render - so the dot lagged/desynced behind hover (and press) movement. Compute the radius reactively with \useAnimatedReaction\ so it follows both gestures accurately.
Same fix as ordinal-data: the highlighted dot's radius was read from the press state shared value during render (and driven from render state via useEffect), so it lagged/desynced behind hover and press movement since shared-value updates happen on the UI thread without a re-render. Compute the radius with useAnimatedReaction instead, and enable hover on the example so the pointer tracks the line just like pressing.
Collaborator
|
Love the idea of supporting hover more, might take me a few weeks to get around to this just fyi! |
adamhari
marked this pull request as ready for review
November 2, 2026 18:22
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds hover support to
victory-nativeusingGesture.Hover()from React Native Gesture Handler, exposed as a unified api across every chart — all cartesian chart types (line, area, bar, scatter, candlestick, … all render throughCartesianChart) and pie/donut charts (PolarChart):New props
enableHover?: boolean— builds the hover gesture. It is composed simultaneously with the existing press/transform gestures so it never competes with them, and touch-only behavior is unchanged. Hover activates on pointer devices (mouse/trackpad — e.g. web or desktop), so it defaults totrueon web (withenableHover={false}to opt out) and stays opt-in elsewhere.chartHoverState?— a Reanimated shared value the hover gesture writes into while the pointer is over the chart, consumed off the UI thread likechartPressState(no extra re-renders). Hover always has a state to drive, in this priority order:chartHoverStatewhen provided — (Cartesian charts: aChartPressStatevalue fromuseChartPressState; Pie/donut charts:{ index: SharedValue<number> }— the hovered slice index, or-1over the donut hole, outside the pie, or off the chart). OnPolarChartthis prop is now optional: the chart maintains a built-in hover state that pie content reads with the newusePieHoverState()hook (exported fromvictory-native), so hover highlighting needs zero setup. Pass the prop only to consume the index outside the chart, where a provider-owned value can't be reached.chartPressStatewhenchartHoverStateis omitted — hover behaves exactly like press with no extra setup.CartesianChartmaintains a hover-only built-in state (mirroringPolarChart) and exposes it through the render functions' newhoverStatefield (isActive,x.value/x.position,y.<yKey>.value/position), so simple hover readouts need zero setup. It'sundefinedwhen you pass a state and read your own object instead.chartHoverConfig?: ChartHoverConfig—{ activeCursor?: string }cursor styling while hovering (web/desktop), andsimultaneousWithExternalGestureto compose the hover gesture with custom gestures built outside the chart (mirrorschartPressConfig.pan.simultaneousWithExternalGesture).TL;DR: Giving hover its own
chartHoverStatekeeps hover and press interactions independent (each with its ownisActive/values); omitting it makes hover and press act as one.Example app
Hover examples are included, and a couple of bugs were fixed so the example app works properly on web:
enableHoverwired into 18 example pages, plus a new/hover-presspage demonstrating independent hover and press states.reactCompiler: true), a chart-rendering wrapper that receives the SkiaFontobject as a prop triggers an infinite re-render.useFontis now hoisted inside each chart wrapper and thefontprops dropped.example/metro.config.jspins the web resolver conditions to the library source (react-native) instead of freshly-builtlib/dist, avoiding a TDZ crash caused by Metro workletizing the dist bundle on web.Website docs
cartesian-chart.md/polar-chart.md: documentenableHover,chartHoverState(including each chart's built-in hover state), andchartHoverConfig; cartesian render-function docs cover the newhoverStatefield.chart-gestures.mdx: new "Hover gesture support" section, including distinct hover and press states.pie-charts.md: cross-links the polar hover API.Changeset
minorforvictory-native.Testing
tsc --noEmitclean onlib,example, andwebsite.yarn test: 267 unit tests (including tests for the pie hover hit-test helper, the hover-config helper, and the newmakeChartPressStatebuilt-in state factory) + 5/5 headless golden renders./hover-pressshows hover and press states updating independently; pie/donut hover reports the hovered slice and stays idle over the donut hole and off-chart — all with zero props, via the built-in states. Console error-free throughout.