0.2.1 • Published 1 year ago

@lowkeychat/react-native-proximity-sensor v0.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

0.2.1

1 year ago

0.2.0

1 year ago