react native shake event listener
npm install react-native-simple-shakeReact Native Simple Shake is a lightweight and powerful package designed for detecting shake gestures on both iOS and Android platforms. Built to support the New Architecture, it offers seamless integration and performance optimization for modern React Native applications.
Install the library using npm or yarn:
``bash`
npm install react-native-simple-shakeor
yarn add react-native-simple-shake
---
Here’s a basic implementation of the react-native-simple-shake library:
`javascript
import React, { useEffect } from 'react';
import { SafeAreaView, StyleSheet, Text } from 'react-native';
import { shakeListener } from 'react-native-simple-shake';
const ShakeComponent = (): JSX.Element => {
useEffect(() => {
const subscription = shakeListener(() => {
alert('Shake event detected');
});
return (): void => {
subscription.remove();
};
}, []);
return (
);
};
const styles = StyleSheet.create({
container: {
padding: 20,
},
text: {
fontSize: 20,
marginBottom: 20,
},
});
export default ShakeComponent;
``