📱 A React Native wrapper that provides access to the proximity sensor on iOS and Android.
Java Objective-C JavaScript Ruby
Switch branches/tags
Nothing to show
Clone or download
Latest commit 3fe9779 Jan 4, 2018
Permalink
Failed to load latest commit information.
RNProximity rn 0.40 fix Feb 10, 2017
android Remove unnecessary comment Oct 24, 2017
.gitignore
LICENCE 📖 Licence Mar 16, 2017
README.md Update README.md Mar 9, 2017
demo.gif Initial commit 🎉 May 2, 2016
index.js Support Android platform Mar 3, 2017
package.json 3.0.0 Dec 15, 2017
react-native-proximity.podspec add podspec Dec 20, 2017

README.md

npm version

react-native-proximity

A React Native wrapper that provides access to the state of the proximity sensor for iOS and Android.

Usage of react-native-proximity and scrollview.

Getting Started

  • Install the library
npm install --save react-native-proximity
  • Link the library
react-native link react-native-proximity

Usage

Import the library

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.

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)

componentWillUnmount() {
  Proximity.removeListener(this._proximityListener);
},