With this library, you can add shake event detector on your React Native app. Because react-native-shake-event is not in active development anymore, I decided to created this.
Please note that it only works on real devices
npm install react-native-shake
or
yarn add react-native-shake
react-native link react-native-shake
-
Add the
ios/RNShakeEvent.xcodeproj
file to your Xcode project Demo; -
Add the
Products/libRNShakeEvent.a
file to Build Phases Demo. -
Add the
ios/RNShakeEvent.xcodeproj
file to your Xcode project Demo; -
Add the
Products/libRNShakeEvent.a
file to Build Phases Demo.
This step is described here: Linking Libraries.
react-native link react-native-shake
import RNShake from 'react-native-shake';
class MyComponent extends React.Component {
componentWillMount() {
RNShake.addEventListener('shake', () => {
// Your code...
});
}
componentWillUnmount() {
RNShake.removeEventListener('shake');
}
}