-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathGraphEvent.tsx
More file actions
74 lines (66 loc) · 1.7 KB
/
GraphEvent.tsx
File metadata and controls
74 lines (66 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React, { useEffect } from 'react'
import {
runOnJS,
useDerivedValue,
useSharedValue,
withSpring,
withTiming,
} from 'react-native-reanimated'
import {
Circle,
Group,
TwoPointConicalGradient,
vec,
} from '@shopify/react-native-skia'
import { EventComponentProps } from '../../../src/LineGraphProps'
const EVENT_SIZE = 6
const ACTIVE_EVENT_SIZE = 8
const ENTERING_ANIMATION_DURATION = 750
export function GraphEvent({
isGraphActive,
fingerX,
eventX,
eventY,
color,
index,
onEventHover,
}: EventComponentProps) {
const isEventActive = useDerivedValue(() => {
// If the finger is on X position of the event.
if (
isGraphActive.value &&
Math.abs(fingerX.value - eventX) < ACTIVE_EVENT_SIZE
) {
if (onEventHover) runOnJS(onEventHover)(index, true)
return true
}
if (onEventHover) runOnJS(onEventHover)(index, false)
return false
})
const dotRadius = useDerivedValue(() =>
withSpring(isEventActive.value ? ACTIVE_EVENT_SIZE : EVENT_SIZE)
)
const gradientEndRadius = useDerivedValue(() =>
withSpring(dotRadius.value / 2)
)
const animatedOpacity = useSharedValue(0)
useEffect(() => {
// Entering opacity animation triggered on the first render.
animatedOpacity.value = withTiming(1, {
duration: ENTERING_ANIMATION_DURATION,
})
}, [animatedOpacity])
return (
<Group opacity={animatedOpacity}>
<Circle cx={eventX} cy={eventY} r={dotRadius} color={color}>
<TwoPointConicalGradient
start={vec(eventX, eventY)}
startR={0}
end={vec(eventX, eventY)}
endR={gradientEndRadius}
colors={['white', color]}
/>
</Circle>
</Group>
)
}