JedWatson / react-hammerjs

ReactJS / HammerJS integration. Support touch events in your React app.
MIT License
937 stars 128 forks source link

How to call `stop` of Hammer.Manager in react-hammerjs? #58

Open lzl124631x opened 7 years ago

lzl124631x commented 7 years ago

I want to stop the current session.

stop([force]) Stop recognizing for the current input session. When forced, the recognizer cycle is stopped immediately.

hinok commented 7 years ago

@lzl124631x Use ref callback.

import React from 'react';
import ReactDOM from 'react-dom';
import Hammer from 'react-hammerjs';

let hammerComponent;

const onSwipe = () => {
  hammerComponent.hammer.stop();
};

const App = () => (
  <Hammer onSwipe={onSwipe} ref={(instance) => { hammerComponent = instance; }}>
    <div>Foo</div>
  </Hammer>
);

ReactDOM.render(<App />, document.getElementById('root'));