0.2.1 • Published 3 years ago
@lowkeychat/react-native-proximity-sensor v0.2.1
react-native-proximity-sensor
Library for React Native to work with proximity-sensor.
Installation
npm install react-native-proximity-sensor
cd ios && pod installor
yarn add react-native-proximity-sensor
cd ios && pod installUsage
- Subscribe on listening Proximity sensor
import { ProximitySensor } from 'react-native-proximity-sensor';
// ...
ProximitySensor.start();- Listen for changes
import { ProximitySensor } from 'react-native-proximity-sensor';
// ...
useEffect(() => {
const subscription = ProximitySensor.onChangeListener((isNear) => {
console.warn('isNear: ', isNear);
});
return () => {
subscription.remove();
};
}, []);- Stop listening
import { ProximitySensor } from 'react-native-proximity-sensor';
// ...
ProximitySensor.stop();Android
Android required some additional steps to work with Proximity sensor. Just add permissions to AndroidManifest.xml:
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.hardware.sensor.proximity"/>New architecture
ios
Install pods with right flag:
RCT_NEW_ARCH_ENABLED=1 pod installandroid
Add to android/gradle.properties:
newArchEnabled=trueLicense
MIT