-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Touch Handling on each path/group inside a canvas ? #513
Comments
I'm also looking into this. As I understand it is impossible right now. The only react native component is Canvas and it's the only one that has a touch hook. Would love to know if this feature is already on the roadmap. It would make RNS 2x more powerful. |
Yea totally. Atm the only working solution I have is using a simple useState hook with the Touch Handler from the canvas and just loop through all the shapes. And if the the x and y postion is inside the bounds of one of the shapes update the state hook. |
The drawing primitives inside the canvas are not components as we're used to in React - they are just wrappers ending up as drawing instructions resulting in Skia rendering rectangles, circles, paths etc on screen. We've done something similar to what @BubbleTrouble14 did, enumerating our elements and checking if the current touch point is inside the element's drawing area. We hope we'll be able to provide a good solution for this in the future that will make it easier to add touch handling to specific areas in the Canvas that you can declaratively set up. |
Okay thanks for the reply. I'll just keep my current solution then. |
Should we close this one, @wcandillon? Ref discussion we had? |
Are there any updates? 🙂 |
Would be awesome to have touch support per "layer" (path, image, etc). Or alternatively an elementFromPoint kinda function returning the topmost [Element] at x,y. |
Referring to the comment I made about above - the primitives aren't real components, just an abstract representation of a part of the drawing and hence does not contain any common information about position etc.. I think the best solution would be to create your own such functions depending on the specific use case you have :) |
would be interested in this as well! |
+1 |
Maybe this one helps? |
@chrfalch Are there any plans to include that as a part as a part of EDIT: Just saw #517 but it's closed I couldn't seem to find a successor PR |
As we've explained before, this is a hard topic that we've decided is out of scope for what we want to do (see previous comment here). The main reasons being: Creating a generic function for returning the bounds of Skia elements are hard, since elements can be translated, clipped and rendered in such a way that we can't calculate where its actual positions are with accurate results.. Our recommendation References |
What would be the best approach to handle touch events on specific paths of a canvas ? As at the moment only the full canvas listens for touch events. Would I have to use the canvas touch handler to get the x and y postion and loop through all the path bounds to get the one which it is inside ? For example a simple barchart where each bar can be clickable to receive its value or even animate it ?
The text was updated successfully, but these errors were encountered: