0.2.5 • Published 2 years ago

rn-proximity-sensor v0.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

rn-proximity-sensor

Retrieve proximity sensor data from IOS and Android.

IOSAndroid
Example with iosExample 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

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago