@chenng/react-native-shake-event
Version:
Add shake event to your React Native app
61 lines (37 loc) • 1.17 kB
Markdown
author: Jadson Lourenco <jadsonlourenco@gmail.com>
homepage: <https://github.com/jadsonlourenco/react-native-shake-event>
Notes: Source can not be used directly, republish it...
---
Add the shake event on your React Native app, giving to users improved usability. Enjoy!
*(works only on real device)*
```shell
$ npm install @chenng/react-native-shake-event --save
```
`react-native link @chenng/react-native-shake-event`
```js
import RNShakeEvent from 'react-native-shake-event';
class MyComponent extends React.Component {
componentWillMount() {
RNShakeEvent.addEventListener('shake', () => {
console.log('Device shake!');
});
}
componentWillUnmount() {
RNShakeEvent.removeEventListener('shake');
}
}
```
Start listening the shake event and handle a callback function.
Stop to listening the shake event, and is recommended to prevent memory leak.
On *debug mode* this event also handle the **DevMenu**, but works fine on *production*.
MIT