11import React , { useEffect } from 'react'
22import {
3+ runOnJS ,
34 useDerivedValue ,
45 useSharedValue ,
56 withSpring ,
67 withTiming ,
78} from 'react-native-reanimated'
89
9- import { Circle , Group } from '@shopify/react-native-skia'
10-
11- import { EventComponentProps } from './LineGraphProps'
10+ import {
11+ Circle ,
12+ Group ,
13+ TwoPointConicalGradient ,
14+ vec ,
15+ } from '@shopify/react-native-skia'
16+ import { EventComponentProps } from '../../../src/LineGraphProps'
1217
1318const EVENT_SIZE = 6
1419const ACTIVE_EVENT_SIZE = 8
1520const ENTERING_ANIMATION_DURATION = 750
1621
17- export function DefaultGraphEvent ( {
22+ export function GraphEvent ( {
1823 isGraphActive,
1924 fingerX,
2025 eventX,
2126 eventY,
2227 color,
28+ index,
29+ onEventHover,
2330} : EventComponentProps ) {
24- const isEventActive = useDerivedValue (
25- ( ) =>
31+ const isEventActive = useDerivedValue ( ( ) => {
32+ // If the finger is on X position of the event.
33+ if (
2634 isGraphActive . value &&
2735 Math . abs ( fingerX . value - eventX ) < ACTIVE_EVENT_SIZE
28- )
36+ ) {
37+ if ( onEventHover ) runOnJS ( onEventHover ) ( index , true )
38+
39+ return true
40+ }
41+
42+ if ( onEventHover ) runOnJS ( onEventHover ) ( index , false )
43+ return false
44+ } )
2945
3046 const dotRadius = useDerivedValue ( ( ) =>
3147 withSpring ( isEventActive . value ? ACTIVE_EVENT_SIZE : EVENT_SIZE )
3248 )
33-
49+ const gradientEndRadius = useDerivedValue ( ( ) =>
50+ withSpring ( dotRadius . value / 2 )
51+ )
3452 const animatedOpacity = useSharedValue ( 0 )
3553
3654 useEffect ( ( ) => {
@@ -42,7 +60,15 @@ export function DefaultGraphEvent({
4260
4361 return (
4462 < Group opacity = { animatedOpacity } >
45- < Circle cx = { eventX } cy = { eventY } r = { dotRadius } color = { color } />
63+ < Circle cx = { eventX } cy = { eventY } r = { dotRadius } color = { color } >
64+ < TwoPointConicalGradient
65+ start = { vec ( eventX , eventY ) }
66+ startR = { 0 }
67+ end = { vec ( eventX , eventY ) }
68+ endR = { gradientEndRadius }
69+ colors = { [ 'white' , color ] }
70+ />
71+ </ Circle >
4672 </ Group >
4773 )
4874}
0 commit comments