Below is the code for the panResponder in componentWillMount() method.
this.panResponder = PanResponder.create({
onStartShouldSetPanResponder: (e, gesture) => true,
onPanResponderGrant: (evt, gestureState) => {
this.state.pan.setOffset(this.state.pan.__getValue());
this.state.pan.setValue({ x: 0, y: 0 });
Animated.spring(this.state.pan, {toValue: {x:100, y:100}}).start();
}
});
How can I call onPanResponderGrant method from a different method?
someMethod = () => {
// call the pan responder function here
// this.panResponder.onPanResponderGrant();
}
Why not just make that function into a method on your component?
class MyComponent extends React.Component {
constructor(props){
super(prop)
this.panResponder = PanResponder.create({
onStartShouldSetPanResponder: (e, gesture) => true,
onPanResponderGrant: this.onResponderGrant,
});
}
onResponderGrant = () => {
this.state.pan.setOffset(this.state.pan.__getValue());
this.state.pan.setValue({ x: 0, y: 0 });
Animated.spring(this.state.pan, {toValue: {x:100, y:100}}).start();
}
}
and now you can pass around and call onResponderGrant()
as you like
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments