react-native-svg @>=6.5 onPress stops working after navigating between tabs
See original GitHub issueHello all,
I’m currently using react-navigation w/ react-native-svg and a weird interaction is occuring: whenever I navigate outside of a screen with a SVG component, when I go back to it the onPress
callbacks inside the SVG stops working. From my tests, this happens on RN-SVG after version 6.5, on Android, though I did not have the opportunity to test it out on iOS.
Here’s a minimal example showcasing the problem:
import * as React from 'react';
import { Text, View, StyleSheet, Dimensions } from 'react-native';
import Svg, { Circle } from 'react-native-svg';
import {createBottomTabNavigator} from 'react-navigation'
const { width } = Dimensions.get('window');
const FirstTab = () => (
<View><Text>First Tab</Text></View>
)
const SecondTab = () => (<View style={styles.container}>
<Svg
width={`${width}`}
height={`${width}`}
viewBox="-200 -200 400 400"
style={{ backgroundColor: '#fff' }}
onTouchStart={() => console.log('touchStart')}
onTouchEnd={() => console.log('touchEnd')}
onTouchMove={() => console.log('onTouchMove')}>
<Circle
onPressIn={() => console.log('onPress')}
onResponderMove={() => {
return;
}}
onResponderGrant={() => console.log('onResponderGrant')}
onResponderReject={() => console.log('onResponderReject')}
onResponderEnd={() => console.log('onResponderEnd')}
onResponderRelease={() => console.log('onResponderRelease')}
onResponderStart={() => console.log('onResponderStart')}
onResponderTerminate={() => console.log('onResponderTerminate')}
stroke="black"
strokeWidth="5"
r="40"
fill={'#fff'}
/>
</Svg>
</View>)
const tabNavigator = createBottomTabNavigator({
FirstTab,
SecondTab
})
export default tabNavigator;
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#ecf0f1',
},
});
Do the following:
- Load this code with
react-native-svg@6.5
- open app, go to “Second Tab”
- Press on the circle. Your console will output all relevant events, as expected.
- Navigate to “First Tab”, and then back to “Second Tab”
- Press the circle again. Now, only the SVG’s
touchStart
,touchMove
andtouchEnd
events will fire, as if the Circle never had anyonPress
events. No Responder granting, no rejecting, nothing.
Do notice that, if you do this on Snack, the error will not occur because Expo uses react-native-svg@6.2.2, which is working fine.
I’ve tested this with version 7.0(it still happens there) and all versions from 6.2 to 6.5, which means the error was introduced somewhere in 6.5 I believe.
Thank you for your time.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:8
Top Results From Across the Web
react-native-svg @>=6.5 onPress stops working after ... - GitHub
react -native-svg @>=6.5 onPress stops working after navigating between tabs #783 ... Navigate to "First Tab", and then back to "Second Tab" ...
Read more >Path onPress doesn't work react native svg - Stack Overflow
I'm working on svg map with react-native-svg. On IOS it works fine, but on Android - not. I have Svg tag, nested G...
Read more >@react-navigation/material-top-tabs - npm
Start using @react-navigation/material-top-tabs in your project by running `npm i @react-navigation/material-top-tabs`. There are 51 other projects in the ...
Read more >while trying to resolve module `@react-native/normalize-color` - You ...
However, this package itself specifies a `main` module field that could not be resolved (`[removed]/node_modules/@react-native/normalize-color/index`.
Read more >SVG library for React Native, React Native Web, and plain ...
To install react-native-svg on iOS visit the link referenced above or do the following (react-native link should do this for you):. Open your...
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
I solved it by updating to version 7.2.0 and clearing cache after you instructions 😃 https://github.com/react-native-community/react-native-svg/issues/814#issuecomment-430022466
@tufik2 Seems you have some caching issues. Try
Or,