Skip to content

How can I get the Canvas touch handler to work nicely within a ScrollView? #898

Answered by Jorundur
Jorundur asked this question in Q&A
Discussion options

You must be logged in to vote

To reiterate, what I wanted to do was to have the touch events of a ScrollView work simultaneously with touch events from a react-native-skia Canvas child component.

The solution was to do the following:

  • Don't use onTouch on Canvas, instead detect gestures via react-native-gesture-handler
  • Create a gesture and add a ref to it
  • Add the simultaneousHandlers prop to the ScrollView and use the ref there
    • This tells the ScrollView that its events should not be blocked by the touch events from the ref

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…

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
3 replies
@Jorundur
Comment options

@wcandillon
Comment options

@Jorundur
Comment options

Comment options

You must be logged in to vote
3 replies
@Jorundur
Comment options

@cihangir-mercan
Comment options

@Alex25197
Comment options

Answer selected by Jorundur
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants