Call PanResponder methods from another method in React Native

Redone

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();
    }

Robbie Milejczak

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unable to call Method from another class in React Native

From Dev

React Native PanResponder

From Dev

React native panResponder Animation

From Java

Static methods - How to call a method from another method?

From Dev

React Native's panResponder has stale value from useState?

From Dev

Lock movement with PanResponder in react native

From Dev

PanResponder & Animated Problem in React Native

From Dev

Call methods from the Activity class (React Native Android)

From Dev

How to call a static method from another static method in React?

From Java

Call a static java method of another package from native code

From Dev

How to call a function from another class in React-Native?

From Dev

How to call a function from another function in React-Native?

From Dev

How to call a function of a class from another file in React Native?

From Dev

How to call a function with parametrs from another class in react native?

From Dev

How would I call a function from another component in react native?

From Dev

React Native: can't call a parent method from child

From Dev

How to call a child component method from parent in React Native typescript

From Dev

React Native Issue - Initialize state by calling another method from constructor

From Dev

how do you call a method from another react class component

From Dev

PanResponder over a TextInput in react-native

From Dev

React Native: How to disable PanResponder temporarily?

From Dev

How To Disable PanResponder on Child Component - React Native

From Dev

How to unit test PanResponder in React Native?

From Dev

react-native PanResponder: OnMoveShouldSetPanResponder Not Working

From Android

How to call methods in React Native MapView?

From Java

Writing a static method to call methods from another class to return a new list from an old list

From Dev

Call Main from another method

From Java

Call a method from another JFrame

From Dev

Method call from another form

Related Related

  1. 1

    Unable to call Method from another class in React Native

  2. 2

    React Native PanResponder

  3. 3

    React native panResponder Animation

  4. 4

    Static methods - How to call a method from another method?

  5. 5

    React Native's panResponder has stale value from useState?

  6. 6

    Lock movement with PanResponder in react native

  7. 7

    PanResponder & Animated Problem in React Native

  8. 8

    Call methods from the Activity class (React Native Android)

  9. 9

    How to call a static method from another static method in React?

  10. 10

    Call a static java method of another package from native code

  11. 11

    How to call a function from another class in React-Native?

  12. 12

    How to call a function from another function in React-Native?

  13. 13

    How to call a function of a class from another file in React Native?

  14. 14

    How to call a function with parametrs from another class in react native?

  15. 15

    How would I call a function from another component in react native?

  16. 16

    React Native: can't call a parent method from child

  17. 17

    How to call a child component method from parent in React Native typescript

  18. 18

    React Native Issue - Initialize state by calling another method from constructor

  19. 19

    how do you call a method from another react class component

  20. 20

    PanResponder over a TextInput in react-native

  21. 21

    React Native: How to disable PanResponder temporarily?

  22. 22

    How To Disable PanResponder on Child Component - React Native

  23. 23

    How to unit test PanResponder in React Native?

  24. 24

    react-native PanResponder: OnMoveShouldSetPanResponder Not Working

  25. 25

    How to call methods in React Native MapView?

  26. 26

    Writing a static method to call methods from another class to return a new list from an old list

  27. 27

    Call Main from another method

  28. 28

    Call a method from another JFrame

  29. 29

    Method call from another form

HotTag

Archive