Android: Svg elements are inside of a PanResponder don't update event.nativeEvent.location
See original GitHub issueThis may be related to https://github.com/react-native-community/react-native-svg/issues/363, but I wasn’t sure so I’ll file a separate issue.
When Svg elements are inside of a PanResponder, onPanResponderMove
’s event.nativeEvent.locationX
(and Y) do not change for Android, but do for iOS. Demo:
import React from 'react';
import { StyleSheet, Text, View, PanResponder } from 'react-native';
import Svg, { Rect } from "react-native-svg";
class Container extends React.Component {
constructor(props) {
super(props);
this.panResponder = this.getResponder();
}
getResponder() {
const yes = () => true;
const no = () => false;
return PanResponder.create({
onStartShouldSetPanResponder: yes,
onStartShouldSetPanResponderCapture: no,
onMoveShouldSetPanResponder: yes,
onMoveShouldSetPanResponderCapture: yes,
onShouldBlockNativeResponder: yes,
onPanResponderTerminationRequest: yes,
// Active touch or touches have moved
onPanResponderMove: this.props.onPanResponderMove.bind(this),
onPanResponderGrant: this.props.onPanResponderMove.bind(this),
});
}
render() {
return (
<View {...this.panResponder.panHandlers}>
{this.props.children}
</View>
);
}
};
export default class App extends React.Component {
render() {
return (
<View>
<Container
onPanResponderMove={
(event) => {
console.log(
event.nativeEvent.locationX,
event.nativeEvent.locationY
);
}
}
>
<Svg
height="100"
width="100"
>
<Rect
width={100}
height={100}
fill="blue"
/>
</Svg>
</Container>
</View>
);
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:11
- Comments:10
Top Results From Across the Web
Android: Svg elements are inside of a PanResponder don't ...
When Svg elements are inside of a PanResponder, onPanResponderMove 's event.nativeEvent.locationX (and Y) do not change for Android, ...
Read more >Update state from inside a PanResponder - Stack Overflow
I have a < Svg > element with a < Circle > in it. The < Circle >'s position is relative to a...
Read more >[Solved]-Limit PanResponder movements React Native-React ...
Coding example for the question Limit PanResponder movements React Native-React ... ( <View style={styles.holder} onLayout={event => { const layout = event.
Read more >PanResponder - React Native
A native event is a synthetic touch event with form of PressEvent. A gestureState object has the following:
Read more >What Sets Apart ReactJS with React Native - Flyoutsourcing
In-app rendering, React Native never employs HTML. However, it has optional elements that have a similar approach. Using the React-Native components, they can ......
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 have a similar issue. I have a panresponder on a View which contains an SVG.
in
onMoveShouldSetPanResponderCapture
, dx and dy start with a big value even on the first press. I think this is because mutlipe elements inside the svg report different locations. Also movement speeds (vx, vy) get messed up because of this. I tried to work around it, but without any success.Were you able to reproduce the issue?