kibolho / react-native-proximity-sensor

React Native Library to retrieve proximity sensor data from IOS and Android.
https://www.npmjs.com/package/rn-proximity-sensor
MIT License
1 stars 2 forks source link
native-module react-native

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

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