@lowkeychat/react-native-proximity-sensor
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

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

  1. Subscribe on listening Proximity sensor
import { ProximitySensor } from 'react-native-proximity-sensor';

// ...

ProximitySensor.start();
  1. Listen for changes
import { ProximitySensor } from 'react-native-proximity-sensor';
// ...

useEffect(() => {
    const subscription = ProximitySensor.onChangeListener((isNear) => {
      console.warn('isNear: ', isNear);
    });

    return () => {
      subscription.remove();
    };
  }, []);
  1. 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

Package Sidebar

Install

npm i @lowkeychat/react-native-proximity-sensor

Weekly Downloads

0

Version

0.2.1

License

MIT

Unpacked Size

37.1 kB

Total Files

29

Last publish

Collaborators

  • lowkeychat