Skip to content
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

onPress works on Circle element, but not on Image element #1170

Closed
gurramlokesh opened this issue Oct 25, 2019 · 4 comments
Closed

onPress works on Circle element, but not on Image element #1170

gurramlokesh opened this issue Oct 25, 2019 · 4 comments
Labels

Comments

@gurramlokesh
Copy link

gurramlokesh commented Oct 25, 2019

Question

<Circle onPress={()=>handleMarkerTouch(key)} cx={scaleX(x)} cy={scaleY(y)} r={5} fill={'#367be2'}/>

<Image onPress={()=>handleMarkerTouch(key)} x={scaleX(x) - MarkerWidth/2} y= {scaleY(y) - MarkerHeight} width={MarkerWidth} height={MarkerHeight} href={imageResouce} />

I'm trying to use onPress for an image element inside an SVG. It doesn't trigger any onPress events. However if I try that on a Circle element, it works.

I also tried the TouchableOpacityG hack suggested by @msand on this expo (https://snack.expo.io/@msand/touchableopacityg).

Can anyone please guide on what could be the mistake I'm doing?

@msand
Copy link
Collaborator

msand commented Oct 25, 2019

Hmm, this seems to work fine for me:

import React from 'react';
import {SafeAreaView, StatusBar} from 'react-native';
import {Svg, Image} from 'react-native-svg';

const App = () => {
  return (
    <>
      <StatusBar barStyle="dark-content" />
      <SafeAreaView>
        <Svg height="100%" width="100%" style={{backgroundColor: '#222'}}>
          <Image
            x="5%"
            y="5%"
            width="90%"
            height="90%"
            href={require('./img.png')}
            onPress={(...args) => alert('Image onPress', args)}
          />
        </Svg>
      </SafeAreaView>
    </>
  );
};

export default App;

Screenshot 2019-10-25 at 20 43 09

Can you make a full reproduction?

@msand
Copy link
Collaborator

msand commented Oct 25, 2019

Seems it's not working on android actually

msand added a commit that referenced this issue Oct 25, 2019
msand pushed a commit that referenced this issue Oct 25, 2019
## [9.13.3](v9.13.2...v9.13.3) (2019-10-25)

### Bug Fixes

* **android:** Image onPress [#1170](#1170) ([5c967b7](5c967b7))
@msand
Copy link
Collaborator

msand commented Oct 25, 2019

Can you try with v9.13.3 in a plain react-native or ejected expo project?

@gurramlokesh
Copy link
Author

Thanks a lot for the fix. Works fine in plain react-native + 9.13.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants