Is it possible to detect a long press on a path? #974
-
Hey folks, I want to start of by saying that I absolutely love this library. Incredible work specially for charts. It's buttery smooth and the examples and tutorials by @wcandillon make it even easier to get set up. Great work <3 I wanted to ask if there was any way to detect long press on a path. I'm using // useGraphTouchHandler hook
export const useGraphTouchHandler = (x: SkiaMutableValue<number>) => {
const isActive = useValue(false)
const isMoving = useValue(false)
const offsetX = useValue(0)
const onTouch = useTouchHandler({
onStart: () => {
isActive.current = true
void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy)
},
onActive: (pos) => {
isMoving.current = true
x.current = clamp(offsetX.current + pos.x, 0, WIDTH)
},
onEnd: () => {
isActive.current = false
isMoving.current = false
void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy)
},
})
return { onTouch, isActive, isMoving }
}
// Path is something like this
<Canvas style={styles.graph} onTouch={onTouch}>
<Group transform={[{ translateY }]}>
<Path
style="stroke"
path={path}
strokeWidth={3}
strokeJoin="round"
strokeCap="round"
color={trendColorMapping[trend.current].line}
/>
<Mask mask={<Path style="fill" path={gradientPath} opacity={gradientTransition} />}>
<Rect x={0} y={0} width={WIDTH} height={HEIGHT}>
<LinearGradient
start={vec(0, 0)}
end={vec(0, HEIGHT)}
colors={[trendColorMapping[trend.current].gradient, TRANSPARENT]}
/>
</Rect>
</Mask>
<Rect
x={x}
y={-2}
width={WIDTH}
height={HEIGHT + 2}
opacity={opacity}
color={colors.priceHeader.headerBackgroundColor}
/>
</Group>
<Cursor
x={x}
y={y}
strokeColor={trendColorMapping[trend.current].line}
circleColor={colors.priceHeader.headerBackgroundColor}
isMoving={isMoving}
/>
</Canvas> Essentially I only want the cursor to become active ( Let me know if you need any other info or if I can contribute in someway. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
For such a use-case we recommend to use react-native-gesture-handler via reanimated: https://shopify.github.io/react-native-skia/docs/animations/reanimated |
Beta Was this translation helpful? Give feedback.
For such a use-case we recommend to use react-native-gesture-handler via reanimated: https://shopify.github.io/react-native-skia/docs/animations/reanimated