question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to make an SVG properly clickable on React Native with Expo?

See original GitHub issue

I am using React Native with Expo and I have 4 SVG elements that I need them to be clickable. This is the code for each of these:

  <Svg.G
    id="Passangers-Going-B"
    onPress={() => console.log(`${cardinalPoint} Avatar Was Clicked`)}
   >
...

With that code I am able to click on the SVG element but the weird thing is that when I try to click on another element the click is still firing the event of the last element I clicked on.

I recorded a video with the behavior

So, is there a better way to do this? All I need is to click on those SVG elements in order to change to a new route.

Any ideas?

I am using SVG from expo. import { Svg } from 'expo'; -> https://docs.expo.io/versions/latest/sdk/svg/

I also created a Snack but I don’t see it is working at all -> https://snack.expo.io/@maketroli/expo.svg-example?session_id=snack-session-_9YKofW2Y

What I see is that if I click on one of the elements the click gets stuck there because if I click a new element it throws the function of the last clicked element. I have to click around 3 times the new element in order to focus the click on that element.

I saw something about PanResponder but I don’t know this has something to do with it.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8

github_iconTop GitHub Comments

4reactions
AdamGerthelcommented, Feb 28, 2019

@maketroli Yes. If you look at what’s different between the two, it’s basically only that renderLocations, which is bugged, has a group element surrounding the circle element. If you have the Expo app you can easily look at my sample and play around with it to see the difference.

0reactions
m-retcommented, Feb 28, 2019

Yeah, I’ll give it a try in a few days. Thanks, @AdamGerthel.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make an SVG properly clickable on React Native with ...
I am using React Native with Expo and I have 4 SVG elements that I need them to be clickable. This is the...
Read more >
How can I make a SVG element clickable on React?
I am using React Native with Expo and I have 4 SVG elements that I need them to be clickable. This is the...
Read more >
Using SVGs - Expo Documentation
Paste the SVG contents from the exported SVG file into React-SVGR and make sure the "native" checkbox is ticked. It will provide output...
Read more >
Working with SVGs in React Native - OpenReplay Blog
It provides a uri prop that we can pass a link to an external site. Go to the App.js file and modify the...
Read more >
react-native-svg - npm
Easy to convert SVG code to react-native-svg. Installation. With expo-cli. ✓ The Expo client app comes with the native code installed!
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found