How to use PanResponder with Animated values?

Viewed 114

I have been trying to get a simple animation to work with PanResponder and the React Animated API. This is what I have so far:

export default class Main extends Component {

  constructor(props) {
    super(props)
    this.state = {
      y: new Animated.Value(0)
    }

    this._panResponder = PanResponder.create({
      onMoveShouldSetResponderCapture: () => true,
      onMoveShouldSetPanResponderCapture: () => true,

      onPanResponderMove: Animated.event([
        null,               
        {
          dy: this.state.y
        }
      ]),

    });
  }


  render() {
    let { y } = this.state;
    return (
      <View  {...this._panResponder.panHandlers} style={{ flex: 1 }} >
        <LinearGradient start={{ x: 1.0, y: 0 }} end={{ x: 0.0, y: 1.0 }} colors={['rgba(0,187,9,0.575)', 'rgba(255, 217, 0 , 0.719)']} style={{ alignItems: "center", justifyContent: "center", margin: 0, flex: 1, padding: 20, width: "100%" }}>
          <ResponsiveImage  style={{ transform: [{ rotateZ: y + " deg" }, { perspective: 1000 }], marginBottom: 100 }} source={require('./assets/images/logo.png')} initWidth="225" initHeight="220" />
       </LinearGradient>
      </View>


    );
  }
}

With the code attached above, the rotation animations don't work. It only works when I use the following code in place of the current onPanResponderMove method.

onPanResponderMove: (a,b)=>{this.setState({y: b.dy}) }

Why does the Animated.Event method not work?

0 Answers
Related