Retrieve proximity sensor data from IOS and Android.
IOS | Android |
---|---|
npm install rn-proximity-sensor
import proximity, { SubscriptionRef } from 'rn-proximity-sensor';
// ...
const sensorSubscriptionRef = useRef<SubscriptionRef | null>(null);
const [isShowingBalance, setIsShowingBalance] = useState<boolean>(false);
useEffect(() => {
sensorSubscriptionRef.current = proximity.subscribe((values) => {
if (values.is_double_toggle) setIsShowingBalance((prev) => !prev);
});
return () => {
if (sensorSubscriptionRef.current) {
sensorSubscriptionRef.current.unsubscribe();
sensorSubscriptionRef.current = null;
}
};
}, []);
The subscribe callback function will return values with the following properties: |
Property | Description | Support |
---|---|---|---|
distance | Number - 0 to 10cm | Android & IOS* | |
is_close | boolean | Android & IOS | |
is_toggle | boolean - toggle from one state to another | Android & IOS | |
is_double_toggle | boolean - toggle from not close state to close and back to not close | Android & IOS |
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Inspired in react-native-sensors Made with create-react-native-library