New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rn-proximity-sensor

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rn-proximity-sensor

Get proximity sensor data

  • 0.2.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
54
decreased by-44.9%
Maintainers
1
Weekly downloads
 
Created
Source

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:

PropertyDescriptionSupport
distanceNumber - 0 to 10cmAndroid & IOS*
is_closebooleanAndroid & IOS
is_toggleboolean - toggle from one state to anotherAndroid & IOS
is_double_toggleboolean - toggle from not close state to close and back to not closeAndroid & 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

Keywords

FAQs

Package last updated on 11 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc