react-native-proximity-sensor
Library for React Native to work with proximity-sensor.
Installation
npm install react-native-proximity-sensor
cd ios && pod install
or
yarn add react-native-proximity-sensor
cd ios && pod install
Usage
- 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 install
android
Add to android/gradle.properties
:
newArchEnabled=true
License
MIT