Getting the OnPress source element on SVGs with hundreds of shapes.
See original GitHub issueI have a lot of “ready to go” SVGs that I convert with svgr to components.
Inside the SVG there are many paths, each one has a fixed Id
that cannot be changed (it is used in other apps).
Q: I need to know which shape the user has touched … looks simple
In my PoC the only way I found is to modify the component by svgr by adding these attributes for each path (which are hundreds):
ref={this.circleRef} onPress={e => this.onCirclePress(e, this.circleRef.current.props.id)}
I know arrow functions are bad in render, but I need the onPress location coordinates as well.
The onPress
event gives me target
(runtime id) which is not available from the DOM and therefore I can’t associate it to my fixed Id
.
Is there really no solution to get the source element pressed by the user? Dropping RN for this would be a pity.
Thank you in advance
Issue Analytics
- State:
- Created 3 years ago
- Comments:38 (18 by maintainers)
Top Results From Across the Web
Getting the OnPress source element on SVGs with hundreds ...
I have a lot of "ready to go" SVGs that I convert with svgr to components. Inside the SVG there are many paths,...
Read more >Making an svg image object clickable with onclick, avoiding ...
So, I made a div exclusively for the svg, and placed onclick in this div tag. But, no effect unless visitor clicks on...
Read more >How to use SVGs in React | Sanity.io guide
This article will explore how to use SVG in React in three examples.
Read more >Work with SVG format in Illustrator - Adobe Support
SVG, on the other hand, is a vector format that describes images as shapes, paths, text, and filter effects. The resulting files are...
Read more >High Performance SVGs | CSS-Tricks
This doesn't mean that you can't make seemingly complex shapes. But hundreds of path points can sometimes have the same appearance and interest ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks good imo, explicit, clear, slightly repetitive perhaps, but quite much required for typescript, probably not a significant contribution to total app size, and easy to add further tailor-made helpers and convenience methods per component type. Pull request looks good as well, will merge once I have some spare time to prepare a release. At least no reason to suspect anything breaking in this case what I can see.
Something like this might help with the types for the id prop: