Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/williambout/react-native-proximity
:iphone: A React Native wrapper that provides access to the proximity sensor on iOS and Android.
https://github.com/williambout/react-native-proximity
android ios iphone proximity-sensor react-native sensor
Last synced: about 2 months ago
JSON representation
:iphone: A React Native wrapper that provides access to the proximity sensor on iOS and Android.
- Host: GitHub
- URL: https://github.com/williambout/react-native-proximity
- Owner: williambout
- License: mit
- Archived: true
- Created: 2016-05-02T13:19:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-07-07T13:20:15.000Z (over 3 years ago)
- Last Synced: 2024-05-03T01:32:03.223Z (8 months ago)
- Topics: android, ios, iphone, proximity-sensor, react-native, sensor
- Language: Java
- Homepage:
- Size: 2.49 MB
- Stars: 212
- Watchers: 7
- Forks: 69
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-react-native-native-modules - react-native-proximity ★128
README
[![npm version](https://badge.fury.io/js/react-native-proximity.svg)](https://badge.fury.io/js/react-native-proximity)
# react-native-proximity
A React Native wrapper that provides access to the state of the proximity sensor for iOS and Android.
![](https://github.com/williambout/react-native-proximity/raw/master/demo.gif)
*Usage of react-native-proximity and scrollview.*
## Getting Started
- Install the library
```shell
npm install --save react-native-proximity
```
- Link the library
```shell
react-native link react-native-proximity
```## Usage
Import the library
```javascript
import Proximity from 'react-native-proximity';
```### addListener(callback)
The callback function returns an object with *proximity* and *distance* properties. If *proximity* is true, it means the device is close to an physical object. *distance* is only supported in Android.
```javascript
componentDidMount(){
Proximity.addListener(this._proximityListener);
},/**
* State of proximity sensor
* @param {object} data
*/
_proximityListener(data) {
this.setState({
proximity: data.proximity,
distance: data.distance // Android-only
});
},
```### removeListener(callback)
```javascript
componentWillUnmount() {
Proximity.removeListener(this._proximityListener);
},
```