-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Closed
Labels
API: PanResponderBugPlatform: iOSiOS applications.iOS applications.StaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.
Description
Is this a bug report?
yes
Have you read the Bugs section of the How to Contribute guide?
yes
Environment
react-native -v
: 0.43.4node -v
: v6.9.1npm -v
: 3.10.8yarn --version
: 0.18.1
Then, specify:
-
Target Platform: iOS
-
Development Operating System: macOS
-
Build tools: Xcode
Steps to Reproduce
(Write your steps here:)
- use panResponder
- console.log locationX and locationY of view when I move it in onPanResponderMove
Expected Behavior
the locationX change with the view move
Actual Behavior
locationX do change when view move, but the value is not currect, just like:
locationX : 38.5 locationY : 53.5
locationX : 152.5 locationY : 278.5
locationX : 29.5 locationY : 45
locationX : 138 locationY : 264.5
Reproducible Demo
import React, {PureComponent, Component} from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
PanResponder,
} from 'react-native';
export default class TouchStartAndRelease extends PureComponent {
constructor(props) {
super(props);
this.state = {
backgroundColor: 'red',
marginTop: 100,
marginLeft: 100,
}
}
componentWillMount(){
this._panResponder = PanResponder.create({
onStartShouldSetPanResponder: (evt, gestureState) => {
return true;
},
onMoveShouldSetPanResponder: (evt, gestureState) => {
return true;
},
onPanResponderGrant: (evt, gestureState) => {
this._highlight();
},
onPanResponderMove: (evt, gestureState) => {
console.log(`locationX : ${evt.nativeEvent.locationX} locationY : ${evt.nativeEvent.locationY}`);
this.setState({
marginLeft: evt.nativeEvent.locationX,
marginTop: evt.nativeEvent.locationY,
});
},
onPanResponderRelease: (evt, gestureState) => {
this._unhighlight();
},
onPanResponderTerminate: (evt, gestureState) => {
},
});
}
_unhighlight(){
this.setState({
backgroundColor: 'red',
});
}
_highlight(){
this.setState({
backgroundColor: 'blue',
});
}
render() {
return (
<View style={styles.container}>
<View style={[styles.redView,
{
backgroundColor: this.state.backgroundColor,
marginTop: this.state.marginTop,
marginLeft: this.state.marginLeft,
}
]}
{...this._panResponder.panHandlers}
></View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
redView: {
width: 100,
height: 100,
},
});
AppRegistry.registerComponent('TouchStartAndRelease', () => TouchStartAndRelease);
Metadata
Metadata
Assignees
Labels
API: PanResponderBugPlatform: iOSiOS applications.iOS applications.StaleThere has been a lack of activity on this issue and it may be closed soon.There has been a lack of activity on this issue and it may be closed soon.