-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathCustomSelectionDot.tsx
57 lines (53 loc) · 1.2 KB
/
CustomSelectionDot.tsx
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
/**
* An example for a custom SelectionDot component.
*
* Usage:
*
* ```jsx
* <LineGraph
* points={priceHistory}
* animated={true}
* enablePanGesture={true}
* SelectionDot={CustomSelectionDot}
* />
* ```
*
* This example has removed the outer ring and light
* shadow from the default one to make it more flat.
*/
import React, { useCallback } from 'react'
import {
runOnJS,
useAnimatedReaction,
withSpring,
useSharedValue,
} from 'react-native-reanimated'
import { Circle } from '@shopify/react-native-skia'
import type { SelectionDotProps } from 'react-native-graph'
export function SelectionDot({
isActive,
color,
circleX,
circleY,
}: SelectionDotProps): React.ReactElement {
const circleRadius = useSharedValue(0)
const setIsActive = useCallback(
(active: boolean) => {
circleRadius.value = withSpring(active ? 5 : 0, {
mass: 1,
stiffness: 1000,
damping: 50,
velocity: 0,
})
},
[circleRadius]
)
useAnimatedReaction(
() => isActive.value,
(active) => {
runOnJS(setIsActive)(active)
},
[isActive, setIsActive]
)
return <Circle cx={circleX} cy={circleY} r={circleRadius} color={color} />
}