2.0.5 • Published 8 years ago

@hyl2015/react-native-proximity v2.0.5

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

npm version

react-native-proximity

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

npm.io

Usage of react-native-proximity and scrollview.

Getting Started

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

Usage

Import the library

import Proximity from '@hyl2015/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);
},
2.0.5

8 years ago

2.0.4

8 years ago