Skip to content

PanResponder > onPanResponderMove doesn't work with Animated.event() if called inside a function #15880

Closed
@xardit

Description

@xardit

I have the following examples:

WORKS

// moving
onPanResponderMove: Animated.event([null, {
  dx: this.state.pan.x, // x,y are Animated.Value
  dy: this.state.pan.y,
}]),

DOESN'T WORK

// moving
onPanResponderMove: (evt, gestureState) => {
  this.props.updatePanPosition(gestureState.moveX, gestureState.moveY)

  return Animated.event([null, {
    dx: this.state.pan.x,
    dy: this.state.pan.y,
  }])
},

The pan state is an Animated.ValueXY()
I need to use the onPanResponderMove function to get latest coordinates on the screen and use it in another component

This looks like an issue!

I'm using react-native: 0.47.2

Activity

xardit

xardit commented on Sep 10, 2017

@xardit
Author

Never mind, fixed it
Reason was because Animation.event() only generates the function which is used from onPanResponderMove, it also needs the default arguments evt, gestureState

WORKING CODE

// moving
onPanResponderMove: (evt, gestureState) => {
  this.props.updatePanPosition(gestureState.moveX, gestureState.moveY)

  return Animated.event([null, {
    dx: this.state.pan.x,
    dy: this.state.pan.y,
  }])(evt, gestureState)
},
locked as resolved and limited conversation to collaborators on Sep 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @xardit@react-native-bot

        Issue actions

          PanResponder > onPanResponderMove doesn't work with Animated.event() if called inside a function · Issue #15880 · facebook/react-native