-
See issue and discussion here for context: #681 I have a I have a reproducible demo in the issue linked above. From the comment I made there:
Much appreciated if anyone has any ideas on how to solve this! I couldn't work out how to do it via Here's a Snack with the reproducible demo: https://snack.expo.dev/@jorundur/supportive-raisins FYI: For some reason the Canvas disappears after 1 second in the Snack, but if you make any change in the file and save (such add a newline somewhere), then it appears. It's fine if you run locally. But that's some other problem we can ignore for the purpose of this discussion. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
I think the solution here is to use gesture-handler; this is the kind of use-cases where gesture-handlers excels at and that is outside the scope of our current built-in gesture API. |
Beta Was this translation helpful? Give feedback.
-
To reiterate, what I wanted to do was to have the touch events of a The solution was to do the following:
Code (relevant code only - don't just run this expecting to see anything😅): import * as React from 'react';
import {
GestureHandlerRootView,
ScrollView // Note that this is not imported from react-native
} from 'react-native-gesture-handler';
const App = () => {
// Create ref for the ScrollView to know what other gestures it should work simultaneously with.
// My use case required pan but this can be swapped for other gestures.
const panGestureRef = React.useRef<GestureType>(Gesture.Pan());
// The logic that used to be in `onTouch` on the Canvas is now here
const panGesture = Gesture.Pan()
.onChange((e) => {
// Do stuff, also use the other callbacks available as needed
})
.withRef(panGestureRef);
return (
<GestureHandlerRootView style={{ flex: 1 }}>{/* Don't forget this! It should be at the root of your project. */}
<ScrollView simultaneousHandlers={[panGestureRef]}>
<GestureDetector gesture={panGesture}>
<Canvas style={{ width: 200, height: 200 }}>
{/* Your react-native-skia magic that allows for interaction */}
</Canvas>
</GestureDetector>
</ScrollView>
</GestureHandlerRootView>
);
};
export default App; |
Beta Was this translation helpful? Give feedback.
-
how about class component? |
Beta Was this translation helpful? Give feedback.
To reiterate, what I wanted to do was to have the touch events of a
ScrollView
work simultaneously with touch events from areact-native-skia
Canvas
child component.The solution was to do the following:
onTouch
onCanvas
, instead detect gestures viareact-native-gesture-handler
simultaneousHandlers
prop to theScrollView
and use the ref thereScrollView
that its events should not be blocked by the touch events from the refCode (relevant code only - don't just run this expecting to see anything😅):