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

Gestures don't work with sub-components of react-native-svg's <Svg> on iOS #2734

Open
chriscoomber opened this issue Jan 29, 2024 · 3 comments
Labels
Platform: iOS This issue is specific to iOS Repro provided A reproduction with a snack or repo is provided

Comments

@chriscoomber
Copy link
Contributor

chriscoomber commented Jan 29, 2024

Description

Wrapping SVG sub-components with <GestureDetector> doesn't seem to work.

(There is a related issue, #2502, which was resolved. However, the code presented in the solution doesn't work any more. This indicates to me that this did work at some point, but doesn't seem to any more.)

Naturally, this could be a react-native-svg issue.

Steps to reproduce

Attempt to wrap an SVG sub-component, such as Path, in a GestureDetector:

<GestureDetector gesture={tapGesture}>
  <Path d={path} fill={fill} />
</GestureDetector>

Expected result: clicking the square causes it to change color, but clicking anywhere else does nothing. Should work on Android and iOS.

Actual result: Works on web, via react-native-web. Also works on Android.

Does not work on iOS.

Snack or a link to a repository

https://github.com/chriscoomber/RNSvg-gesture-handler-repro

I also made a snack, though it is muddied by software-mansion/react-native-svg#2214 which makes it crash on android/iOS.

https://snack.expo.dev/@chris_whiterosemaths/interactive-svg-component

Gesture Handler version

2.12.1

React Native version

0.72.6

Platforms

iOS

JavaScript runtime

None

Workflow

None

Architecture

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

@github-actions github-actions bot added Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided labels Jan 29, 2024
@chriscoomber chriscoomber changed the title Gestures don't work with sub-components of react-native-svg's <Svg> on native Gestures don't work with sub-components of react-native-svg's <Svg> on iOS Jan 29, 2024
@github-actions github-actions bot added Platform: iOS This issue is specific to iOS and removed Platform: Android This issue is specific to Android labels Jan 29, 2024
@m-bert
Copy link
Contributor

m-bert commented Feb 1, 2024

Hi @chriscoomber! The code in issue that you've mentioned still works. There's just one difference that makes it work. In the linked issue there is:

<GestureDetector key={key} gesture={tapGesture}>
    <Path d={path} onResponderMove={(_) => {}} />
</GestureDetector>

while in your case there's:

<GestureDetector gesture={tapGesture}>
    <Path d={path} fill={fill} />
</GestureDetector>

Now, adding onResponderMove={(_) => {}} to your example makes it work. Moreover, you can add other props related to responder. For example, if you use onStartShouldSetResponder, you can pass there an arrow function and it doesn't matter whether it returns true or false, the square will change its color.

For now I'm not sure why it happens, but I'll definitely investigate that!

@chriscoomber
Copy link
Contributor Author

@m-bert Thanks for the quick response and the workaround - that seems to work! I'm happy for you to close, or keep open if there's more investigation to be done.

However, I'm now seeing a new issue on Android only, which I've raised separately: #2748.

@m-bert
Copy link
Contributor

m-bert commented Feb 6, 2024

I'll close it later because I want to dive into it and see why it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: iOS This issue is specific to iOS Repro provided A reproduction with a snack or repo is provided
Projects
None yet
Development

No branches or pull requests

2 participants