rn-proximity-sensor
TypeScript icon, indicating that this package has built-in type declarations

0.2.5 • Public • Published

rn-proximity-sensor

Retrieve proximity sensor data from IOS and Android.

IOS Android
Example with ios Example with android

Installation

npm install rn-proximity-sensor

Usage

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
  • Since in IOS we just have a boolean as the returned value of the sensor we mapped:
    • is_close = true to 0 cm
    • is_close = false to 10 cm

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Inspired in react-native-sensors Made with create-react-native-library

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.58latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.58
0.2.41
0.2.31
0.2.21
0.2.11
0.2.01

Package Sidebar

Install

npm i rn-proximity-sensor

Weekly Downloads

7

Version

0.2.5

License

MIT

Unpacked Size

40.8 kB

Total Files

28

Last publish

Collaborators

  • kibolho