forked from williambout/react-native-proximity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·41 lines (36 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict';
import {
DeviceEventEmitter,
NativeModules,
Platform,
} from 'react-native';
const nativeModule = NativeModules.RNProximity;
let addListener = null;
let removeListener = null;
if (Platform.OS === 'ios') {
addListener = function(callback) {
NativeModules.RNProximity.proximityEnabled(true);
return DeviceEventEmitter.addListener(
'proximityStateDidChange', callback
);
},
removeListener = function(listener) {
NativeModules.RNProximity.proximityEnabled(false);
DeviceEventEmitter.removeAllListeners(
'proximityStateDidChange', listener
);
}
} else if (Platform.OS == 'android') {
addListener = (callback) => {
nativeModule.addListener();
DeviceEventEmitter.addListener(nativeModule.EVENT_ON_SENSOR_CHANGE, e => callback(e));
};
removeListener = (listener) => {
nativeModule.removeListener();
DeviceEventEmitter.removeAllListeners(nativeModule.EVENT_ON_SENSOR_CHANGE, listener);
};
}
module.exports = {
addListener,
removeListener,
};