react-native-shake-event-by-littlekey
Version:
[fork] Add shake event to your React Native app
71 lines (45 loc) • 2.12 kB
Markdown

[](https://www.npmjs.org/package/react-native-shake-event)
[](https://discord.gg/0ZcbPKXt5bXsb3os)
Add the shake event on your React Native app, giving to users improved usability. Enjoy!
*(works only on real device)*
<img src="https://cdn.rawgit.com/jadsonlourenco/react-native-shake-event/master/media/demo.gif" width="480" height="270" alt="react-native-shake-event">
```
$ npm install react-native-shake-event --save
```
`react-native link react-native-shake-event`
1. Add the `RNShakeEvent.xcodeproj` file to your Xcode project [Demo](https://facebook.github.io/react-native/img/AddToLibraries.png);
2. Add the `Products/libRNShakeEvent.a` file to **Build Phases** [Demo](https://facebook.github.io/react-native/img/AddToBuildPhases.png).
This step is described here: [Linking Libraries](https://facebook.github.io/react-native/docs/linking-libraries-ios.html#content).
`react-native link react-native-shake-event`
```
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.
1. On *debug mode* this event also handle the **DevMenu**, but works fine on *production*.
2. [Submit here](https://github.com/jadsonlourenco/react-native-shake-event/issues);
MIT